org.ros.internal.node
Class DefaultNode

java.lang.Object
  extended by org.ros.internal.node.DefaultNode
All Implemented Interfaces:
ConnectedNode, Node

public class DefaultNode
extends java.lang.Object
implements ConnectedNode

The default implementation of a Node.


Constructor Summary
DefaultNode(NodeConfiguration nodeConfiguration, java.util.Collection<NodeListener> nodeListeners, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
          DefaultNodes should only be constructed using the DefaultNodeFactory.
 
Method Summary
 void addListener(NodeListener listener)
          Add a new NodeListener to the Node.
 void executeCancellableLoop(CancellableLoop cancellableLoop)
          Executes a CancellableLoop using the Node's ScheduledExecutorService.
 Time getCurrentTime()
          In ROS, time can be wallclock (actual) or simulated, so it is important to use ConnectedNode.getCurrentTime() instead of using the standard Java routines for determining the current time.
 org.apache.commons.logging.Log getLog()
           
 java.net.URI getMasterUri()
           
 MessageSerializationFactory getMessageSerializationFactory()
           
 GraphName getName()
           
 ParameterTree getParameterTree()
          Create a ParameterTree to query and set parameters on the ROS parameter server.
 NodeNameResolver getResolver()
           
 java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
           
 MessageFactory getServiceRequestMessageFactory()
           
 MessageFactory getServiceResponseMessageFactory()
           
<T,S> ServiceServer<T,S>
getServiceServer(GraphName serviceName)
           
<T,S> ServiceServer<T,S>
getServiceServer(java.lang.String serviceName)
           
 MessageFactory getTopicMessageFactory()
           
 java.net.URI getUri()
           
 java.net.URI lookupServiceUri(GraphName serviceName)
           
 java.net.URI lookupServiceUri(java.lang.String serviceName)
           
<T> Publisher<T>
newPublisher(GraphName topicName, java.lang.String messageType)
           
<T> Publisher<T>
newPublisher(java.lang.String topicName, java.lang.String messageType)
           
<T,S> ServiceClient<T,S>
newServiceClient(GraphName serviceName, java.lang.String serviceType)
          Create a ServiceClient.
<T,S> ServiceClient<T,S>
newServiceClient(java.lang.String serviceName, java.lang.String serviceType)
           
<T,S> ServiceServer<T,S>
newServiceServer(GraphName serviceName, java.lang.String serviceType, ServiceResponseBuilder<T,S> responseBuilder)
          Create a new ServiceServer.
<T,S> ServiceServer<T,S>
newServiceServer(java.lang.String serviceName, java.lang.String serviceType, ServiceResponseBuilder<T,S> responseBuilder)
           
<T> Subscriber<T>
newSubscriber(GraphName topicName, java.lang.String messageType)
           
<T> Subscriber<T>
newSubscriber(java.lang.String topicName, java.lang.String messageType)
           
 void removeListener(NodeListener listener)
          Remove a NodeListener from the Node.
 GraphName resolveName(GraphName name)
          Resolve the given name, using ROS conventions, into a full ROS namespace name.
 GraphName resolveName(java.lang.String name)
           
 void shutdown()
          Shut the node down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultNode

public DefaultNode(NodeConfiguration nodeConfiguration,
                   java.util.Collection<NodeListener> nodeListeners,
                   java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
DefaultNodes should only be constructed using the DefaultNodeFactory.

Parameters:
nodeConfiguration - the NodeConfiguration for this Node
nodeListeners - a Collection of NodeListeners that will be added to this Node before it starts
Method Detail

newPublisher

public <T> Publisher<T> newPublisher(GraphName topicName,
                                     java.lang.String messageType)
Specified by:
newPublisher in interface ConnectedNode
Type Parameters:
T - the message type to create the publisher for
Parameters:
topicName - the topic name, will be pushed down under this namespace unless '/' is prepended.
messageType - the message data type (e.g. "std_msgs/String")
Returns:
a Publisher for the specified topic

newPublisher

public <T> Publisher<T> newPublisher(java.lang.String topicName,
                                     java.lang.String messageType)
Specified by:
newPublisher in interface ConnectedNode
See Also:
ConnectedNode.newPublisher(GraphName, String)

newSubscriber

public <T> Subscriber<T> newSubscriber(GraphName topicName,
                                       java.lang.String messageType)
Specified by:
newSubscriber in interface ConnectedNode
Type Parameters:
T - the message type to create the Subscriber for
Parameters:
topicName - the topic name to be subscribed to, this will be auto resolved
messageType - the message data type (e.g. "std_msgs/String")
Returns:
a Subscriber for the specified topic

newSubscriber

public <T> Subscriber<T> newSubscriber(java.lang.String topicName,
                                       java.lang.String messageType)
Specified by:
newSubscriber in interface ConnectedNode
See Also:
ConnectedNode.newSubscriber(GraphName, String)

newServiceServer

public <T,S> ServiceServer<T,S> newServiceServer(GraphName serviceName,
                                                 java.lang.String serviceType,
                                                 ServiceResponseBuilder<T,S> responseBuilder)
Description copied from interface: ConnectedNode
Create a new ServiceServer.

Specified by:
newServiceServer in interface ConnectedNode
Parameters:
serviceName - the name of the service
serviceType - the type of the service (e.g. "test_ros/AddTwoInts")
responseBuilder - called for every request to build a response
Returns:
a ServiceServer

newServiceServer

public <T,S> ServiceServer<T,S> newServiceServer(java.lang.String serviceName,
                                                 java.lang.String serviceType,
                                                 ServiceResponseBuilder<T,S> responseBuilder)
Specified by:
newServiceServer in interface ConnectedNode
See Also:
ConnectedNode.newServiceServer(GraphName, String, ServiceResponseBuilder)

getServiceServer

public <T,S> ServiceServer<T,S> getServiceServer(GraphName serviceName)
Specified by:
getServiceServer in interface ConnectedNode
Parameters:
serviceName - the GraphName of the ServiceServer
Returns:
the ServiceServer with the given name or null if it does not exist

getServiceServer

public <T,S> ServiceServer<T,S> getServiceServer(java.lang.String serviceName)
Specified by:
getServiceServer in interface ConnectedNode
See Also:
ConnectedNode.getServiceServer(GraphName)

lookupServiceUri

public java.net.URI lookupServiceUri(GraphName serviceName)
Specified by:
lookupServiceUri in interface ConnectedNode
Parameters:
serviceName - the GraphName of the service URI to lookup
Returns:
the URI of the service or null if it does not exist

lookupServiceUri

public java.net.URI lookupServiceUri(java.lang.String serviceName)
Specified by:
lookupServiceUri in interface ConnectedNode
See Also:
ConnectedNode.lookupServiceUri(GraphName)

newServiceClient

public <T,S> ServiceClient<T,S> newServiceClient(GraphName serviceName,
                                                 java.lang.String serviceType)
                                    throws ServiceNotFoundException
Description copied from interface: ConnectedNode
Create a ServiceClient.

Specified by:
newServiceClient in interface ConnectedNode
Parameters:
serviceName - the name of the service
serviceType - the type of the service (e.g. "test_ros/AddTwoInts")
Returns:
a ServiceClient
Throws:
ServiceNotFoundException - thrown if no matching service could be found

newServiceClient

public <T,S> ServiceClient<T,S> newServiceClient(java.lang.String serviceName,
                                                 java.lang.String serviceType)
                                    throws ServiceNotFoundException
Specified by:
newServiceClient in interface ConnectedNode
Throws:
ServiceNotFoundException
See Also:
ConnectedNode.newServiceClient(GraphName, String)

getCurrentTime

public Time getCurrentTime()
Description copied from interface: ConnectedNode
In ROS, time can be wallclock (actual) or simulated, so it is important to use ConnectedNode.getCurrentTime() instead of using the standard Java routines for determining the current time.

Specified by:
getCurrentTime in interface ConnectedNode
Returns:
the current time

getName

public GraphName getName()
Specified by:
getName in interface Node
Returns:
the fully resolved name of this Node, e.g. "/foo/bar/boop"

getLog

public org.apache.commons.logging.Log getLog()
Specified by:
getLog in interface Node
Returns:
Logger for this node, which will also perform logging to /rosout.

resolveName

public GraphName resolveName(GraphName name)
Description copied from interface: Node
Resolve the given name, using ROS conventions, into a full ROS namespace name. Will be relative to the current namespace unless the name is global.

Specified by:
resolveName in interface Node
Parameters:
name - the name to resolve
Returns:
fully resolved ros namespace name

resolveName

public GraphName resolveName(java.lang.String name)
Specified by:
resolveName in interface Node
See Also:
Node.resolveName(GraphName)

shutdown

public void shutdown()
Description copied from interface: Node
Shut the node down.

Specified by:
shutdown in interface Node

getMasterUri

public java.net.URI getMasterUri()
Specified by:
getMasterUri in interface Node
Returns:
URI of MasterXmlRpcEndpoint that this node is attached to.

getResolver

public NodeNameResolver getResolver()
Specified by:
getResolver in interface Node
Returns:
NodeNameResolver for this namespace

getParameterTree

public ParameterTree getParameterTree()
Description copied from interface: ConnectedNode
Create a ParameterTree to query and set parameters on the ROS parameter server.

Specified by:
getParameterTree in interface ConnectedNode
Returns:
ParameterTree with NameResolver in this namespace.

getUri

public java.net.URI getUri()
Specified by:
getUri in interface Node
Returns:
the URI of this Node

getMessageSerializationFactory

public MessageSerializationFactory getMessageSerializationFactory()
Specified by:
getMessageSerializationFactory in interface Node
Returns:
the MessageSerializationFactory used by this node

getTopicMessageFactory

public MessageFactory getTopicMessageFactory()
Specified by:
getTopicMessageFactory in interface Node
Returns:
the MessageFactory used by this node

getServiceRequestMessageFactory

public MessageFactory getServiceRequestMessageFactory()
Specified by:
getServiceRequestMessageFactory in interface Node
Returns:
the MessageFactory used by this node for service requests

getServiceResponseMessageFactory

public MessageFactory getServiceResponseMessageFactory()
Specified by:
getServiceResponseMessageFactory in interface Node
Returns:
the MessageFactory used by this node for service responses

addListener

public void addListener(NodeListener listener)
Description copied from interface: Node
Add a new NodeListener to the Node.

Specified by:
addListener in interface Node
Parameters:
listener - the NodeListener to add

removeListener

public void removeListener(NodeListener listener)
Description copied from interface: Node
Remove a NodeListener from the Node.

If the given NodeListener is not registered, this has no effect.

Specified by:
removeListener in interface Node
Parameters:
listener - the NodeListener to remove

getScheduledExecutorService

public java.util.concurrent.ScheduledExecutorService getScheduledExecutorService()
Specified by:
getScheduledExecutorService in interface Node
Returns:
the ScheduledExecutorService that this Node uses

executeCancellableLoop

public void executeCancellableLoop(CancellableLoop cancellableLoop)
Description copied from interface: Node
Executes a CancellableLoop using the Node's ScheduledExecutorService. The CancellableLoop will be canceled when the Node starts shutting down.

Any blocking calls executed in the provided CancellableLoop can potentially delay Node shutdown and should be avoided.

Specified by:
executeCancellableLoop in interface Node
Parameters:
cancellableLoop - the CancellableLoop to execute