SubscriberHandshakeHandler.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49