Client.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.client;
00018 
00019 import org.apache.xmlrpc.client.XmlRpcClient;
00020 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
00021 import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
00022 import org.ros.exception.RosRuntimeException;
00023 import org.ros.internal.node.server.XmlRpcServer;
00024 import org.ros.internal.node.xmlrpc.XmlRpcClientFactory;
00025 import org.ros.internal.node.xmlrpc.XmlRpcEndpoint;
00026 
00027 import java.net.MalformedURLException;
00028 import java.net.URI;
00029 
00038 abstract class Client<T extends XmlRpcEndpoint> {
00039 
00040   // TODO(damonkohler): This should be pulled out into a user configurable
00041   // strategy.
00042   private static final int CONNECTION_TIMEOUT = 60 * 1000; // 60 seconds
00043   private static final int REPLY_TIMEOUT = 60 * 1000; // 60 seconds
00044   private static final int XMLRPC_TIMEOUT = 10 * 1000; // 10 seconds
00045 
00046   private final URI uri;
00047 
00048   protected final T xmlRpcEndpoint;
00049 
00056   public Client(URI uri, Class<T> interfaceClass) {
00057     this.uri = uri;
00058     XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
00059     try {
00060       config.setServerURL(uri.toURL());
00061     } catch (MalformedURLException e) {
00062       throw new RosRuntimeException(e);
00063     }
00064     config.setConnectionTimeout(CONNECTION_TIMEOUT);
00065     config.setReplyTimeout(REPLY_TIMEOUT);
00066 
00067     XmlRpcClient client = new XmlRpcClient();
00068     client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
00069     client.setConfig(config);
00070 
00071     XmlRpcClientFactory<T> factory = new XmlRpcClientFactory<T>(client);
00072     xmlRpcEndpoint =
00073         interfaceClass.cast(factory.newInstance(getClass().getClassLoader(), interfaceClass, "",
00074             XMLRPC_TIMEOUT));
00075   }
00076 
00080   public URI getRemoteUri() {
00081     return uri;
00082   }
00083 }


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