GemFire 7.0

com.gemstone.gemfire.cache.util
Class UniversalMembershipListenerAdapter

java.lang.Object
  extended by com.gemstone.gemfire.cache.util.UniversalMembershipListenerAdapter
All Implemented Interfaces:
SystemMembershipListener

public abstract class UniversalMembershipListenerAdapter
extends Object
implements SystemMembershipListener

The UniversalMembershipListenerAdapter is a wrapper for SystemMembershipListener and BridgeMembershipListener, providing a facade that makes both appear to customer code as a single SystemMembershipListener from the Admin API. This includes adapting BridgeMembershipListener events to appear as events for the SystemMembershipListener.

UniversalMembershipListenerAdapter implements SystemMembershipListener, exposing the callbacks in that interface as methods to be overridden by the customer.

An internal implementation of BridgeMembershipListener is registered when this class is instantiated. This implementation creates a SystemMembershipEvent and calls the corresponding SystemMembershipListener public methods on UniversalMembershipListenerAdapter. To the customer code, the BridgeMembershipEvents are wrapped to appear as SystemMembershipEvents. In this way, both types of membership events appear as SystemMembershipEvents, allowing customer code written using the Admin API to continue working by changing the listener implementation to simply extend this class.

Any BridgeServer using the UniversalMembershipListenerAdapter will receive notifications of system membership changes and bridge membership changes through a single listener.

Any bridge client using the UniversalMembershipListenerAdapter would receive notifications of bridge server connection changes. If that bridge client also creates a connection to the GemFire DistributedSystem, then it will also receive notifications of system membership changes.

Subclasses of UniversalMembershipListenerAdapter may be registered as a SystemMembershipListener using AdminDistributedSystem.addMembershipListener(com.gemstone.gemfire.admin.SystemMembershipListener). It is best, however, to register the listener using registerMembershipListener(com.gemstone.gemfire.admin.AdminDistributedSystem) since this allows the adapter to prevent duplicate events for members that are both a system member and a bridge member.

Simply constructing the UniversalMembershipListenerAdapter results in the underlying BridgeMembershipListener also being registered.

The following code illustrates how a BridgeServer application would use UniversalMembershipListenerAdapter. The code in this example assumes that the class MyMembershipListenerImpl extends UniversalMembershipListenerAdapter:


 public class MyMembershipListenerImpl extends UniversalMembershipListenerAdapter {
   public void memberCrashed(SystemMembershipEvent event) {
     // customer code
   }
   public void memberLeft(SystemMembershipEvent event) {
     // customer code
   }
   public void memberJoined(SystemMembershipEvent event) {
     // customer code
   }
 }

 DistributedSystemConfig config = 
   AdminDistributedSystemFactory.defineDistributedSystem(myDS, null);
 AdminDistributedSystem adminDS = 
   AdminDistributedSystemFactory.getDistributedSystem(config);
 adminDS.connect();
 MyMembershipListenerImpl myListener = new MyMembershipListenerImpl();
 myListener.registerMembershipListener(adminDS);
 
The callbacks on MyMembershipListenerImpl would then be invoked for all SystemMembershipEvents and BridgeMembershipEvents. The latter will appear to be SystemMembershipEvents.

Similarly, the following code illustrates how a bridge client application would use UniversalMembershipListenerAdapter, where MyMembershipListenerImpl is a subclass. Simply by constructing this subclass of UniversalMembershipListenerAdapter it is registering itself as a BridgeMembershipListener:


 new MyMembershipListenerImpl();
 
A bridge client that also connects to the DistributedSystem could register with theAdminDistributedSystem as shown above.

It is recommended that subclasses register with the AdminDistributedSystem using registerMembershipListener(com.gemstone.gemfire.admin.AdminDistributedSystem), as this will prevent duplicate events for members that are both bridge members and system members. If duplicate events are acceptable, you may register subclasses using AdminDistributedSystem#addMembershipListener.

Since:
4.2.1

Nested Class Summary
static class UniversalMembershipListenerAdapter.AdaptedMembershipEvent
          Adapts BridgeMembershipEvent to look like a SystemMembershipEvent
 
Field Summary
static int DEFAULT_HISTORY_SIZE
          Default number of historical events to track in order to avoid duplicate events for members that are both bridge members and system members; value is 100.
 
Constructor Summary
UniversalMembershipListenerAdapter()
          Constructs an instance of UniversalMembershipListenerAdapter.
UniversalMembershipListenerAdapter(int historySize)
          Constructs an instance of UniversalMembershipListenerAdapter.
 
Method Summary
 void memberCrashed(SystemMembershipEvent event)
          Invoked when a member has unexpectedly left the distributed system.
 void memberJoined(SystemMembershipEvent event)
          Invoked when a member has joined the distributed system.
 void memberLeft(SystemMembershipEvent event)
          Invoked when a member has gracefully left the distributed system.
 void registerBridgeMembershipListener()
          Registers this adapter as a BridgeMembershipListener.
 void registerMembershipListener(AdminDistributedSystem admin)
          Registers this adapter with the AdminDistributedSystem.
 void unregisterBridgeMembershipListener()
          Unregisters this adapter as a BridgeMembershipListener.
 void unregisterMembershipListener(AdminDistributedSystem admin)
          Unregisters this adapter with the AdminDistributedSystem.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HISTORY_SIZE

public static final int DEFAULT_HISTORY_SIZE
Default number of historical events to track in order to avoid duplicate events for members that are both bridge members and system members; value is 100.

See Also:
Constant Field Values
Constructor Detail

UniversalMembershipListenerAdapter

public UniversalMembershipListenerAdapter()
Constructs an instance of UniversalMembershipListenerAdapter.


UniversalMembershipListenerAdapter

public UniversalMembershipListenerAdapter(int historySize)
Constructs an instance of UniversalMembershipListenerAdapter.

Parameters:
historySize - number of historical events to track in order to avoid duplicate events for members that are both bridge members and system members; must a number between 10 and Integer.MAX_INT
Throws:
IllegalArgumentException - if historySizde is less than 10
Method Detail

registerMembershipListener

public void registerMembershipListener(AdminDistributedSystem admin)
Registers this adapter with the AdminDistributedSystem. Registering in this way allows the adapter to ensure that callbacks will not be invoked twice for members that have a bridge connection and a system connection. If you register with AdminDistributedSystem.addMembershipListener(com.gemstone.gemfire.admin.SystemMembershipListener) then duplicate events may occur for members that are both bridge members and system.


unregisterMembershipListener

public void unregisterMembershipListener(AdminDistributedSystem admin)
Unregisters this adapter with the AdminDistributedSystem. If registration is performed with registerMembershipListener(com.gemstone.gemfire.admin.AdminDistributedSystem) then this method must be used to successfuly unregister the adapter.


registerBridgeMembershipListener

public void registerBridgeMembershipListener()
Registers this adapter as a BridgeMembershipListener. Registration is automatic when constructing this adapter, so this call is no necessary unless it was previously unregistered by calling unregisterBridgeMembershipListener().


unregisterBridgeMembershipListener

public void unregisterBridgeMembershipListener()
Unregisters this adapter as a BridgeMembershipListener.

See Also:
registerBridgeMembershipListener()

memberJoined

public void memberJoined(SystemMembershipEvent event)
Invoked when a member has joined the distributed system. Also invoked when a client has connected to this process or when this process has connected to a BridgeServer.

Specified by:
memberJoined in interface SystemMembershipListener

memberLeft

public void memberLeft(SystemMembershipEvent event)
Invoked when a member has gracefully left the distributed system. Also invoked when a client has gracefully disconnected from this process. or when this process has gracefully disconnected from a BridgeServer.

Specified by:
memberLeft in interface SystemMembershipListener

memberCrashed

public void memberCrashed(SystemMembershipEvent event)
Invoked when a member has unexpectedly left the distributed system. Also invoked when a client has unexpectedly disconnected from this process or when this process has unexpectedly disconnected from a BridgeServer.

Specified by:
memberCrashed in interface SystemMembershipListener

GemFire 7.0

Copyright © 1997-2012 VMware, Inc. All rights reserved.