org.jboss.messaging.core.distributed
Class PeerSupport

java.lang.Object
  extended byorg.jboss.messaging.core.distributed.PeerSupport
All Implemented Interfaces:
Peer, PeerFacade, ServerFacade
Direct Known Subclasses:
QueuePeer, org.jboss.messaging.core.distributed.replicator.ReplicatorPeer

public abstract class PeerSupport
extends java.lang.Object
implements Peer, PeerFacade

The class that mediates the access of a distributed destination instance to the group. Provides generic behavior in top of which subclasses must layer their specific behavior.

Version:
$Revision: 549 $ $Id: PeerSupport.java 549 2005-12-28 07:03:59Z ovidiu $
Author:
Ovidiu Feodorov

Field Summary
protected  RpcDispatcher dispatcher
           
protected  boolean joined
           
protected  java.io.Serializable peerID
           
protected  RpcServer rpcServer
           
static long TIMEOUT
           
protected  ViewKeeper viewKeeper
           
 
Constructor Summary
PeerSupport(java.io.Serializable peerID, java.io.Serializable groupID, RpcDispatcher dispatcher)
          Use this to create a PeerSupport with an internal ViewKeeper.
PeerSupport(java.io.Serializable peerID, ViewKeeper viewKeeper, RpcDispatcher dispatcher)
          Use this to create a PeerSupport with an external ViewKeeper.
 
Method Summary
protected abstract  RemotePeer createRemotePeer(RemotePeerInfo newRemotePeerInfo)
          Create a local representation of a remote peer.
protected abstract  void doJoin()
           
protected abstract  void doLeave()
           
 void exclude(PeerIdentity originator)
          Method invocation received by all group peers when a peer wants to leave the group.
 RpcDispatcher getDispatcher()
           
 java.io.Serializable getGroupID()
           
 java.io.Serializable getID()
          Return the ID under which server object is registered with the RpcServer.
 PeerIdentity getPeerIdentity()
           
protected abstract  RemotePeerInfo getRemotePeerInfo()
          Create a representation of myself to be returned to other peers that need this information.
 java.util.Set getView()
          Returns a Set of PeerIdentity instances corresponding to peers that are part of the group.
 boolean hasJoined()
           
 RemotePeerInfo include(RemotePeerInfo newPeerInfo)
          Method invocation received by all group peers when a new peer wants to join the group.
 void join()
          Connects the peer to the distributed destination.
 void leave()
          Stops the peer and disconnects it from the distributed destination.
 java.util.Set ping()
          Return a Set of PeerIdentity instances corresponding to peers that are part of the group, as a result of a dynamic query.
 PeerIdentity ping(PeerIdentity originator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

public static final long TIMEOUT
See Also:
Constant Field Values

dispatcher

protected RpcDispatcher dispatcher

rpcServer

protected RpcServer rpcServer

viewKeeper

protected ViewKeeper viewKeeper

peerID

protected java.io.Serializable peerID

joined

protected boolean joined
Constructor Detail

PeerSupport

public PeerSupport(java.io.Serializable peerID,
                   java.io.Serializable groupID,
                   RpcDispatcher dispatcher)
Use this to create a PeerSupport with an internal ViewKeeper.

Throws:
java.lang.IllegalStateException - in case the dispatcher is not configured with an RpcServer

PeerSupport

public PeerSupport(java.io.Serializable peerID,
                   ViewKeeper viewKeeper,
                   RpcDispatcher dispatcher)
Use this to create a PeerSupport with an external ViewKeeper.

Parameters:
viewKeeper - must contain the valid group ID. This peer support will use the group ID obtained from the viewKeeper to connect to the group.
Throws:
java.lang.IllegalStateException - in case the dispatcher is not configured with an RpcServer
Method Detail

getGroupID

public java.io.Serializable getGroupID()
Specified by:
getGroupID in interface Peer

getPeerIdentity

public PeerIdentity getPeerIdentity()
Specified by:
getPeerIdentity in interface Peer

hasJoined

public boolean hasJoined()
Specified by:
hasJoined in interface Peer

getDispatcher

public RpcDispatcher getDispatcher()
Specified by:
getDispatcher in interface Peer

getView

public java.util.Set getView()
Description copied from interface: Peer
Returns a Set of PeerIdentity instances corresponding to peers that are part of the group. It may return an empty set (in case the peer didn't join the group yet), but never null.

Specified by:
getView in interface Peer

join

public void join()
          throws DistributedException
Description copied from interface: Peer
Connects the peer to the distributed destination. The underlying JChannel must be connected at the time of the call.

Specified by:
join in interface Peer
Throws:
DistributedException - - a wrapper for exceptions thrown by the distributed layer.

leave

public void leave()
           throws DistributedException
Description copied from interface: Peer
Stops the peer and disconnects it from the distributed destination.

Specified by:
leave in interface Peer
Throws:
DistributedException - - a wrapper for exceptions thrown by the distributed layer.

ping

public java.util.Set ping()
                   throws DistributedException
Description copied from interface: Peer
Return a Set of PeerIdentity instances corresponding to peers that are part of the group, as a result of a dynamic query. Returns an empty set if the peer is not currently part of any group.

Specified by:
ping in interface Peer
Throws:
DistributedException

getID

public java.io.Serializable getID()
Description copied from interface: ServerFacade
Return the ID under which server object is registered with the RpcServer.

Specified by:
getID in interface ServerFacade

include

public RemotePeerInfo include(RemotePeerInfo newPeerInfo)
                       throws java.lang.Throwable
Description copied from interface: PeerFacade
Method invocation received by all group peers when a new peer wants to join the group.

Specified by:
include in interface PeerFacade
Returns:
a RemotePeerInfo representing the current peer. The new peer may use this information to create a RemotePeer representation of this peer.
Throws:
java.lang.Throwable - - negative acknowledgment. The join is vetoed (willingly or unwillingly) by this member.

exclude

public void exclude(PeerIdentity originator)
Description copied from interface: PeerFacade
Method invocation received by all group peers when a peer wants to leave the group.

Specified by:
exclude in interface PeerFacade

ping

public PeerIdentity ping(PeerIdentity originator)
Specified by:
ping in interface PeerFacade

doJoin

protected abstract void doJoin()
                        throws DistributedException
Throws:
DistributedException

doLeave

protected abstract void doLeave()
                         throws DistributedException
Throws:
DistributedException

createRemotePeer

protected abstract RemotePeer createRemotePeer(RemotePeerInfo newRemotePeerInfo)
Create a local representation of a remote peer.


getRemotePeerInfo

protected abstract RemotePeerInfo getRemotePeerInfo()
Create a representation of myself to be returned to other peers that need this information.



Copyright © 2006 JBoss Inc. All Rights Reserved.