org.ros.internal.node.server.master
Class MasterServer

java.lang.Object
  extended by org.ros.internal.node.server.XmlRpcServer
      extended by org.ros.internal.node.server.master.MasterServer
All Implemented Interfaces:
MasterRegistrationListener

public class MasterServer
extends XmlRpcServer
implements MasterRegistrationListener

The MasterServer provides naming and registration services to the rest of the Nodes in the ROS system. It tracks Publishers and Subscribers to TopicSystemStates as well as ServiceServers. The role of the MasterServer is to enable individual ROS Nodes to locate one another. Once these Nodes have located each other they communicate with each other peer-to-peer.

See Also:
Master documentation

Field Summary
static int SYSTEM_STATE_PUBLISHERS
          Position in the getSystemState() for publisher information.
static int SYSTEM_STATE_SERVICES
          Position in the getSystemState() for service information.
static int SYSTEM_STATE_SUBSCRIBERS
          Position in the getSystemState() for subscriber information.
 
Constructor Summary
MasterServer(BindAddress bindAddress, AdvertiseAddress advertiseAddress)
           
 
Method Summary
protected  void contactSubscriberForPublisherUpdate(java.net.URI subscriberSlaveUri, GraphName topicName, java.util.List<java.net.URI> publisherUris)
          Contact a subscriber and send it a publisher update.
 java.util.List<java.lang.Object> getPublishedTopics(GraphName caller, GraphName subgraph)
          Get a list of all topics published for the give subgraph.
 java.util.List<java.lang.Object> getSystemState()
          Get the state of the ROS graph.
 java.util.List<java.util.List<java.lang.String>> getTopicTypes(GraphName calledId)
          Get a List of all TopicSystemState message types.
 java.net.URI lookupNode(GraphName nodeName)
          Returns a NodeIdentifier for the Node with the given name.
 java.net.URI lookupService(GraphName serviceName)
          Lookup the provider of a particular service.
 void onNodeReplacement(NodeRegistrationInfo nodeInfo)
          A node is being replaced.
 java.util.List<java.net.URI> registerPublisher(GraphName nodeName, java.net.URI nodeSlaveUri, GraphName topicName, java.lang.String topicMessageType)
          Register the caller as a Publisher of the specified topic.
 void registerService(GraphName nodeName, java.net.URI nodeSlaveUri, GraphName serviceName, java.net.URI serviceUri)
          Register a service with the master.
 java.util.List<java.net.URI> registerSubscriber(GraphName nodeName, java.net.URI nodeSlaveUri, GraphName topicName, java.lang.String topicMessageType)
          Subscribe the caller to the specified topic.
 void start()
          Start the MasterServer.
 boolean unregisterPublisher(GraphName nodeName, GraphName topicName)
          Unregister a Publisher.
 boolean unregisterService(GraphName nodeName, GraphName serviceName, java.net.URI serviceUri)
          Unregister a service from the master.
 boolean unregisterSubscriber(GraphName nodeName, GraphName topicName)
          Unregister a Subscriber.
 
Methods inherited from class org.ros.internal.node.server.XmlRpcServer
awaitStart, awaitStart, getAddress, getAdvertiseAddress, getPid, getUri, shutdown, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSTEM_STATE_PUBLISHERS

public static final int SYSTEM_STATE_PUBLISHERS
Position in the getSystemState() for publisher information.

See Also:
Constant Field Values

SYSTEM_STATE_SUBSCRIBERS

public static final int SYSTEM_STATE_SUBSCRIBERS
Position in the getSystemState() for subscriber information.

See Also:
Constant Field Values

SYSTEM_STATE_SERVICES

public static final int SYSTEM_STATE_SERVICES
Position in the getSystemState() for service information.

See Also:
Constant Field Values
Constructor Detail

MasterServer

public MasterServer(BindAddress bindAddress,
                    AdvertiseAddress advertiseAddress)
Method Detail

start

public void start()
Start the MasterServer.


registerService

public void registerService(GraphName nodeName,
                            java.net.URI nodeSlaveUri,
                            GraphName serviceName,
                            java.net.URI serviceUri)
Register a service with the master.

Parameters:
nodeName - the GraphName of the Node offering the service
nodeSlaveUri - the URI of the Node's SlaveServer
serviceName - the GraphName of the service
serviceUri - the URI of the service

unregisterService

public boolean unregisterService(GraphName nodeName,
                                 GraphName serviceName,
                                 java.net.URI serviceUri)
Unregister a service from the master.

