Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.ubermq.chord.jms
Class LocalChordNode  view LocalChordNode download LocalChordNode.java

java.lang.Object
  extended bycom.ubermq.chord.AbstractChordNode
      extended bycom.ubermq.chord.jms.LocalChordNode
All Implemented Interfaces:
com.ubermq.chord.ChordNode, com.ubermq.chord.ChordNodeProvider, javax.jms.MessageListener

public class LocalChordNode
extends com.ubermq.chord.AbstractChordNode
implements com.ubermq.chord.ChordNodeProvider, javax.jms.MessageListener

A local chord node that provides storage functionality to the infrastructure.

This implementation can be interacted with via JMS chord messages.


Field Summary
private  javax.jms.TopicSubscriber announceSub
           
private static ClockDaemon cd
          A clock daemon for periodic refresh operations.
static java.lang.String CHORD_COMMAND_PREFIX
          The prefix for chord command topics.
static java.lang.String CHORD_FINGER_TABLE_KEY
          A special key that contains a List of ChordNode objects describing this node's finger table.
static java.lang.String CHORD_IDENTIFIER
          The node identifier.
static java.lang.String CHORD_LOCAL_KEYS
          A Collection of keys stored at this node.
static java.lang.String CHORD_NODE_LOCATOR_QUERY_PROP
           
static java.lang.String CHORD_NODE_LOCATOR_TOPIC
          Broadcasting a message to this topic with the Query property set to true will invoke a set of replies on the same topic that have the URI property set to a valid addressable node URI.
static java.lang.String CHORD_NODE_LOCATOR_URI_PROP
           
static java.lang.String CHORD_PREDECESSOR
          The predecessor node special query key.
private  java.util.Map data
           
static com.ubermq.chord.ChordIdentifierFactory DEFAULT_IDENTIFIER_FACTORY
          The default identifier factory, usable for most applications.
private static long FIX_FINGER_PERIOD
          Period used for stabilization operations.
private  MessageServer ms
           
private  java.net.URI serviceURI
           
private static long STABILIZE_PERIOD
          Period used for stabilization operations.
private  javax.jms.TopicConnection tc
           
private  javax.jms.TopicPublisher tpub
           
private  javax.jms.TopicSession ts
           
private  javax.jms.TopicSubscriber tsub
           
 
Fields inherited from class com.ubermq.chord.AbstractChordNode
 
Constructor Summary
LocalChordNode(MessageServer ms, com.ubermq.chord.ChordIdentifier id, int m)
          Constructs a chord server node at the local machine.
 
Method Summary
 void close()
          Closes the node's resources.
static com.ubermq.chord.ChordNodeProvider createServerNode(MessageServer ms, com.ubermq.chord.ChordIdentifierFactory identifierFactory)
          Starts a local in-process message server with the given set of properties, and returns the node created.
static java.lang.String getCommandTopic(com.ubermq.chord.ChordIdentifier id)
          Returns the topic that should be used to communicate with a chord node of the given identifier.
 java.net.URI getServiceURI()
          Returns the URI that clients should connect to for communication with this node.
static java.net.URI getServiceURI(java.net.URI serverURI, com.ubermq.chord.ChordIdentifier id)
          Returns the service URI that corresponds to the given server base URI and chord node, by convention.
protected  java.util.Collection keys()
          Returns the collection of keys that are stored locally at this node.
static void main(java.lang.String[] args)
          Provides capabilities to host a chord node here.
protected  void moveItem(java.lang.Object key, com.ubermq.chord.ChordNode destination)
          Moves an item from the local data store to another node as specified.
 void onMessage(javax.jms.Message p0)
          Responds to JMS messages, an alternate way to store or query from this node.
 java.lang.Object query(java.lang.Object key)
          Queries the node for the object indexed at the specified key.
 void store(java.lang.Object key, java.lang.Object value)
          Stores the specified object at the given key, on this node.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class com.ubermq.chord.AbstractChordNode
closestPrecedingFinger, equals, fingers, fixFingers, hashCode, identifier, join, leave, notify, notifyGoingAway, predecessor, stabilize, successor, toHtml
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.ubermq.chord.ChordNodeProvider
fixFingers, stabilize
 
Methods inherited from interface com.ubermq.chord.ChordNode
closestPrecedingFinger, fingers, identifier, join, leave, notify, notifyGoingAway, predecessor, successor, toHtml
 

Field Detail

ms

private final MessageServer ms

serviceURI

private final java.net.URI serviceURI

data

private final java.util.Map data

tc

private final javax.jms.TopicConnection tc

ts

private final javax.jms.TopicSession ts

tsub

private final javax.jms.TopicSubscriber tsub

announceSub

private final javax.jms.TopicSubscriber announceSub

tpub

