Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.internal.transport.queue;
00018
00019 import org.ros.concurrent.CircularBlockingDeque;
00020
00021 import org.apache.commons.logging.Log;
00022 import org.apache.commons.logging.LogFactory;
00023 import org.jboss.netty.buffer.ChannelBuffer;
00024 import org.jboss.netty.channel.ChannelHandlerContext;
00025 import org.jboss.netty.channel.MessageEvent;
00026 import org.ros.internal.transport.tcp.AbstractNamedChannelHandler;
00027 import org.ros.message.MessageDeserializer;
00028
00035 public class MessageReceiver<T> extends AbstractNamedChannelHandler {
00036
00037 private static final boolean DEBUG = false;
00038 private static final Log log = LogFactory.getLog(MessageReceiver.class);
00039
00040 private final CircularBlockingDeque<LazyMessage<T>> lazyMessages;
00041 private final MessageDeserializer<T> deserializer;
00042
00043 public MessageReceiver(CircularBlockingDeque<LazyMessage<T>> lazyMessages,
00044 MessageDeserializer<T> deserializer) {
00045 this.lazyMessages = lazyMessages;
00046 this.deserializer = deserializer;
00047 }
00048
00049 @Override
00050 public String getName() {
00051 return "IncomingMessageQueueChannelHandler";
00052 }
00053
00054 @Override
00055 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
00056 ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
00057 if (DEBUG) {
00058 log.info(String.format("Received %d byte message.", buffer.readableBytes()));
00059 }
00060
00061
00062 lazyMessages.addLast(new LazyMessage<T>(buffer.copy(), deserializer));
00063 super.messageReceived(ctx, e);
00064 }
00065 }