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

Quick Search    Search Deep

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

java.lang.Object
  extended bycom.ubermq.chord.jms.RemoteChordNode
All Implemented Interfaces:
com.ubermq.chord.ChordNode, java.io.Serializable

public class RemoteChordNode
extends java.lang.Object
implements com.ubermq.chord.ChordNode, java.io.Serializable

A proxy for a remote chord node. This implementation uses JMS and the ChordMessage object hierarchy for connectivity.

This object may be serialized across the network as a way to describe chord nodes to other chord participants.


Field Summary
private static java.util.Map cachedNodes
           
private  java.lang.String commandTopic
           
private  boolean connected
           
static long DEFAULT_QUERY_TIMEOUT
          The default query timeout to wait for a response from the remote node.
private  com.ubermq.chord.ChordIdentifier identifier
           
private  Mutex queryMutex
           
private  javax.jms.TopicSubscriber replySub
           
private  javax.jms.Topic replyTopic
           
static long serialVersionUID
           
private  javax.jms.TopicConnection tc
           
private  javax.jms.TopicPublisher tpub
           
private  javax.jms.TopicSession ts
           
private  java.net.URI uri
           
 
Constructor Summary
private RemoteChordNode(com.ubermq.chord.ChordIdentifierFactory f, java.net.URI remoteURI)
           
 
Method Summary
private static void cache(java.net.URI uri, RemoteChordNode n)
           
 void close()
          Closes the node's resources.
 com.ubermq.chord.ChordNode closestPrecedingFinger(com.ubermq.chord.ChordIdentifier id)
          Returns the element of the finger table that most closely precedes the given identifier.
 void connect()
          Connects to the service provider for the remote node.
static RemoteChordNode createRemoteInstance(com.ubermq.chord.ChordIdentifierFactory f, java.net.URI uri)
          Constructs a remote chord node from a JMS topic connection factory.
private  void ensureConnected()
           
 boolean equals(java.lang.Object o)
          Determine whether this Object is semantically equal to another Object.
static java.util.List findNodeAtURI(java.net.URI uri)
          Given a non-specific URI of a message server, this method probes the server for connected nodes and returns the URI of one that is uniquely addressable.
 com.ubermq.chord.ChordNode[] fingers()
          Returns the finger table for this node.
static RemoteChordNode getRemoteRepresentation(com.ubermq.chord.ChordNodeProvider p)
          Creates a remote chord node representation for a local chord node provider.
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 com.ubermq.chord.ChordIdentifier identifier()
          Returns the identifier for this node.
 boolean isConnected()
          Returns true if the connect method has been invoked successfully.
 void join(com.ubermq.chord.ChordInfrastructure i)
          Joins the node to the specified infrastructure.
 void leave(com.ubermq.chord.ChordInfrastructure i)
          Leaves the infrastructure, by notifying the immediate predecessor that we are going away.
private static RemoteChordNode lookup(java.net.URI uri)
          Looks for a remote node with the given URI in the big cache.
 void notify(com.ubermq.chord.ChordNode n)
          Instructs the node that the specified node may be its predecessor.
 void notifyGoingAway(com.ubermq.chord.ChordNode n)
          Instructs the node that the specified node is leaving the infrastructure.
 com.ubermq.chord.ChordNode predecessor()
          Returns the predecessor of this node, defined as the node n such that n.successor() == this.
 java.lang.Object query(java.lang.Object key)
          Queries the node for the object indexed at the specified key.
private  java.lang.Object readResolve()
          Read resolution provides us a way to go through our cached local connections, rather than creating new ones every time.
 void store(java.lang.Object key, java.lang.Object value)
          Stores the specified object at the given key, on this node.
 com.ubermq.chord.ChordNode successor()
          Returns the successor of this node.
 java.lang.String toHtml()
          Returns an in-depth HTML description of this chord node.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

identifier

private final com.ubermq.chord.ChordIdentifier identifier

uri

private final java.net.URI uri

commandTopic

private final java.lang.String commandTopic

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

connected

private transient boolean connected

queryMutex

private transient Mutex queryMutex

tc

private transient javax.jms.TopicConnection tc

