ServiceClientHandshakeHandler.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.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 }


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