Skip to content
Snippets Groups Projects
Commit b668ee95 authored by Damon Kohler's avatar Damon Kohler
Browse files

Removes unnecessary buffer copy operation and decreases the size of the...

Removes unnecessary buffer copy operation and decreases the size of the incomming message buffer. Previously the size was in excess of what could easily be handled by Android.
parent 3b3c5f1d
No related branches found
No related tags found
No related merge requests found
...@@ -37,14 +37,14 @@ public class IncomingMessageQueue<T> { ...@@ -37,14 +37,14 @@ public class IncomingMessageQueue<T> {
* {@link IncomingMessageQueue#addListener(MessageListener, int)} which are * {@link IncomingMessageQueue#addListener(MessageListener, int)} which are
* consumed by user provided {@link MessageListener}s. * consumed by user provided {@link MessageListener}s.
*/ */
private static final int QUEUE_CAPACITY = 128; private static final int QUEUE_CAPACITY = 16;
private final CircularBlockingQueue<LazyMessage<T>> lazyMessages;
private final MessageReceiver<T> messageReceiver; private final MessageReceiver<T> messageReceiver;
private final MessageDispatcher<T> messageDispatcher; private final MessageDispatcher<T> messageDispatcher;
public IncomingMessageQueue(MessageDeserializer<T> deserializer, ExecutorService executorService) { public IncomingMessageQueue(MessageDeserializer<T> deserializer, ExecutorService executorService) {
lazyMessages = new CircularBlockingQueue<LazyMessage<T>>(QUEUE_CAPACITY); CircularBlockingQueue<LazyMessage<T>> lazyMessages =
new CircularBlockingQueue<LazyMessage<T>>(QUEUE_CAPACITY);
messageReceiver = new MessageReceiver<T>(lazyMessages, deserializer); messageReceiver = new MessageReceiver<T>(lazyMessages, deserializer);
messageDispatcher = new MessageDispatcher<T>(lazyMessages, executorService); messageDispatcher = new MessageDispatcher<T>(lazyMessages, executorService);
executorService.execute(messageDispatcher); executorService.execute(messageDispatcher);
......
...@@ -57,7 +57,6 @@ public class MessageReceiver<T> extends AbstractNamedChannelHandler { ...@@ -57,7 +57,6 @@ public class MessageReceiver<T> extends AbstractNamedChannelHandler {
if (DEBUG) { if (DEBUG) {
log.info(String.format("Received %d byte message.", buffer.readableBytes())); log.info(String.format("Received %d byte message.", buffer.readableBytes()));
} }
// TODO(damonkohler): Use MessageBuffers pool.
// We have to make a defensive copy of the buffer here because Netty does // We have to make a defensive copy of the buffer here because Netty does
// not guarantee that the returned ChannelBuffer will not be reused. // not guarantee that the returned ChannelBuffer will not be reused.
lazyMessages.add(new LazyMessage<T>(buffer.copy(), deserializer)); lazyMessages.add(new LazyMessage<T>(buffer.copy(), deserializer));
......
...@@ -42,7 +42,7 @@ public class OutgoingMessageQueue<T> { ...@@ -42,7 +42,7 @@ public class OutgoingMessageQueue<T> {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final Log log = LogFactory.getLog(OutgoingMessageQueue.class); private static final Log log = LogFactory.getLog(OutgoingMessageQueue.class);
private static final int QUEUE_CAPACITY = 128; private static final int QUEUE_CAPACITY = 16;
private final MessageSerializer<T> serializer; private final MessageSerializer<T> serializer;
private final CircularBlockingQueue<T> queue; private final CircularBlockingQueue<T> queue;
......
...@@ -73,9 +73,7 @@ public class ChannelBufferField extends Field { ...@@ -73,9 +73,7 @@ public class ChannelBufferField extends Field {
if (currentSize < 0) { if (currentSize < 0) {
currentSize = buffer.readInt(); currentSize = buffer.readInt();
} }
// There are no guarantees this buffer won't be reused so we create a value = buffer.readSlice(currentSize);
// defensive copy.
value = buffer.readSlice(currentSize).copy();
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment