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.service;
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.tcp.TcpClientPipelineFactory;
00027 import org.ros.message.MessageDeserializer;
00028 import org.ros.node.service.ServiceResponseListener;
00029 import org.ros.node.service.ServiceServer;
00030
00031 import java.util.Queue;
00032 import java.util.concurrent.ExecutorService;
00033
00045 class ServiceClientHandshakeHandler<T, S> extends BaseClientHandshakeHandler {
00046
00047 private static final Log log = LogFactory.getLog(ServiceClientHandshakeHandler.class);
00048
00049 private final Queue<ServiceResponseListener<S>> responseListeners;
00050 private final MessageDeserializer<S> deserializer;
00051 private final ExecutorService executorService;
00052
00053 public ServiceClientHandshakeHandler(ConnectionHeader outgoingConnectionHeader,
00054 Queue<ServiceResponseListener<S>> responseListeners,
00055 MessageDeserializer<S> deserializer, ExecutorService executorService) {
00056 super(new ServiceClientHandshake(outgoingConnectionHeader), executorService);
00057 this.responseListeners = responseListeners;
00058 this.deserializer = deserializer;
00059 this.executorService = executorService;
00060 }
00061
00062 @Override
00063 protected void onSuccess(ConnectionHeader incommingConnectionHeader, ChannelHandlerContext ctx,
00064 MessageEvent e) {
00065 ChannelPipeline pipeline = e.getChannel().getPipeline();
00066 pipeline.remove(TcpClientPipelineFactory.LENGTH_FIELD_BASED_FRAME_DECODER);
00067 pipeline.remove(ServiceClientHandshakeHandler.this);
00068 pipeline.addLast("ResponseDecoder", new ServiceResponseDecoder<S>());
00069 pipeline.addLast("ResponseHandler", new ServiceResponseHandler<S>(responseListeners,
00070 deserializer, executorService));
00071 }
00072
00073 @Override
00074 protected void onFailure(String errorMessage, ChannelHandlerContext ctx, MessageEvent e) {
00075 log.error("Service client handshake failed: " + errorMessage);
00076 e.getChannel().close();
00077 }
00078
00079 @Override
00080 public String getName() {
00081 return "ServiceClientHandshakeHandler";
00082 }
00083 }