jgroup.relacs.gm
Class MembershipLayer

java.lang.Object
  extended by jgroup.relacs.gm.MembershipLayer
All Implemented Interfaces:
Layer, Layer.FinalizeLayer, MembershipService, EventTags, DispatcherListener

public final class MembershipLayer
extends java.lang.Object
implements MembershipService, DispatcherListener, EventTags

The MembershipLayer class implements the group membership service interface and provide membership events to listeners.

Since:
Jgroup 2.2
Author:
Alberto Montresor, Hein Meling

Nested Class Summary
 
Nested classes/interfaces inherited from interface jgroup.core.Layer
Layer.FinalizeLayer
 
Field Summary
 
Fields inherited from interface jgroup.relacs.events.EventTags
DAEMON_FAILURE_EVENT, DELIVERY_ACK, DELIVERY_EVENT, INSTALL_ACK, INSTALL_EVENT, JOIN_REQUEST, LEAVE_REQUEST, MEMBER_LEFT_EVENT, MULTICAST_REQUEST, PREPARE_ACK, PREPARE_EVENT
 
Method Summary
 void addListener(java.lang.Object listener)
          Add a listener object for this layer to provide upcalls to, in response to membership events.
 void complete(java.lang.Object server)
          Post initialization of the MembershipLayer; invoked once all group manager layers have been constructed.
 int[] eventTypes()
          Returns the set of event types supported by this listener.
 int getGid()
          Returns the group identifier.
static MembershipLayer getLayer(DispatcherService dispatcher)
           
 int getMemberIndex()
          Position index of this member in the array containing the local members of the current view.
 MemberTable getMemberTable()
          Returns a MemberTable helper object that will be notified of changes in the membership.
 MemberId getMyIdentifier()
          Returns the member identifier of the local member.
 int getViewIndex()
          Position index of this member in the array containing the members of the current view.
 boolean isJoining()
          Returns true if the GroupManager is in the process of joining some group.
 boolean isLeader()
          Returns true if the local member is the group leader.
 boolean isMember()
          Returns true if the GroupManager is member of some group.
 boolean isMemberOrJoining()
          Returns true if the GroupManager is member of some group or is in the process of joining some group.
 boolean isUnused()
           
 void join()
          Requests to join the default group associated with the Jgroup daemon.
 void join(int gid)
          Requests to join a group identified by groupId.
 void leave()
          Request to leave a group.
 int members()
          Return the number of members of this group.
 void notifyEvent(Event event)
          This method is invoked by a dispatcher to notify a listener about an event.
 java.lang.String toString()
          Returns a string representation of this object; currently only the status and group identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getLayer

public static MembershipLayer getLayer(DispatcherService dispatcher)
                                throws JgroupException
Throws:
JgroupException

addListener

public void addListener(java.lang.Object listener)
Add a listener object for this layer to provide upcalls to, in response to membership events.

Specified by:
addListener in interface Layer
Parameters:
listener - An Object representation of the listener interface. This will typically be cast to the appropriate listener interface type after checking the type with the instanceof operator.
See Also:
Layer.addListener(java.lang.Object)

complete

public void complete(java.lang.Object server)
              throws JgroupException
Post initialization of the MembershipLayer; invoked once all group manager layers have been constructed. This method is defined in the FinalizeLayer inherited through the MembershipSerivce.

This method is used to determine if the provided server should join the group automatically, as soon as the group manager layer stack has been completed. By default, automatic join is disabled. To enable auto join you must configure it in the applications.xml file.

Specified by:
complete in interface Layer.FinalizeLayer
Parameters:
server - The server using a layer implementing the FinalizeLayer interface.
Throws:
JgroupException - Thrown if the layer could not be completed.

join

public void join()
          throws JgroupException
Description copied from interface: MembershipService
Requests to join the default group associated with the Jgroup daemon.

Each Jgroup daemon has a default group. If a Jgroup daemon does not need to be shared by multiple groups, the application servers may simply join the default group without having to specify group identifiers.

Specified by:
join in interface MembershipService
Throws:
JgroupException - Raised if the membership service receives a request to join a group to which it is already a member.

join

public void join(int gid)
          throws JgroupException
Description copied from interface: MembershipService
Requests to join a group identified by groupId.

Specified by:
join in interface MembershipService
Parameters:
gid - Non-negative integer identifying the group.
Throws:
JgroupException - Raised if the membership service receives a request to join a group to which it is already a member.

leave

public void leave()
           throws JgroupException
Description copied from interface: MembershipService
Request to leave a group. Note that an object member may receive event notifications such as view installations for a group even after having requested to leave the group itself. However, the member will eventually leave the group. When this happens, its hasLeft method is invoked. After this invocation, the member will not receive any further event notification related to the group.

Specified by:
leave in interface MembershipService
Throws:
JgroupException - Rasied if the server is not member of any group, or is already leaving its current group.

isMember

public boolean isMember()
Description copied from interface: MembershipService
Returns true if the GroupManager is member of some group. Otherwise, false is returned.

Specified by:
isMember in interface MembershipService

isJoining

public boolean isJoining()
Description copied from interface: MembershipService
Returns true if the GroupManager is in the process of joining some group. Otherwise, false is returned.

Specified by:
isJoining in interface MembershipService

isMemberOrJoining

public boolean isMemberOrJoining()
Description copied from interface: MembershipService
Returns true if the GroupManager is member of some group or is in the process of joining some group. Otherwise, false is returned.

Specified by:
isMemberOrJoining in interface MembershipService

isUnused

public boolean isUnused()

isLeader

public boolean isLeader()
Description copied from interface: MembershipService
Returns true if the local member is the group leader.

Specified by:
isLeader in interface MembershipService

getMyIdentifier

public MemberId getMyIdentifier()
Description copied from interface: MembershipService
Returns the member identifier of the local member.

Specified by:
getMyIdentifier in interface MembershipService

getGid

public int getGid()
Description copied from interface: MembershipService
Returns the group identifier.

Specified by:
getGid in interface MembershipService

getMemberTable

public MemberTable getMemberTable()
Description copied from interface: MembershipService
Returns a MemberTable helper object that will be notified of changes in the membership. This is used to provide application developers with additional information about members of their current view.

Specified by:
getMemberTable in interface MembershipService

members

public int members()
Description copied from interface: MembershipService
Return the number of members of this group.

Specified by:
members in interface MembershipService

getViewIndex

public int getViewIndex()
Description copied from interface: MembershipService
Position index of this member in the array containing the members of the current view.

Specified by:
getViewIndex in interface MembershipService

getMemberIndex

public int getMemberIndex()
Description copied from interface: MembershipService
Position index of this member in the array containing the local members of the current view.

Specified by:
getMemberIndex in interface MembershipService

eventTypes

public int[] eventTypes()
Description copied from interface: DispatcherListener
Returns the set of event types supported by this listener. Legal event types are given in the EventTags interface.

Specified by:
eventTypes in interface DispatcherListener

notifyEvent

public void notifyEvent(Event event)
Description copied from interface: DispatcherListener
This method is invoked by a dispatcher to notify a listener about an event.

Specified by:
notifyEvent in interface DispatcherListener
Parameters:
event - The Event object to be processed.

toString

public java.lang.String toString()
Returns a string representation of this object; currently only the status and group identifier.

Overrides:
toString in class java.lang.Object


Copyright © 1998-2006 The Jgroup/ARM development team. All Rights Reserved.