private final javax.jms.TopicPublisher tpub

DEFAULT_IDENTIFIER_FACTORY

public static final com.ubermq.chord.ChordIdentifierFactory DEFAULT_IDENTIFIER_FACTORY
The default identifier factory, usable for most applications.


CHORD_COMMAND_PREFIX

public static final java.lang.String CHORD_COMMAND_PREFIX
The prefix for chord command topics.

See Also:
Constant Field Values

CHORD_NODE_LOCATOR_TOPIC

public static final java.lang.String CHORD_NODE_LOCATOR_TOPIC
Broadcasting a message to this topic with the Query property set to true will invoke a set of replies on the same topic that have the URI property set to a valid addressable node URI.

See Also:
Constant Field Values

CHORD_NODE_LOCATOR_QUERY_PROP

public static final java.lang.String CHORD_NODE_LOCATOR_QUERY_PROP
See Also:
Constant Field Values

CHORD_NODE_LOCATOR_URI_PROP

public static final java.lang.String CHORD_NODE_LOCATOR_URI_PROP
See Also:
Constant Field Values

CHORD_FINGER_TABLE_KEY

public static final java.lang.String CHORD_FINGER_TABLE_KEY
A special key that contains a List of ChordNode objects describing this node's finger table. This key can be queried through normal query operations.

See Also:
Constant Field Values

CHORD_PREDECESSOR

public static final java.lang.String CHORD_PREDECESSOR
The predecessor node special query key.

See Also:
Constant Field Values

CHORD_IDENTIFIER

public static final java.lang.String CHORD_IDENTIFIER
The node identifier.

See Also:
Constant Field Values

CHORD_LOCAL_KEYS

public static final java.lang.String CHORD_LOCAL_KEYS
A Collection of keys stored at this node.

See Also:
Constant Field Values

cd

private static final ClockDaemon cd
A clock daemon for periodic refresh operations.


STABILIZE_PERIOD

private static final long STABILIZE_PERIOD
Period used for stabilization operations.

See Also:
Constant Field Values

FIX_FINGER_PERIOD

private static final long FIX_FINGER_PERIOD
Period used for stabilization operations.

See Also:
Constant Field Values
Constructor Detail

LocalChordNode

public LocalChordNode(MessageServer ms,
                      com.ubermq.chord.ChordIdentifier id,
                      int m)
               throws javax.jms.JMSException
Constructs a chord server node at the local machine. This requires a local JMS message server.

Method Detail

createServerNode

public static com.ubermq.chord.ChordNodeProvider createServerNode(MessageServer ms,
                                                                  com.ubermq.chord.ChordIdentifierFactory identifierFactory)
                                                           throws java.rmi.RemoteException
Starts a local in-process message server with the given set of properties, and returns the node created. The node is initially not part of an infrastructure.

The node must be joined to an existing infrastructure by the caller, by using the join method.


getCommandTopic

public static java.lang.String getCommandTopic(com.ubermq.chord.ChordIdentifier id)
Returns the topic that should be used to communicate with a chord node of the given identifier.


close

public void close()
Closes the node's resources.

Specified by:
close in interface com.ubermq.chord.ChordNode

store

public void store(java.lang.Object key,
                  java.lang.Object value)
Stores the specified object at the given key, on this node. The node may refuse the key if the hash value is not consistent.

Specified by:
store in interface com.ubermq.chord.ChordNode

getServiceURI

public java.net.URI getServiceURI()
Returns the URI that clients should connect to for communication with this node.

Specified by:
getServiceURI in interface com.ubermq.chord.ChordNodeProvider

getServiceURI

public static java.net.URI getServiceURI(java.net.URI serverURI,
                                         com.ubermq.chord.ChordIdentifier id)
Returns the service URI that corresponds to the given server base URI and chord node, by convention.


query

public java.lang.Object query(java.lang.Object key)
Queries the node for the object indexed at the specified key.

Specified by:
query in interface com.ubermq.chord.ChordNode

keys

protected java.util.Collection keys()
Returns the collection of keys that are stored locally at this node. This method is implemented by subclasses for use by algorithms implemented in this object.


moveItem

protected void moveItem(java.lang.Object key,
                        com.ubermq.chord.ChordNode destination)
Moves an item from the local data store to another node as specified. This is an abstract method so subclasses can make choices like retaining the moved item, or ignoring the move request altogether.


onMessage

public void onMessage(javax.jms.Message p0)
Responds to JMS messages, an alternate way to store or query from this node. This should typically only be called by the messaging infrastructure.

Specified by:
onMessage in interface javax.jms.MessageListener

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


main

public static void main(java.lang.String[] args)
Provides capabilities to host a chord node here.

args: host-port number-of-nodes [well-known-entry-point]