ts

private transient javax.jms.TopicSession ts

tpub

private transient javax.jms.TopicPublisher tpub

replyTopic

private transient javax.jms.Topic replyTopic

replySub

private transient javax.jms.TopicSubscriber replySub

cachedNodes

private static final java.util.Map cachedNodes

DEFAULT_QUERY_TIMEOUT

public static final long DEFAULT_QUERY_TIMEOUT
The default query timeout to wait for a response from the remote node.

See Also:
Constant Field Values
Constructor Detail

RemoteChordNode

private RemoteChordNode(com.ubermq.chord.ChordIdentifierFactory f,
                        java.net.URI remoteURI)
Method Detail

lookup

private static RemoteChordNode lookup(java.net.URI uri)
Looks for a remote node with the given URI in the big cache.


cache

private static void cache(java.net.URI uri,
                          RemoteChordNode n)

createRemoteInstance

public static RemoteChordNode createRemoteInstance(com.ubermq.chord.ChordIdentifierFactory f,
                                                   java.net.URI uri)
Constructs a remote chord node from a JMS topic connection factory. The node must be connected with the connect method before being used.


getRemoteRepresentation

public static RemoteChordNode getRemoteRepresentation(com.ubermq.chord.ChordNodeProvider p)
Creates a remote chord node representation for a local chord node provider.


findNodeAtURI

public static java.util.List findNodeAtURI(java.net.URI uri)
                                    throws javax.jms.JMSException
Given a non-specific URI of a message server, this method probes the server for connected nodes and returns the URI of one that is uniquely addressable.


readResolve

private java.lang.Object readResolve()
                              throws java.io.ObjectStreamException
Read resolution provides us a way to go through our cached local connections, rather than creating new ones every time.


connect

public void connect()
             throws javax.jms.JMSException
Connects to the service provider for the remote node.


close

public void close()
Description copied from interface: com.ubermq.chord.ChordNode
Closes the node's resources.

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

isConnected

public boolean isConnected()
Returns true if the connect method has been invoked successfully.


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()).


toHtml

public java.lang.String toHtml()
Description copied from interface: com.ubermq.chord.ChordNode
Returns an in-depth HTML description of this chord node. The information returned could include the set of keys stored here, etc.

It is anticipated that this method may be costly to invoke. Please do not use it for debugging purposes.

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

identifier

public com.ubermq.chord.ChordIdentifier identifier()
Returns the identifier for this node.

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

successor

public com.ubermq.chord.ChordNode successor()
Returns the successor of this node.

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

predecessor

public com.ubermq.chord.ChordNode predecessor()
Description copied from interface: com.ubermq.chord.ChordNode
Returns the predecessor of this node, defined as the node n such that n.successor() == this.

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

notify

public void notify(com.ubermq.chord.ChordNode n)
Instructs the node that the specified node may be its predecessor.

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

notifyGoingAway

public void notifyGoingAway(com.ubermq.chord.ChordNode n)
Description copied from interface: com.ubermq.chord.ChordNode
Instructs the node that the specified node is leaving the infrastructure. This may be received by an existing predecessor or successor node.

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

closestPrecedingFinger

public com.ubermq.chord.ChordNode closestPrecedingFinger(com.ubermq.chord.ChordIdentifier id)
Returns the element of the finger table that most closely precedes the given identifier.

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

join

public void join(com.ubermq.chord.ChordInfrastructure i)
Joins the node to the specified infrastructure. This causes the node to perform any logic that is required to inform itself or other nodes in the infrastructure about its presence.

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

leave

public void leave(com.ubermq.chord.ChordInfrastructure i)
Description copied from interface: com.ubermq.chord.ChordNode
Leaves the infrastructure, by notifying the immediate predecessor that we are going away.

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

fingers

public com.ubermq.chord.ChordNode[] fingers()
Returns the finger table for this node. The finger table is a set of nodes, such that the ith entry contains the identity of the first node that succeeds this node by at least 2 i-1 on the identifier circle.

Specified by:
fingers 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

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

ensureConnected

private void ensureConnected()

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


equals

public boolean equals(java.lang.Object o)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.