ePOST API

rice.p2p.scribe
Class ScribeImpl

java.lang.Object
  extended by rice.p2p.scribe.ScribeImpl
All Implemented Interfaces:
Destructable, Application, Scribe

public class ScribeImpl
extends java.lang.Object
implements Scribe, Application

Version:
$Id: ScribeImpl.java 2885 2006-01-05 12:20:54Z jeffh $
Author:
Alan Mislove

Nested Class Summary
 class ScribeImpl.TopicManager
          Class which keeps track of a given topic
 
Field Summary
protected  Endpoint endpoint
          this application's endpoint
protected  NodeHandle handle
          the local node handle
 int MAINTENANCE_INTERVAL
          The interval with which to perform maintenance
 int MESSAGE_TIMEOUT
          the timeout for a subscribe message
protected  ScribePolicy policy
          this scribe's policy
 java.util.Hashtable topics
          the hashtable of topic -> TopicManager
 
Constructor Summary
ScribeImpl(Node node, ScribePolicy policy, java.lang.String instance)
          Constructor for Scribe
ScribeImpl(Node node, java.lang.String instance)
          Constructor for Scribe, using the default policy.
 
Method Summary
 void addChild(Topic topic, NodeHandle child)
          Adds a child to the given topic
protected  void addChild(Topic topic, NodeHandle child, int id)
          Adds a child to the given topic, using the specified sequence number in the ack message sent to the child.
 void anycast(Topic topic, ScribeContent content)
          Anycasts the given content to a member of the given topic
 void deliver(Id id, Message message)
          This method is called on the application at the destination node for the given id.
 void destroy()
           
 boolean forward(RouteMessage message)
          This method is invoked on applications when the underlying node is about to forward the given message with the provided target to the specified next hop.
 NodeHandle[] getChildren(Topic topic)
          Returns the list of children for a given topic
 ScribeClient[] getClients(Topic topic)
          Returns the list of clients for a given topic
 Environment getEnvironment()
           
 Id getId()
          Returns the Id of the local node
 NodeHandle getParent(Topic topic)
          Returns the parent for a given topic
 ScribePolicy getPolicy()
          Returns the current policy for this scribe object
 Topic[] getTopics(ScribeClient client)
          Returns the list of topics the given client is subscribed to.
 boolean isRoot(Topic topic)
          Returns whether or not this Scribe is the root for the given topic
 void publish(Topic topic, ScribeContent content)
          Publishes the given message to the topic.
 void removeChild(Topic topic, NodeHandle child)
          Removes a child from the given topic
protected  void removeChild(Topic topic, NodeHandle child, boolean sendDrop)
          Removes a child from the given topic
 void setPolicy(ScribePolicy policy)
          Sets the current policy for this scribe object
 void subscribe(Topic topic, ScribeClient client)
          Subscribes the given client to the provided topic.
 void subscribe(Topic topic, ScribeClient client, ScribeContent content)
          Subscribes the given client to the provided topic.
 void unsubscribe(Topic topic, ScribeClient client)
          Unsubscribes the given client from the provided topic.
 void update(NodeHandle handle, boolean joined)
          This method is invoked to inform the application that the given node has either joined or left the neighbor set of the local node, as the set would be returned by the neighborSet call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAINTENANCE_INTERVAL

public final int MAINTENANCE_INTERVAL
The interval with which to perform maintenance


MESSAGE_TIMEOUT

public final int MESSAGE_TIMEOUT
the timeout for a subscribe message


topics

public java.util.Hashtable topics
the hashtable of topic -> TopicManager


policy

protected ScribePolicy policy
this scribe's policy


endpoint

protected Endpoint endpoint
this application's endpoint


handle

protected NodeHandle handle
the local node handle

Constructor Detail

ScribeImpl

public ScribeImpl(Node node,
                  java.lang.String instance)
Constructor for Scribe, using the default policy.

Parameters:
node - The node below this Scribe implementation
instance - The unique instance name of this Scribe

ScribeImpl

public ScribeImpl(Node node,
                  ScribePolicy policy,
                  java.lang.String instance)
Constructor for Scribe

Parameters:
node - The node below this Scribe implementation
policy - The policy for this Scribe
instance - The unique instance name of this Scribe
Method Detail

getEnvironment

public Environment getEnvironment()
Specified by:
getEnvironment in interface Scribe
Returns:

getPolicy

public ScribePolicy getPolicy()
Returns the current policy for this scribe object

Specified by:
getPolicy in interface Scribe
Returns:
The current policy for this scribe

setPolicy

public void setPolicy(ScribePolicy policy)
Sets the current policy for this scribe object

Specified by:
setPolicy in interface Scribe
Parameters:
policy - The current policy for this scribe

getId

public Id getId()
Returns the Id of the local node

Returns:
The Id of the local node

getClients

public ScribeClient[] getClients(Topic topic)
Returns the list of clients for a given topic

Parameters:
topic - The topic to return the clients of
Returns:
The clients of the topic

getChildren

public NodeHandle[] getChildren(Topic topic)
Returns the list of children for a given topic

Specified by:
getChildren in interface Scribe
Parameters:
topic - The topic to return the children of
Returns:
The children of the topic

getParent

public NodeHandle getParent(Topic topic)
Returns the parent for a given topic

Specified by:
getParent in interface Scribe
Parameters:
topic - The topic to return the parent of
Returns:
The parent of the topic

isRoot

public boolean isRoot(Topic topic)
Returns whether or not this Scribe is the root for the given topic

Specified by:
isRoot in interface Scribe
Parameters:
topic - The topic in question
Returns:
Whether or not we are currently the root

subscribe

public void subscribe(Topic topic,
                      ScribeClient client)
Subscribes the given client to the provided topic. Any message published to the topic will be delivered to the Client via the deliver() method.

Specified by:
subscribe in interface Scribe
Parameters:
topic - The topic to subscribe to
client - The client to give messages to

subscribe

public void subscribe(Topic topic,
                      ScribeClient client,
                      ScribeContent content)
Subscribes the given client to the provided topic. Any message published to the topic will be delivered to the Client via the deliver() method.

Specified by:
subscribe in interface Scribe
Parameters:
topic - The topic to subscribe to
client - The client to give messages to
content - The content to include in the subscribe

unsubscribe

public void unsubscribe(Topic topic,
                        ScribeClient client)
Unsubscribes the given client from the provided topic.

Specified by:
unsubscribe in interface Scribe
Parameters:
topic - The topic to unsubscribe from
client - The client to unsubscribe

publish

public void publish(Topic topic,
                    ScribeContent content)
Publishes the given message to the topic.

Specified by:
publish in interface Scribe
Parameters:
topic - The topic to publish to
content - The content to publish

anycast

public void anycast(Topic topic,
                    ScribeContent content)
Anycasts the given content to a member of the given topic

Specified by:
anycast in interface Scribe
Parameters:
topic - The topic to anycast to
content - The content to anycast

addChild

public void addChild(Topic topic,
                     NodeHandle child)
Adds a child to the given topic

Specified by:
addChild in interface Scribe
Parameters:
topic - The topic to add the child to
child - The child to add

addChild

protected void addChild(Topic topic,
                        NodeHandle child,
                        int id)
Adds a child to the given topic, using the specified sequence number in the ack message sent to the child.

Parameters:
topic - The topic
child - THe child to add
id - THe seuqnce number

removeChild

public void removeChild(Topic topic,
                        NodeHandle child)
Removes a child from the given topic

Specified by:
removeChild in interface Scribe
Parameters:
topic - The topic to remove the child from
child - The child to remove

removeChild

protected void removeChild(Topic topic,
                           NodeHandle child,
                           boolean sendDrop)
Removes a child from the given topic

Parameters:
topic - The topic to remove the child from
child - The child to remove
sendDrop - Whether or not to send a drop message to the chil

getTopics

public Topic[] getTopics(ScribeClient client)
Returns the list of topics the given client is subscribed to.

Specified by:
getTopics in interface Scribe
Parameters:
client - The client in question
Returns:
The list of topics

forward

public boolean forward(RouteMessage message)
This method is invoked on applications when the underlying node is about to forward the given message with the provided target to the specified next hop. Applications can change the contents of the message, specify a different nextHop (through re-routing), or completely terminate the message.

Specified by:
forward in interface Application
Parameters:
message - The message being sent, containing an internal message along with a destination key and nodeHandle next hop.
Returns:
Whether or not to forward the message further

deliver

public void deliver(Id id,
                    Message message)
This method is called on the application at the destination node for the given id.

Specified by:
deliver in interface Application
Parameters:
id - The destination id of the message
message - The message being sent

update

public void update(NodeHandle handle,
                   boolean joined)
This method is invoked to inform the application that the given node has either joined or left the neighbor set of the local node, as the set would be returned by the neighborSet call.

Specified by:
update in interface Application
Parameters:
handle - The handle that has joined/left
joined - Whether the node has joined or left

destroy

public void destroy()
Specified by:
destroy in interface Destructable
Specified by:
destroy in interface Scribe

ePOST API

Copyright © 2001-2005 - Rice Pastry.