Skip to content
Snippets Groups Projects
Commit ba3dd3e6 authored by Stefan Glaser's avatar Stefan Glaser
Browse files

Added option to specify transport hints.

* Added TransportHints class, currently only containing a TCP-NO-DELAY option.
* Added option to specify transport hints when subscribing to a topic.
* Added transport hints to TopicDeclaration class.
parent 1f2ec3ea
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,7 @@ import org.ros.node.topic.DefaultPublisherListener; ...@@ -65,6 +65,7 @@ import org.ros.node.topic.DefaultPublisherListener;
import org.ros.node.topic.DefaultSubscriberListener; import org.ros.node.topic.DefaultSubscriberListener;
import org.ros.node.topic.Publisher; import org.ros.node.topic.Publisher;
import org.ros.node.topic.Subscriber; import org.ros.node.topic.Subscriber;
import org.ros.node.topic.TransportHints;
import org.ros.time.ClockTopicTimeProvider; import org.ros.time.ClockTopicTimeProvider;
import org.ros.time.TimeProvider; import org.ros.time.TimeProvider;
...@@ -283,7 +284,7 @@ public class DefaultNode implements ConnectedNode { ...@@ -283,7 +284,7 @@ public class DefaultNode implements ConnectedNode {
TopicDescription topicDescription = TopicDescription topicDescription =
nodeConfiguration.getTopicDescriptionFactory().newFromType(messageType); nodeConfiguration.getTopicDescriptionFactory().newFromType(messageType);
TopicDeclaration topicDeclaration = TopicDeclaration topicDeclaration =
TopicDeclaration.newFromTopicName(resolvedTopicName, topicDescription); TopicDeclaration.newFromTopicName(resolvedTopicName, topicDescription, null);
org.ros.message.MessageSerializer<T> serializer = newMessageSerializer(messageType); org.ros.message.MessageSerializer<T> serializer = newMessageSerializer(messageType);
return publisherFactory.newOrExisting(topicDeclaration, serializer); return publisherFactory.newOrExisting(topicDeclaration, serializer);
} }
...@@ -295,11 +296,16 @@ public class DefaultNode implements ConnectedNode { ...@@ -295,11 +296,16 @@ public class DefaultNode implements ConnectedNode {
@Override @Override
public <T> Subscriber<T> newSubscriber(GraphName topicName, String messageType) { public <T> Subscriber<T> newSubscriber(GraphName topicName, String messageType) {
return newSubscriber(topicName, messageType, null);
}
@Override
public <T> Subscriber<T> newSubscriber(GraphName topicName, String messageType, TransportHints transportHints) {
GraphName resolvedTopicName = resolveName(topicName); GraphName resolvedTopicName = resolveName(topicName);
TopicDescription topicDescription = TopicDescription topicDescription =
nodeConfiguration.getTopicDescriptionFactory().newFromType(messageType); nodeConfiguration.getTopicDescriptionFactory().newFromType(messageType);
TopicDeclaration topicDeclaration = TopicDeclaration topicDeclaration =
TopicDeclaration.newFromTopicName(resolvedTopicName, topicDescription); TopicDeclaration.newFromTopicName(resolvedTopicName, topicDescription, transportHints);
MessageDeserializer<T> deserializer = newMessageDeserializer(messageType); MessageDeserializer<T> deserializer = newMessageDeserializer(messageType);
Subscriber<T> subscriber = subscriberFactory.newOrExisting(topicDeclaration, deserializer); Subscriber<T> subscriber = subscriberFactory.newOrExisting(topicDeclaration, deserializer);
return subscriber; return subscriber;
...@@ -307,7 +313,12 @@ public class DefaultNode implements ConnectedNode { ...@@ -307,7 +313,12 @@ public class DefaultNode implements ConnectedNode {
@Override @Override
public <T> Subscriber<T> newSubscriber(String topicName, String messageType) { public <T> Subscriber<T> newSubscriber(String topicName, String messageType) {
return newSubscriber(GraphName.of(topicName), messageType); return newSubscriber(GraphName.of(topicName), messageType, null);
}
@Override
public <T> Subscriber<T> newSubscriber(String topicName, String messageType, TransportHints transportHints) {
return newSubscriber(GraphName.of(topicName), messageType, transportHints);
} }
@Override @Override
......
...@@ -43,7 +43,7 @@ public class TopicListResultFactory implements ResultFactory<List<TopicDeclarati ...@@ -43,7 +43,7 @@ public class TopicListResultFactory implements ResultFactory<List<TopicDeclarati
String name = (String) ((Object[]) topic)[0]; String name = (String) ((Object[]) topic)[0];
String type = (String) ((Object[]) topic)[1]; String type = (String) ((Object[]) topic)[1];
descriptions.add(TopicDeclaration.newFromTopicName(GraphName.of(name), new TopicDescription(type, null, descriptions.add(TopicDeclaration.newFromTopicName(GraphName.of(name), new TopicDescription(type, null,
null))); null), null));
} }
return descriptions; return descriptions;
} }
......
...@@ -23,6 +23,7 @@ import org.ros.internal.message.topic.TopicDescription; ...@@ -23,6 +23,7 @@ import org.ros.internal.message.topic.TopicDescription;
import org.ros.internal.transport.ConnectionHeader; import org.ros.internal.transport.ConnectionHeader;
import org.ros.internal.transport.ConnectionHeaderFields; import org.ros.internal.transport.ConnectionHeaderFields;
import org.ros.namespace.GraphName; import org.ros.namespace.GraphName;
import org.ros.node.topic.TransportHints;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -36,6 +37,7 @@ public class TopicDeclaration { ...@@ -36,6 +37,7 @@ public class TopicDeclaration {
private final TopicIdentifier topicIdentifier; private final TopicIdentifier topicIdentifier;
private final TopicDescription topicDescription; private final TopicDescription topicDescription;
private final TransportHints transportHints;
/** /**
* @param header * @param header
...@@ -49,19 +51,26 @@ public class TopicDeclaration { ...@@ -49,19 +51,26 @@ public class TopicDeclaration {
String definition = header.get(ConnectionHeaderFields.MESSAGE_DEFINITION); String definition = header.get(ConnectionHeaderFields.MESSAGE_DEFINITION);
String md5Checksum = header.get(ConnectionHeaderFields.MD5_CHECKSUM); String md5Checksum = header.get(ConnectionHeaderFields.MD5_CHECKSUM);
TopicDescription topicDescription = new TopicDescription(type, definition, md5Checksum); TopicDescription topicDescription = new TopicDescription(type, definition, md5Checksum);
return new TopicDeclaration(new TopicIdentifier(name), topicDescription); boolean tcpNoDelay = "1".equals(header.get(ConnectionHeaderFields.TCP_NODELAY));
return new TopicDeclaration(new TopicIdentifier(name), topicDescription, new TransportHints(tcpNoDelay));
} }
public static TopicDeclaration newFromTopicName(GraphName topicName, public static TopicDeclaration newFromTopicName(GraphName topicName,
TopicDescription topicDescription) { TopicDescription topicDescription, TransportHints transportHints) {
return new TopicDeclaration(new TopicIdentifier(topicName), topicDescription); return new TopicDeclaration(new TopicIdentifier(topicName), topicDescription, transportHints);
} }
public TopicDeclaration(TopicIdentifier topicIdentifier, TopicDescription topicDescription) { public TopicDeclaration(TopicIdentifier topicIdentifier, TopicDescription topicDescription, TransportHints transportHints) {
Preconditions.checkNotNull(topicIdentifier); Preconditions.checkNotNull(topicIdentifier);
Preconditions.checkNotNull(topicDescription); Preconditions.checkNotNull(topicDescription);
this.topicIdentifier = topicIdentifier; this.topicIdentifier = topicIdentifier;
this.topicDescription = topicDescription; this.topicDescription = topicDescription;
if (transportHints != null) {
this.transportHints = transportHints;
} else {
this.transportHints = new TransportHints();
}
} }
public TopicIdentifier getIdentifier() { public TopicIdentifier getIdentifier() {
...@@ -84,6 +93,7 @@ public class TopicDeclaration { ...@@ -84,6 +93,7 @@ public class TopicDeclaration {
topicDescription.getDefinition()); topicDescription.getDefinition());
connectionHeader.addField(ConnectionHeaderFields.MD5_CHECKSUM, connectionHeader.addField(ConnectionHeaderFields.MD5_CHECKSUM,
topicDescription.getMd5Checksum()); topicDescription.getMd5Checksum());
connectionHeader.addField(ConnectionHeaderFields.TCP_NODELAY, transportHints.getTcpNoDelay() ? "1" : "0");
return connectionHeader; return connectionHeader;
} }
......
...@@ -26,6 +26,7 @@ import org.ros.node.service.ServiceResponseBuilder; ...@@ -26,6 +26,7 @@ import org.ros.node.service.ServiceResponseBuilder;
import org.ros.node.service.ServiceServer; import org.ros.node.service.ServiceServer;
import org.ros.node.topic.Publisher; import org.ros.node.topic.Publisher;
import org.ros.node.topic.Subscriber; import org.ros.node.topic.Subscriber;
import org.ros.node.topic.TransportHints;
import java.net.URI; import java.net.URI;
...@@ -82,11 +83,29 @@ public interface ConnectedNode extends Node { ...@@ -82,11 +83,29 @@ public interface ConnectedNode extends Node {
*/ */
<T> Subscriber<T> newSubscriber(GraphName topicName, String messageType); <T> Subscriber<T> newSubscriber(GraphName topicName, String messageType);
/**
* @param <T>
* the message type to create the {@link Subscriber} for
* @param topicName
* the topic name to be subscribed to, this will be auto resolved
* @param messageType
* the message data type (e.g. "std_msgs/String")
* @param transportHints
* the transport hints
* @return a {@link Subscriber} for the specified topic
*/
<T> Subscriber<T> newSubscriber(GraphName topicName, String messageType, TransportHints transportHints);
/** /**
* @see #newSubscriber(GraphName, String) * @see #newSubscriber(GraphName, String)
*/ */
<T> Subscriber<T> newSubscriber(String topicName, String messageType); <T> Subscriber<T> newSubscriber(String topicName, String messageType);
/**
* @see #newSubscriber(GraphName, String, TransportHints)
*/
<T> Subscriber<T> newSubscriber(String topicName, String messageType, TransportHints transportHints);
/** /**
* Create a new {@link ServiceServer}. * Create a new {@link ServiceServer}.
* *
......
package org.ros.node.topic;
import java.util.Map;
import org.ros.internal.transport.ConnectionHeaderFields;
import org.ros.node.ConnectedNode;
import com.google.common.collect.Maps;
/**
* Provides a way of specifying network transport hints to
* {@link ConnectedNode#newSubscriber(String, String)} and
* {@link ConnectedNode#newSubscriber(org.ros.namespace.GraphName, String)}.
*
* @author stefan.glaser@hs-offenburg.de (Stefan Glaser)
*/
public class TransportHints {
Map<String, String> options;
public TransportHints() {
this.options = Maps.newConcurrentMap();
}
public TransportHints(boolean tcpNoDelay) {
tcpNoDelay(tcpNoDelay);
}
public TransportHints tcpNoDelay(boolean nodelay) {
options.put(ConnectionHeaderFields.TCP_NODELAY, nodelay ? "1" : "0");
return this;
}
public boolean getTcpNoDelay() {
return "1".equals(options.get(ConnectionHeaderFields.TCP_NODELAY));
}
public Map<String, String> getOptions() {
return options;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment