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.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
00070
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
00079 log.error(e);
00080 } catch (XmlRpcTimeoutException e) {
00081
00082 log.error(e);
00083 } catch (RuntimeException e) {
00084
00085
00086
00087
00088
00089 log.error(e);
00090 }
00091 }
00092 }