mirror of
https://github.com/apache/activemq.git
synced 2025-02-16 23:16:52 +00:00
Add a storeConentAndClear() method to message so that we can lower the memory impact of embedded broker usage.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1481527 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b820ac2bf9
commit
30038957b6
@ -135,6 +135,12 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
|||||||
map.clear();
|
map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void storeContentAndClear() {
|
||||||
|
storeContent();
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeContent() {
|
public void storeContent() {
|
||||||
try {
|
try {
|
||||||
|
@ -752,4 +752,9 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess
|
|||||||
@Override
|
@Override
|
||||||
public void storeContent() {
|
public void storeContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void storeContentAndClear() {
|
||||||
|
storeContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,12 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void storeContentAndClear() {
|
||||||
|
storeContent();
|
||||||
|
object = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeContent() {
|
public void storeContent() {
|
||||||
ByteSequence bodyAsBytes = getContent();
|
ByteSequence bodyAsBytes = getContent();
|
||||||
|
@ -74,6 +74,16 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage
|
|||||||
|
|
||||||
public String getText() throws JMSException {
|
public String getText() throws JMSException {
|
||||||
if (text == null && getContent() != null) {
|
if (text == null && getContent() != null) {
|
||||||
|
text = decodeContent();
|
||||||
|
setContent(null);
|
||||||
|
setCompressed(false);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decodeContent() throws JMSException {
|
||||||
|
String text = null;
|
||||||
|
if (getContent() != null) {
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
ByteSequence bodyAsBytes = getContent();
|
ByteSequence bodyAsBytes = getContent();
|
||||||
@ -85,8 +95,6 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage
|
|||||||
DataInputStream dataIn = new DataInputStream(is);
|
DataInputStream dataIn = new DataInputStream(is);
|
||||||
text = MarshallingSupport.readUTF8(dataIn);
|
text = MarshallingSupport.readUTF8(dataIn);
|
||||||
dataIn.close();
|
dataIn.close();
|
||||||
setContent(null);
|
|
||||||
setCompressed(false);
|
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw JMSExceptionSupport.create(ioe);
|
throw JMSExceptionSupport.create(ioe);
|
||||||
@ -108,6 +116,12 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage
|
|||||||
storeContent();
|
storeContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void storeContentAndClear() {
|
||||||
|
storeContent();
|
||||||
|
text=null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeContent() {
|
public void storeContent() {
|
||||||
try {
|
try {
|
||||||
@ -166,7 +180,10 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
String text = getText();
|
String text = this.text;
|
||||||
|
if( text == null ) {
|
||||||
|
text = decodeContent();
|
||||||
|
}
|
||||||
if (text != null) {
|
if (text != null) {
|
||||||
text = MarshallingSupport.truncate64(text);
|
text = MarshallingSupport.truncate64(text);
|
||||||
HashMap<String, Object> overrideFields = new HashMap<String, Object>();
|
HashMap<String, Object> overrideFields = new HashMap<String, Object>();
|
||||||
|
@ -104,6 +104,7 @@ public abstract class Message extends BaseCommand implements MarshallAware, Mess
|
|||||||
public abstract Message copy();
|
public abstract Message copy();
|
||||||
public abstract void clearBody() throws JMSException;
|
public abstract void clearBody() throws JMSException;
|
||||||
public abstract void storeContent();
|
public abstract void storeContent();
|
||||||
|
public abstract void storeContentAndClear();
|
||||||
|
|
||||||
// useful to reduce the memory footprint of a persisted message
|
// useful to reduce the memory footprint of a persisted message
|
||||||
public void clearMarshalledState() throws JMSException {
|
public void clearMarshalledState() throws JMSException {
|
||||||
|
@ -257,6 +257,9 @@ class DelayableUOW(val manager:DBManager) extends BaseRetained {
|
|||||||
|
|
||||||
val messageRecord = id.getDataLocator match {
|
val messageRecord = id.getDataLocator match {
|
||||||
case null =>
|
case null =>
|
||||||
|
// encodes body and release object bodies, in case message was sent from
|
||||||
|
// a VM connection. Releases additional memory.
|
||||||
|
message.storeContentAndClear()
|
||||||
var packet = manager.parent.wireFormat.marshal(message)
|
var packet = manager.parent.wireFormat.marshal(message)
|
||||||
var data = new Buffer(packet.data, packet.offset, packet.length)
|
var data = new Buffer(packet.data, packet.offset, packet.length)
|
||||||
if( manager.snappyCompressLogs ) {
|
if( manager.snappyCompressLogs ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user