Parameters:
nodeName - the GraphName of the Node offering the service
serviceName - the GraphName of the service
serviceUri - the URI of the service
Returns:
true if the service was registered

registerSubscriber

public java.util.List<java.net.URI> registerSubscriber(GraphName nodeName,
                                                       java.net.URI nodeSlaveUri,
                                                       GraphName topicName,
                                                       java.lang.String topicMessageType)
Subscribe the caller to the specified topic. In addition to receiving a list of current publishers, the subscriber will also receive notifications of new publishers via the publisherUpdate API.

Parameters:
nodeName - the GraphName of the Node offering the service
nodeSlaveUri - the URI of the Node's SlaveServer
topicName - the GraphName of the subscribed TopicParticipant
topicMessageType - the message type of the topic
Returns:
A List of XMLRPC API URIs for nodes currently publishing the specified topic

unregisterSubscriber

public boolean unregisterSubscriber(GraphName nodeName,
                                    GraphName topicName)
Unregister a Subscriber.

Parameters:
nodeName - the GraphName of the Node offering the service
topicName - the GraphName of the subscribed TopicParticipant
Returns:
true if the Subscriber was registered

registerPublisher

public java.util.List<java.net.URI> registerPublisher(GraphName nodeName,
                                                      java.net.URI nodeSlaveUri,
                                                      GraphName topicName,
                                                      java.lang.String topicMessageType)
Register the caller as a Publisher of the specified topic.

Parameters:
nodeName - the GraphName of the Node offering the service
nodeSlaveUri - the URI of the Node's SlaveServer
topicName - the GraphName of the subscribed TopicParticipant
topicMessageType - the message type of the topic
Returns:
a List of the current Subscribers to the Publisher's TopicSystemState in the form of XML-RPC URIs for each Subscriber's SlaveServer

contactSubscriberForPublisherUpdate

protected void contactSubscriberForPublisherUpdate(java.net.URI subscriberSlaveUri,
                                                   GraphName topicName,
                                                   java.util.List<java.net.URI> publisherUris)
Contact a subscriber and send it a publisher update.

Parameters:
subscriberSlaveUri - the slave URI of the subscriber to contact
topicName - the name of the topic whose publisher URIs are being updated
publisherUris - the new list of publisher URIs to be sent to the subscriber

unregisterPublisher

public boolean unregisterPublisher(GraphName nodeName,
                                   GraphName topicName)
Unregister a Publisher.

Parameters:
nodeName - the GraphName of the Node offering the service
topicName - the GraphName of the subscribed TopicParticipant
Returns:
true if the Publisher was unregistered

lookupNode

public java.net.URI lookupNode(GraphName nodeName)
Returns a NodeIdentifier for the Node with the given name. This API is for looking information about Publishers and Subscribers. Use lookupService(GraphName) instead to lookup ROS-RPC URIs for ServiceServers.

Parameters:
nodeName - name of Node to lookup
Returns:
the URI for the Node slave server with the given name, or null if there is no Node with the given name

getTopicTypes

public java.util.List<java.util.List<java.lang.String>> getTopicTypes(GraphName calledId)
Get a List of all TopicSystemState message types.

Parameters:
calledId - the Node name of the caller
Returns:
a list of the form [[topic 1 name, topic 1 message type], [topic 2 name, topic 2 message type], ...]

getSystemState

public java.util.List<java.lang.Object> getSystemState()
Get the state of the ROS graph.

This includes information about publishers, subscribers, and services.

Returns:
TODO(keith): Fill in.

lookupService

public java.net.URI lookupService(GraphName serviceName)
Lookup the provider of a particular service.

Parameters:
serviceName - name of service
Returns:
URI of the SlaveServer with the provided name, or null if there is no such service.

getPublishedTopics

public java.util.List<java.lang.Object> getPublishedTopics(GraphName caller,
                                                           GraphName subgraph)
Get a list of all topics published for the give subgraph.

Parameters:
caller - name of the caller
subgraph - subgraph containing the requested TopicSystemStates, relative to caller
Returns:
a List of Lists where the nested Lists contain, in order, the TopicSystemState name and TopicSystemState message type

onNodeReplacement

public void onNodeReplacement(NodeRegistrationInfo nodeInfo)
Description copied from interface: MasterRegistrationListener
A node is being replaced.

The information object is about to be trashed, so it should not be hung onto.

Specified by:
onNodeReplacement in interface MasterRegistrationListener
Parameters:
nodeInfo - the node being replaced