UpdatePublisherRunnable.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.ros.exception.RemoteException;
00022 import org.ros.internal.node.client.SlaveClient;
00023 import org.ros.internal.node.response.Response;
00024 import org.ros.internal.node.server.NodeIdentifier;
00025 import org.ros.internal.node.server.SlaveServer;
00026 import org.ros.internal.node.xmlrpc.XmlRpcTimeoutException;
00027 import org.ros.internal.transport.ProtocolDescription;
00028 import org.ros.internal.transport.ProtocolNames;
00029 import org.ros.node.topic.Publisher;
00030 import org.ros.node.topic.Subscriber;
00031 
00039 class UpdatePublisherRunnable<MessageType> implements Runnable {
00040 
00041   private static final Log log = LogFactory.getLog(UpdatePublisherRunnable.class);
00042 
00043   private final DefaultSubscriber<MessageType> subscriber;
00044   private final PublisherIdentifier publisherIdentifier;
00045   private final NodeIdentifier nodeIdentifier;
00046 
00055   public UpdatePublisherRunnable(DefaultSubscriber<MessageType> subscriber,
00056       NodeIdentifier nodeIdentifier, PublisherIdentifier publisherIdentifier) {
00057     this.subscriber = subscriber;
00058     this.nodeIdentifier = nodeIdentifier;
00059     this.publisherIdentifier = publisherIdentifier;
00060   }
00061 
00062   @Override
00063   public void run() {
00064     SlaveClient slaveClient;
00065     try {
00066       slaveClient = new SlaveClient(nodeIdentifier.getName(), publisherIdentifier.getNodeUri());
00067       Response<ProtocolDescription> response =
00068           slaveClient.requestTopic(subscriber.getTopicName(), ProtocolNames.SUPPORTED);
00069       // TODO(kwc): all of this logic really belongs in a protocol handler
00070       // registry.
00071       ProtocolDescription selected = response.getResult();
00072       if (ProtocolNames.SUPPORTED.contains(selected.getName())) {
00073         subscriber.addPublisher(publisherIdentifier, selected.getAddress());
00074       } else {
00075         log.error("Publisher returned unsupported protocol selection: " + response);
00076       }
00077     } catch (RemoteException e) {
00078       // TODO(damonkohler): Retry logic is needed at the XML-RPC layer.
00079       log.error(e);
00080     } catch (XmlRpcTimeoutException e) {
00081       // TODO(damonkohler): see above note re: retry
00082       log.error(e);
00083     } catch (RuntimeException e) {
00084       // TODO(kwc):
00085       // org.apache.xmlrpc.XmlRpcException/java.net.ConnectException's are
00086       // leaking through as java.lang.reflect.UndeclaredThrowableExceptions.
00087       // This is happening whenever the node attempts to connect to a stale
00088       // publisher (i.e. a publisher that is no longer online).
00089       log.error(e);
00090     }
00091   }
00092 }


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