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.node.topic;
00018
00019 import org.apache.commons.logging.Log;
00020 import org.apache.commons.logging.LogFactory;
00021 import org.jboss.netty.channel.ChannelHandlerContext;
00022 import org.jboss.netty.channel.ChannelPipeline;
00023 import org.jboss.netty.channel.MessageEvent;
00024 import org.ros.internal.transport.BaseClientHandshakeHandler;
00025 import org.ros.internal.transport.ConnectionHeader;
00026 import org.ros.internal.transport.ConnectionHeaderFields;
00027 import org.ros.internal.transport.queue.IncomingMessageQueue;
00028 import org.ros.internal.transport.tcp.NamedChannelHandler;
00029 import org.ros.node.topic.Publisher;
00030 import org.ros.node.topic.Subscriber;
00031
00032 import java.util.concurrent.ExecutorService;
00033
00043 class SubscriberHandshakeHandler<T> extends BaseClientHandshakeHandler {
00044
00045 private static final Log log = LogFactory.getLog(SubscriberHandshakeHandler.class);
00046
00047 private final IncomingMessageQueue<T> incomingMessageQueue;
00048
00049 public SubscriberHandshakeHandler(ConnectionHeader outgoingConnectionHeader,
00050 final IncomingMessageQueue<T> incomingMessageQueue, ExecutorService executorService) {
00051 super(new SubscriberHandshake(outgoingConnectionHeader), executorService);
00052 this.incomingMessageQueue = incomingMessageQueue;
00053 }
00054
00055 @Override
00056 protected void onSuccess(ConnectionHeader incomingConnectionHeader, ChannelHandlerContext ctx,
00057 MessageEvent e) {
00058 ChannelPipeline pipeline = e.getChannel().getPipeline();
00059 pipeline.remove(SubscriberHandshakeHandler.this);
00060 NamedChannelHandler namedChannelHandler = incomingMessageQueue.getMessageReceiver();
00061 pipeline.addLast(namedChannelHandler.getName(), namedChannelHandler);
00062 String latching = incomingConnectionHeader.getField(ConnectionHeaderFields.LATCHING);
00063 if (latching != null && latching.equals("1")) {
00064 incomingMessageQueue.setLatchMode(true);
00065 }
00066 }
00067
00068 @Override
00069 protected void onFailure(String errorMessage, ChannelHandlerContext ctx, MessageEvent e) {
00070 log.error("Subscriber handshake failed: " + errorMessage);
00071 e.getChannel().close();
00072 }
00073
00074 @Override
00075 public String getName() {
00076 return "SubscriberHandshakeHandler";
00077 }
00078 }