Skip to content
Snippets Groups Projects
Commit e9708a4a authored by Damon Kohler's avatar Damon Kohler
Browse files

Add getDefaultNodeName() to NodeMain to support the typical ROS behavior of...

Add getDefaultNodeName() to NodeMain to support the typical ROS behavior of overriding default node names.
Add (almost) proper handling of slaves with the same name attempting to register with the master.
Fix pubsub tutorial.
Some rename cleanup.
parent e54d93ee
No related branches found
No related tags found
No related merge requests found
Showing
with 149 additions and 96 deletions
...@@ -10,6 +10,7 @@ import org.ros.message.actionlib_tutorials.FibonacciActionResult; ...@@ -10,6 +10,7 @@ import org.ros.message.actionlib_tutorials.FibonacciActionResult;
import org.ros.message.actionlib_tutorials.FibonacciFeedback; import org.ros.message.actionlib_tutorials.FibonacciFeedback;
import org.ros.message.actionlib_tutorials.FibonacciGoal; import org.ros.message.actionlib_tutorials.FibonacciGoal;
import org.ros.message.actionlib_tutorials.FibonacciResult; import org.ros.message.actionlib_tutorials.FibonacciResult;
import org.ros.namespace.GraphName;
import org.ros.node.DefaultNodeMainExecutor; import org.ros.node.DefaultNodeMainExecutor;
import org.ros.node.Node; import org.ros.node.Node;
import org.ros.node.NodeConfiguration; import org.ros.node.NodeConfiguration;
...@@ -38,7 +39,7 @@ public class RunFibonacciSimpleActionClient { ...@@ -38,7 +39,7 @@ public class RunFibonacciSimpleActionClient {
FibonacciActionSpec spec = new FibonacciActionSpec(); FibonacciActionSpec spec = new FibonacciActionSpec();
final FibonacciSimpleActionClient sac = spec.buildSimpleActionClient("fibonacci_client"); final FibonacciSimpleActionClient sac = spec.buildSimpleActionClient("fibonacci_client");
runner.run(new NodeMain() { runner.executeNodeMain(new NodeMain() {
@Override @Override
public void onStart(Node node) { public void onStart(Node node) {
...@@ -53,6 +54,10 @@ public class RunFibonacciSimpleActionClient { ...@@ -53,6 +54,10 @@ public class RunFibonacciSimpleActionClient {
public void onShutdownComplete(Node node) { public void onShutdownComplete(Node node) {
} }
@Override
public GraphName getDefaultNodeName() {
return new GraphName("actionlib_java/fibonacci_client");
}
}, configuration); }, configuration);
System.out.println("[Test] Waiting for action server to start"); System.out.println("[Test] Waiting for action server to start");
...@@ -117,7 +122,7 @@ public class RunFibonacciSimpleActionClient { ...@@ -117,7 +122,7 @@ public class RunFibonacciSimpleActionClient {
final SimpleActionClient<FibonacciActionFeedback, FibonacciActionGoal, FibonacciActionResult, FibonacciFeedback, FibonacciGoal, FibonacciResult> sac = final SimpleActionClient<FibonacciActionFeedback, FibonacciActionGoal, FibonacciActionResult, FibonacciFeedback, FibonacciGoal, FibonacciResult> sac =
spec.buildSimpleActionClient("fibonacci"); spec.buildSimpleActionClient("fibonacci");
runner.run(new NodeMain() { runner.executeNodeMain(new NodeMain() {
@Override @Override
public void onStart(Node node) { public void onStart(Node node) {
...@@ -132,6 +137,10 @@ public class RunFibonacciSimpleActionClient { ...@@ -132,6 +137,10 @@ public class RunFibonacciSimpleActionClient {
public void onShutdownComplete(Node node) { public void onShutdownComplete(Node node) {
} }
@Override
public GraphName getDefaultNodeName() {
return new GraphName("actionlib_java/fibonacci_client");
}
}, configuration); }, configuration);
System.out.println("[Test] Waiting for action server to start"); System.out.println("[Test] Waiting for action server to start");
......
package org.ros.actionlib.example; package org.ros.actionlib.example;
import org.ros.namespace.GraphName;
import org.ros.node.DefaultNodeMainExecutor; import org.ros.node.DefaultNodeMainExecutor;
import org.ros.node.Node; import org.ros.node.Node;
import org.ros.node.NodeConfiguration; import org.ros.node.NodeConfiguration;
...@@ -28,7 +29,7 @@ public class RunFibonacciSimpleActionServer { ...@@ -28,7 +29,7 @@ public class RunFibonacciSimpleActionServer {
NodeMainExecutor runner = DefaultNodeMainExecutor.newDefault(); NodeMainExecutor runner = DefaultNodeMainExecutor.newDefault();
runner.run(new NodeMain() { runner.executeNodeMain(new NodeMain() {
@Override @Override
public void onStart(Node node) { public void onStart(Node node) {
...@@ -43,6 +44,10 @@ public class RunFibonacciSimpleActionServer { ...@@ -43,6 +44,10 @@ public class RunFibonacciSimpleActionServer {
public void onShutdownComplete(Node node) { public void onShutdownComplete(Node node) {
} }
@Override
public GraphName getDefaultNodeName() {
throw new UnsupportedOperationException();
}
}, configuration); }, configuration);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
......
...@@ -67,7 +67,8 @@ public class RosRun { ...@@ -67,7 +67,8 @@ public class RosRun {
throw new RosRuntimeException("Unable to instantiate node: " + nodeClassName, e); throw new RosRuntimeException("Unable to instantiate node: " + nodeClassName, e);
} }
Preconditions.checkState(nodeMain != null);
NodeMainExecutor runner = DefaultNodeMainExecutor.newDefault(); NodeMainExecutor runner = DefaultNodeMainExecutor.newDefault();
runner.run(nodeMain, nodeConfiguration); runner.executeNodeMain(nodeMain, nodeConfiguration);
} }
} }
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package org.ros.internal.node.client; package org.ros.internal.node.client;
import java.net.MalformedURLException;
import java.net.URI;
import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
...@@ -27,6 +24,9 @@ import org.ros.internal.node.server.NodeServer; ...@@ -27,6 +24,9 @@ import org.ros.internal.node.server.NodeServer;
import org.ros.internal.node.xmlrpc.XmlRpcClientFactory; import org.ros.internal.node.xmlrpc.XmlRpcClientFactory;
import org.ros.internal.node.xmlrpc.XmlRpcEndpoint; import org.ros.internal.node.xmlrpc.XmlRpcEndpoint;
import java.net.MalformedURLException;
import java.net.URI;
/** /**
* Base class for XML-RPC clients (e.g. MasterClient and SlaveClient). * Base class for XML-RPC clients (e.g. MasterClient and SlaveClient).
* *
...@@ -45,7 +45,7 @@ abstract class Client<T extends XmlRpcEndpoint> { ...@@ -45,7 +45,7 @@ abstract class Client<T extends XmlRpcEndpoint> {
private final URI uri; private final URI uri;
protected final T node; protected final T xmlRpcEndpoint;
/** /**
* @param uri * @param uri
...@@ -69,7 +69,7 @@ abstract class Client<T extends XmlRpcEndpoint> { ...@@ -69,7 +69,7 @@ abstract class Client<T extends XmlRpcEndpoint> {
client.setConfig(config); client.setConfig(config);
XmlRpcClientFactory<T> factory = new XmlRpcClientFactory<T>(client); XmlRpcClientFactory<T> factory = new XmlRpcClientFactory<T>(client);
node = xmlRpcEndpoint =
interfaceClass.cast(factory.newInstance(getClass().getClassLoader(), interfaceClass, "", interfaceClass.cast(factory.newInstance(getClass().getClassLoader(), interfaceClass, "",
XMLRPC_TIMEOUT)); XMLRPC_TIMEOUT));
} }
...@@ -80,5 +80,4 @@ abstract class Client<T extends XmlRpcEndpoint> { ...@@ -80,5 +80,4 @@ abstract class Client<T extends XmlRpcEndpoint> {
public URI getRemoteUri() { public URI getRemoteUri() {
return uri; return uri;
} }
} }
...@@ -65,7 +65,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -65,7 +65,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
* @return a {@link Response} with a void result * @return a {@link Response} with a void result
*/ */
public Response<Void> registerService(SlaveIdentifier slave, ServiceServer<?, ?> service) { public Response<Void> registerService(SlaveIdentifier slave, ServiceServer<?, ?> service) {
return Response.fromListChecked(node.registerService(slave.getNodeName().toString(), service return Response.fromListChecked(xmlRpcEndpoint.registerService(slave.getNodeName().toString(), service
.getName().toString(), service.getUri().toString(), slave.getUri().toString()), .getName().toString(), service.getUri().toString(), slave.getUri().toString()),
new VoidResultFactory()); new VoidResultFactory());
} }
...@@ -82,7 +82,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -82,7 +82,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
* result * result
*/ */
public Response<Integer> unregisterService(SlaveIdentifier slave, ServiceServer<?, ?> service) { public Response<Integer> unregisterService(SlaveIdentifier slave, ServiceServer<?, ?> service) {
return Response.fromListChecked(node.unregisterService(slave.getNodeName().toString(), service return Response.fromListChecked(xmlRpcEndpoint.unregisterService(slave.getNodeName().toString(), service
.getName().toString(), service.getUri().toString()), new IntegerResultFactory()); .getName().toString(), service.getUri().toString()), new IntegerResultFactory());
} }
...@@ -102,7 +102,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -102,7 +102,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
* as the result * as the result
*/ */
public Response<List<URI>> registerSubscriber(SlaveIdentifier slave, Subscriber<?> subscriber) { public Response<List<URI>> registerSubscriber(SlaveIdentifier slave, Subscriber<?> subscriber) {
return Response.fromListChecked(node.registerSubscriber(slave.getNodeName().toString(), subscriber return Response.fromListChecked(xmlRpcEndpoint.registerSubscriber(slave.getNodeName().toString(), subscriber
.getTopicName().toString(), subscriber.getTopicMessageType(), slave.getUri().toString()), .getTopicName().toString(), subscriber.getTopicMessageType(), slave.getUri().toString()),
new UriListResultFactory()); new UriListResultFactory());
} }
...@@ -118,7 +118,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -118,7 +118,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
* the result * the result
*/ */
public Response<Integer> unregisterSubscriber(SlaveIdentifier slave, Subscriber<?> subscriber) { public Response<Integer> unregisterSubscriber(SlaveIdentifier slave, Subscriber<?> subscriber) {
return Response.fromListChecked(node.unregisterSubscriber(slave.getNodeName().toString(), return Response.fromListChecked(xmlRpcEndpoint.unregisterSubscriber(slave.getNodeName().toString(),
subscriber.getTopicName().toString(), slave.getUri().toString()), subscriber.getTopicName().toString(), slave.getUri().toString()),
new IntegerResultFactory()); new IntegerResultFactory());
} }
...@@ -139,7 +139,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -139,7 +139,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
String topicName = publisherDefinition.getTopicName().toString(); String topicName = publisherDefinition.getTopicName().toString();
String messageType = publisherDefinition.getTopicMessageType(); String messageType = publisherDefinition.getTopicMessageType();
return Response.fromListChecked( return Response.fromListChecked(
node.registerPublisher(slaveName, topicName, messageType, slaveUri), xmlRpcEndpoint.registerPublisher(slaveName, topicName, messageType, slaveUri),
new UriListResultFactory()); new UriListResultFactory());
} }
...@@ -156,7 +156,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -156,7 +156,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
String slaveName = publisherIdentifier.getSlaveName().toString(); String slaveName = publisherIdentifier.getSlaveName().toString();
String slaveUri = publisherIdentifier.getSlaveUri().toString(); String slaveUri = publisherIdentifier.getSlaveUri().toString();
String topicName = publisherIdentifier.getTopicName().toString(); String topicName = publisherIdentifier.getTopicName().toString();
return Response.fromListChecked(node.unregisterPublisher(slaveName, topicName, slaveUri), return Response.fromListChecked(xmlRpcEndpoint.unregisterPublisher(slaveName, topicName, slaveUri),
new IntegerResultFactory()); new IntegerResultFactory());
} }
...@@ -171,7 +171,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -171,7 +171,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
* as a result * as a result
*/ */
public Response<URI> lookupNode(SlaveIdentifier slave, String nodeName) { public Response<URI> lookupNode(SlaveIdentifier slave, String nodeName) {
return Response.fromListChecked(node.lookupNode(slave.getNodeName().toString(), nodeName), return Response.fromListChecked(xmlRpcEndpoint.lookupNode(slave.getNodeName().toString(), nodeName),
new UriResultFactory()); new UriResultFactory());
} }
...@@ -184,7 +184,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -184,7 +184,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
*/ */
public Response<URI> getUri(SlaveIdentifier slave) { public Response<URI> getUri(SlaveIdentifier slave) {
return Response return Response
.fromListChecked(node.getUri(slave.getNodeName().toString()), new UriResultFactory()); .fromListChecked(xmlRpcEndpoint.getUri(slave.getNodeName().toString()), new UriResultFactory());
} }
/** /**
...@@ -199,7 +199,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> { ...@@ -199,7 +199,7 @@ public class MasterClient extends Client<MasterXmlRpcEndpoint> {
*/ */
public Response<URI> lookupService(SlaveIdentifier slave, String serviceName) { public Response<URI> lookupService(SlaveIdentifier slave, String serviceName) {
return Response.fromListCheckedFailure( return Response.fromListCheckedFailure(
node.lookupService(slave.getNodeName().toString(), serviceName), new UriResultFactory()); xmlRpcEndpoint.lookupService(slave.getNodeName().toString(), serviceName), new UriResultFactory());
} }
public Response<List<TopicDefinition>> getPublishedTopics(SlaveIdentifier slave, String subgraph) { public Response<List<TopicDefinition>> getPublishedTopics(SlaveIdentifier slave, String subgraph) {
......
...@@ -60,72 +60,72 @@ public class ParameterClient extends Client<ParameterServerXmlRpcEndpoint> { ...@@ -60,72 +60,72 @@ public class ParameterClient extends Client<ParameterServerXmlRpcEndpoint> {
} }
public Response<Object> getParam(GraphName parameterName) { public Response<Object> getParam(GraphName parameterName) {
return Response.fromListCheckedFailure(node.getParam(nodeName, parameterName.toString()), return Response.fromListCheckedFailure(xmlRpcEndpoint.getParam(nodeName, parameterName.toString()),
new ObjectResultFactory()); new ObjectResultFactory());
} }
public Response<Void> setParam(GraphName parameterName, Boolean parameterValue) { public Response<Void> setParam(GraphName parameterName, Boolean parameterValue) {
return Response.fromListChecked( return Response.fromListChecked(
node.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory()); xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
} }
public Response<Void> setParam(GraphName parameterName, Integer parameterValue) { public Response<Void> setParam(GraphName parameterName, Integer parameterValue) {
return Response.fromListChecked( return Response.fromListChecked(
node.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory()); xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
} }
public Response<Void> setParam(GraphName parameterName, Double parameterValue) { public Response<Void> setParam(GraphName parameterName, Double parameterValue) {
return Response.fromListChecked( return Response.fromListChecked(
node.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory()); xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
} }
public Response<Void> setParam(GraphName parameterName, String parameterValue) { public Response<Void> setParam(GraphName parameterName, String parameterValue) {
return Response.fromListChecked( return Response.fromListChecked(
node.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory()); xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
} }
public Response<Void> setParam(GraphName parameterName, List<?> parameterValue) { public Response<Void> setParam(GraphName parameterName, List<?> parameterValue) {
return Response.fromListChecked( return Response.fromListChecked(
node.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory()); xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
} }
public Response<Void> setParam(GraphName parameterName, Map<?, ?> parameterValue) { public Response<Void> setParam(GraphName parameterName, Map<?, ?> parameterValue) {
return Response.fromListChecked( return Response.fromListChecked(
node.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory()); xmlRpcEndpoint.setParam(nodeName, parameterName.toString(), parameterValue), new VoidResultFactory());
} }
public Response<GraphName> searchParam(GraphName parameterName) { public Response<GraphName> searchParam(GraphName parameterName) {
Response<String> response = Response<String> response =
Response.fromListCheckedFailure(node.searchParam(nodeName, parameterName.toString()), Response.fromListCheckedFailure(xmlRpcEndpoint.searchParam(nodeName, parameterName.toString()),
new StringResultFactory()); new StringResultFactory());
return new Response<GraphName>(response.getStatusCode(), response.getStatusMessage(), return new Response<GraphName>(response.getStatusCode(), response.getStatusMessage(),
new GraphName(response.getResult())); new GraphName(response.getResult()));
} }
public Response<Object> subscribeParam(GraphName parameterName) { public Response<Object> subscribeParam(GraphName parameterName) {
return Response.fromListChecked(node.subscribeParam(nodeName, slaveIdentifier.getUri() return Response.fromListChecked(xmlRpcEndpoint.subscribeParam(nodeName, slaveIdentifier.getUri()
.toString(), parameterName.toString()), new ObjectResultFactory()); .toString(), parameterName.toString()), new ObjectResultFactory());
} }
public Response<Integer> unsubscribeParam(GraphName parameterName) { public Response<Integer> unsubscribeParam(GraphName parameterName) {
return Response.fromListChecked( return Response.fromListChecked(
node.unsubscribeParam(nodeName, slaveIdentifier.getUri().toString(), xmlRpcEndpoint.unsubscribeParam(nodeName, slaveIdentifier.getUri().toString(),
parameterName.toString()), new IntegerResultFactory()); parameterName.toString()), new IntegerResultFactory());
} }
public Response<Boolean> hasParam(GraphName parameterName) { public Response<Boolean> hasParam(GraphName parameterName) {
return Response.fromListChecked(node.hasParam(nodeName, parameterName.toString()), return Response.fromListChecked(xmlRpcEndpoint.hasParam(nodeName, parameterName.toString()),
new BooleanResultFactory()); new BooleanResultFactory());
} }
public Response<Void> deleteParam(GraphName parameterName) { public Response<Void> deleteParam(GraphName parameterName) {
return Response.fromListChecked(node.deleteParam(nodeName, parameterName.toString()), return Response.fromListChecked(xmlRpcEndpoint.deleteParam(nodeName, parameterName.toString()),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<List<GraphName>> getParamNames() { public Response<List<GraphName>> getParamNames() {
Response<List<String>> response = Response<List<String>> response =
Response.fromListChecked(node.getParamNames(nodeName), new StringListResultFactory()); Response.fromListChecked(xmlRpcEndpoint.getParamNames(nodeName), new StringListResultFactory());
List<GraphName> graphNames = Lists.newArrayList(); List<GraphName> graphNames = Lists.newArrayList();
for (String name : response.getResult()) { for (String name : response.getResult()) {
graphNames.add(new GraphName(name)); graphNames.add(new GraphName(name));
......
...@@ -16,10 +16,7 @@ ...@@ -16,10 +16,7 @@
package org.ros.internal.node.client; package org.ros.internal.node.client;
import java.net.URI; import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.ros.internal.node.response.IntegerResultFactory; import org.ros.internal.node.response.IntegerResultFactory;
import org.ros.internal.node.response.ProtocolDescriptionResultFactory; import org.ros.internal.node.response.ProtocolDescriptionResultFactory;
...@@ -32,7 +29,10 @@ import org.ros.internal.node.xmlrpc.SlaveXmlRpcEndpoint; ...@@ -32,7 +29,10 @@ import org.ros.internal.node.xmlrpc.SlaveXmlRpcEndpoint;
import org.ros.internal.transport.ProtocolDescription; import org.ros.internal.transport.ProtocolDescription;
import org.ros.namespace.GraphName; import org.ros.namespace.GraphName;
import com.google.common.collect.Lists; import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* @author damonkohler@google.com (Damon Kohler) * @author damonkohler@google.com (Damon Kohler)
...@@ -55,59 +55,59 @@ public class SlaveClient extends Client<SlaveXmlRpcEndpoint> { ...@@ -55,59 +55,59 @@ public class SlaveClient extends Client<SlaveXmlRpcEndpoint> {
} }
public Response<URI> getMasterUri() { public Response<URI> getMasterUri() {
return Response.fromListChecked(node.getMasterUri(nodeName.toString()), new UriResultFactory()); return Response.fromListChecked(xmlRpcEndpoint.getMasterUri(nodeName.toString()), new UriResultFactory());
} }
public List<Object> shutdown(String message) { public Response<Void> shutdown(String message) {
throw new UnsupportedOperationException(); return Response.fromListChecked(xmlRpcEndpoint.shutdown("/master", message), new VoidResultFactory());
} }
public Response<Integer> getPid() { public Response<Integer> getPid() {
return Response.fromListChecked(node.getPid(nodeName.toString()), new IntegerResultFactory()); return Response.fromListChecked(xmlRpcEndpoint.getPid(nodeName.toString()), new IntegerResultFactory());
} }
public Response<List<TopicDefinition>> getSubscriptions() { public Response<List<TopicDefinition>> getSubscriptions() {
return Response.fromListChecked(node.getSubscriptions(nodeName.toString()), return Response.fromListChecked(xmlRpcEndpoint.getSubscriptions(nodeName.toString()),
new TopicDefinitionListResultFactory()); new TopicDefinitionListResultFactory());
} }
public Response<List<TopicDefinition>> getPublications() { public Response<List<TopicDefinition>> getPublications() {
return Response.fromListChecked(node.getPublications(nodeName.toString()), return Response.fromListChecked(xmlRpcEndpoint.getPublications(nodeName.toString()),
new TopicDefinitionListResultFactory()); new TopicDefinitionListResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, boolean value) { public Response<Void> paramUpdate(GraphName name, boolean value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, char value) { public Response<Void> paramUpdate(GraphName name, char value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, int value) { public Response<Void> paramUpdate(GraphName name, int value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, double value) { public Response<Void> paramUpdate(GraphName name, double value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, String value) { public Response<Void> paramUpdate(GraphName name, String value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, List<?> value) { public Response<Void> paramUpdate(GraphName name, List<?> value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<Void> paramUpdate(GraphName name, Map<?, ?> value) { public Response<Void> paramUpdate(GraphName name, Map<?, ?> value) {
return Response.fromListChecked(node.paramUpdate(nodeName.toString(), name.toString(), value), return Response.fromListChecked(xmlRpcEndpoint.paramUpdate(nodeName.toString(), name.toString(), value),
new VoidResultFactory()); new VoidResultFactory());
} }
...@@ -117,14 +117,13 @@ public class SlaveClient extends Client<SlaveXmlRpcEndpoint> { ...@@ -117,14 +117,13 @@ public class SlaveClient extends Client<SlaveXmlRpcEndpoint> {
publishers.add(uri.toString()); publishers.add(uri.toString());
} }
return Response.fromListChecked( return Response.fromListChecked(
node.publisherUpdate(nodeName.toString(), topic.toString(), publishers.toArray()), xmlRpcEndpoint.publisherUpdate(nodeName.toString(), topic.toString(), publishers.toArray()),
new VoidResultFactory()); new VoidResultFactory());
} }
public Response<ProtocolDescription> requestTopic(GraphName topic, public Response<ProtocolDescription> requestTopic(GraphName topic,
Collection<String> requestedProtocols) { Collection<String> requestedProtocols) {
return Response.fromListChecked(node.requestTopic(nodeName.toString(), topic.toString(), return Response.fromListChecked(xmlRpcEndpoint.requestTopic(nodeName.toString(), topic.toString(),
new Object[][] { requestedProtocols.toArray() }), new ProtocolDescriptionResultFactory()); new Object[][] { requestedProtocols.toArray() }), new ProtocolDescriptionResultFactory());
} }
} }
...@@ -162,9 +162,12 @@ public class MasterServer extends NodeServer { ...@@ -162,9 +162,12 @@ public class MasterServer extends NodeServer {
private void addSlave(SlaveIdentifier slaveIdentifier) { private void addSlave(SlaveIdentifier slaveIdentifier) {
Preconditions.checkNotNull(slaveIdentifier); Preconditions.checkNotNull(slaveIdentifier);
GraphName slaveName = slaveIdentifier.getNodeName(); GraphName slaveName = slaveIdentifier.getNodeName();
Preconditions.checkState( SlaveIdentifier existingSlaveIdentifier = slaves.get(slaveName);
slaves.get(slaveName) == null || slaves.get(slaveName).equals(slaveIdentifier), if (existingSlaveIdentifier != null && !existingSlaveIdentifier.equals(slaveIdentifier)) {
"Failed to add slave: " + slaveIdentifier + "\nExisting slave: " + slaves.get(slaveName)); log.warn(String.format("Existing slave %s will be shutdown.", existingSlaveIdentifier));
SlaveClient client = new SlaveClient(MASTER_NODE_NAME, existingSlaveIdentifier.getUri());
client.shutdown(String.format("Replaced by slave %s.", slaveIdentifier));
}
slaves.put(slaveName, slaveIdentifier); slaves.put(slaveName, slaveIdentifier);
} }
......
...@@ -80,10 +80,12 @@ public class SlaveServer extends NodeServer { ...@@ -80,10 +80,12 @@ public class SlaveServer extends NodeServer {
* correct information when topics are requested. * correct information when topics are requested.
*/ */
public void start() { public void start() {
super.start(org.ros.internal.node.xmlrpc.SlaveXmlRpcEndpointImpl.class, new SlaveXmlRpcEndpointImpl(this)); super.start(org.ros.internal.node.xmlrpc.SlaveXmlRpcEndpointImpl.class,
new SlaveXmlRpcEndpointImpl(this));
tcpRosServer.start(); tcpRosServer.start();
} }
// TODO(damonkohler): This should also shut down the Node.
@Override @Override
public void shutdown() { public void shutdown() {
super.shutdown(); super.shutdown();
......
...@@ -97,15 +97,16 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor { ...@@ -97,15 +97,16 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor {
} }
@Override @Override
public void run(final NodeMain nodeMain, final NodeConfiguration nodeConfiguration, public void executeNodeMain(final NodeMain nodeMain, final NodeConfiguration nodeConfiguration,
final Collection<NodeListener> nodeListeners) { final Collection<NodeListener> nodeListeners) {
Preconditions.checkNotNull(nodeConfiguration.getNodeName(), "Node name not specified."); // NOTE(damonkohler): To avoid a race condition, we have to make our copy
if (DEBUG) {
log.info("Starting node: " + nodeConfiguration.getNodeName());
}
// NOTE(damonkohler): To avoid a race condition, we have to make a copy
// of the NodeConfiguration in the current thread. // of the NodeConfiguration in the current thread.
final NodeConfiguration nodeConfigurationCopy = NodeConfiguration.copyOf(nodeConfiguration); final NodeConfiguration nodeConfigurationCopy = NodeConfiguration.copyOf(nodeConfiguration);
nodeConfigurationCopy.setDefaultNodeName(nodeMain.getDefaultNodeName());
Preconditions.checkNotNull(nodeConfigurationCopy.getNodeName(), "Node name not specified.");
if (DEBUG) {
log.info("Starting node: " + nodeConfigurationCopy.getNodeName());
}
executorService.execute(new Runnable() { executorService.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -123,8 +124,8 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor { ...@@ -123,8 +124,8 @@ public class DefaultNodeMainExecutor implements NodeMainExecutor {
} }
@Override @Override
public void run(NodeMain nodeMain, NodeConfiguration nodeConfiguration) { public void executeNodeMain(NodeMain nodeMain, NodeConfiguration nodeConfiguration) {
run(nodeMain, nodeConfiguration, null); executeNodeMain(nodeMain, nodeConfiguration, null);
} }
@Override @Override
......
...@@ -16,18 +16,27 @@ ...@@ -16,18 +16,27 @@
package org.ros.node; package org.ros.node;
import org.ros.namespace.GraphName;
import org.ros.node.topic.Publisher; import org.ros.node.topic.Publisher;
import org.ros.node.topic.Subscriber; import org.ros.node.topic.Subscriber;
/** /**
* The one required {@link NodeListener} for node creation. * Encapsulates a {@link Node} with its associated program logic.
* *
* <p> * <p>
* {@link NodeListener#onStart(Node)} should be used to set up your program's * {@link NodeMain} is the one required {@link NodeListener} for {@link Node}
* {@link Publisher}s, {@link Subscriber}s, and services. * creation. {@link NodeListener#onStart(Node)} should be used to set up your
* program's {@link Publisher}s, {@link Subscriber}s, etc.
* *
* @author ethan.rublee@gmail.com (Ethan Rublee) * @author ethan.rublee@gmail.com (Ethan Rublee)
* @author damonkohler@google.com (Damon Kohler) * @author damonkohler@google.com (Damon Kohler)
*/ */
public interface NodeMain extends NodeListener { public interface NodeMain extends NodeListener {
/**
* @return the name of the {@link Node} that will be used if a name was not
* specified in the {@link Node}'s associated
* {@link NodeConfiguration}
*/
GraphName getDefaultNodeName();
} }
...@@ -20,7 +20,8 @@ import java.util.Collection; ...@@ -20,7 +20,8 @@ import java.util.Collection;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
/** /**
* Executes {@link NodeMain}s. * Executes {@link NodeMain}s and allows shutting down individual
* {@link NodeMain}s or all currently running {@link NodeMain}s as a group.
* *
* @author damonkohler@google.com (Damon Kohler) * @author damonkohler@google.com (Damon Kohler)
*/ */
...@@ -37,9 +38,9 @@ public interface NodeMainExecutor { ...@@ -37,9 +38,9 @@ public interface NodeMainExecutor {
* {@link Node} * {@link Node}
* @param nodeListeners * @param nodeListeners
* a {@link Collection} of {@link NodeListener}s to be added to the * a {@link Collection} of {@link NodeListener}s to be added to the
* {@link Node} before it starts (can be {@code null}) * {@link Node} before it starts, can be {@code null}
*/ */
void run(NodeMain nodeMain, NodeConfiguration nodeConfiguration, void executeNodeMain(NodeMain nodeMain, NodeConfiguration nodeConfiguration,
Collection<NodeListener> nodeListeners); Collection<NodeListener> nodeListeners);
/** /**
...@@ -52,7 +53,7 @@ public interface NodeMainExecutor { ...@@ -52,7 +53,7 @@ public interface NodeMainExecutor {
* the {@link NodeConfiguration} that will be used to create the * the {@link NodeConfiguration} that will be used to create the
* {@link Node} * {@link Node}
*/ */
void run(NodeMain nodeMain, NodeConfiguration nodeConfiguration); void executeNodeMain(NodeMain nodeMain, NodeConfiguration nodeConfiguration);
/** /**
* Executes a {@link Runnable} using this {@link NodeMainExecutor}'s * Executes a {@link Runnable} using this {@link NodeMainExecutor}'s
......
...@@ -41,6 +41,11 @@ import java.util.Map; ...@@ -41,6 +41,11 @@ import java.util.Map;
*/ */
public class ParameterServerTestNode implements NodeMain { public class ParameterServerTestNode implements NodeMain {
@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava/parameter_server_test_node");
}
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public void onStart(Node node) { public void onStart(Node node) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.ros; package org.ros;
import org.ros.message.MessageListener; import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.Node; import org.ros.node.Node;
import org.ros.node.NodeMain; import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher; import org.ros.node.topic.Publisher;
...@@ -30,6 +31,11 @@ import org.ros.node.topic.Subscriber; ...@@ -30,6 +31,11 @@ import org.ros.node.topic.Subscriber;
*/ */
public class PassthroughTestNode implements NodeMain { public class PassthroughTestNode implements NodeMain {
@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava/passthrough_test_node");
}
@Override @Override
public void onStart(final Node node) { public void onStart(final Node node) {
// The goal of the passthrough node is simply to retransmit the messages // The goal of the passthrough node is simply to retransmit the messages
......
...@@ -19,6 +19,7 @@ package org.ros; ...@@ -19,6 +19,7 @@ package org.ros;
import org.ros.concurrent.CancellableLoop; import org.ros.concurrent.CancellableLoop;
import org.ros.message.MessageListener; import org.ros.message.MessageListener;
import org.ros.message.std_msgs.Int64; import org.ros.message.std_msgs.Int64;
import org.ros.namespace.GraphName;
import org.ros.node.Node; import org.ros.node.Node;
import org.ros.node.NodeMain; import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher; import org.ros.node.topic.Publisher;
...@@ -31,6 +32,11 @@ import org.ros.node.topic.Subscriber; ...@@ -31,6 +32,11 @@ import org.ros.node.topic.Subscriber;
*/ */
public class SlaveApiTestNode implements NodeMain { public class SlaveApiTestNode implements NodeMain {
@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava/slave_api_test_node");
}
@Override @Override
public void onStart(Node node) { public void onStart(Node node) {
// Basic chatter in/out test. // Basic chatter in/out test.
......
...@@ -18,6 +18,7 @@ package org.ros.tutorials.pubsub; ...@@ -18,6 +18,7 @@ package org.ros.tutorials.pubsub;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.ros.message.MessageListener; import org.ros.message.MessageListener;
import org.ros.namespace.GraphName;
import org.ros.node.Node; import org.ros.node.Node;
import org.ros.node.NodeMain; import org.ros.node.NodeMain;
import org.ros.node.topic.Subscriber; import org.ros.node.topic.Subscriber;
...@@ -30,6 +31,11 @@ import org.ros.node.topic.Subscriber; ...@@ -30,6 +31,11 @@ import org.ros.node.topic.Subscriber;
*/ */
public class Listener implements NodeMain { public class Listener implements NodeMain {
@Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava_tutorial_pubsub/listener");
}
@Override @Override
public void onStart(Node node) { public void onStart(Node node) {
final Log log = node.getLog(); final Log log = node.getLog();
......
...@@ -16,46 +16,47 @@ ...@@ -16,46 +16,47 @@
package org.ros.tutorials.pubsub; package org.ros.tutorials.pubsub;
import com.google.common.base.Preconditions; import org.ros.concurrent.CancellableLoop;
import org.ros.namespace.GraphName;
import org.ros.node.Node; import org.ros.node.Node;
import org.ros.node.NodeMain; import org.ros.node.NodeMain;
import org.ros.node.topic.Publisher; import org.ros.node.topic.Publisher;
/** /**
* This is a simple rosjava {@link Publisher} {@link Node}. It assumes an * A simple {@link Publisher} {@link Node}.
* external roscore is already running.
* *
* @author ethan.rublee@gmail.com (Ethan Rublee)
* @author damonkohler@google.com (Damon Kohler) * @author damonkohler@google.com (Damon Kohler)
*/ */
public class Talker implements NodeMain { public class Talker implements NodeMain {
private Node node; @Override
public GraphName getDefaultNodeName() {
return new GraphName("rosjava_tutorial_pubsub/talker");
}
@Override @Override
public void onStart(Node node) { public void onStart(final Node node) {
Preconditions.checkState(this.node == null); final Publisher<org.ros.message.std_msgs.String> publisher =
this.node = node;
try {
Publisher<org.ros.message.std_msgs.String> publisher =
node.newPublisher("chatter", "std_msgs/String"); node.newPublisher("chatter", "std_msgs/String");
int seq = 0; // This CancellableLoop will be canceled automatically when the Node shuts
while (true) { // down.
node.executeCancellableLoop(new CancellableLoop() {
private int sequenceNumber;
@Override
protected void setup() {
sequenceNumber = 0;
}
@Override
protected void loop() throws InterruptedException {
org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String(); org.ros.message.std_msgs.String str = new org.ros.message.std_msgs.String();
str.data = "Hello world! " + seq; str.data = "Hello world! " + sequenceNumber;
publisher.publish(str); publisher.publish(str);
node.getLog().info("Hello, world! " + seq); sequenceNumber++;
seq++;
Thread.sleep(1000); Thread.sleep(1000);
} }
} catch (Exception e) { });
if (node != null) {
node.getLog().fatal(e);
} else {
e.printStackTrace();
}
}
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment