Class MessageListenerAdapter
java.lang.Object
org.jgroups.blocks.MessageListenerAdapter
- All Implemented Interfaces:
ExtendedMessageListener, MessageListener
This class provides multiplexing possibilities for
MessageListener
instances. Usually, we have more than one instance willing to listen to
incoming messages, but only one that can produce state for group.
PullPushAdapter allows only one instance of MessageListener
to be registered for message notification. With help of this class you
can overcome this limitation.- Author:
- Roman Rokytskyy (rrokytskyy@acm.org)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HashSetprotected MessageListener[]protected MessageListener -
Constructor Summary
ConstructorsConstructorDescriptionCreate default instance of this class.MessageListenerAdapter(MessageListener mainListener) Create instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddMessageListener(MessageListener listener) Add message listener to this adapter.byte[]getState()Get state from state listener if present.voidgetState(OutputStream ostream) Allows an application to write a state through a provided OutputStream.byte[]Allows an application to provide a partial state as a byte arrayvoidgetState(String state_id, OutputStream ostream) Allows an application to write a partial state through a provided OutputStream.voidReceive message from group.voidremoveMessageListener(MessageListener listener) Remove message listener from this adapter.voidsetState(byte[] state) Set state of ths group.voidsetState(InputStream istream) Allows an application to read a state through a provided InputStream.voidAllows an application to read a partial state indicated by state_id from a given state byte array parameter.voidsetState(String state_id, InputStream istream) Allows an application to read a partial state through a provided InputStream.voidsetStateListener(MessageListener listener) Registerlistenerfor state notification events.
-
Field Details
-
stateListener
-
messageListeners
-
messageListenersCache
-
-
Constructor Details
-
MessageListenerAdapter
public MessageListenerAdapter()Create default instance of this class. Newly created instance will have no message or state listeners. You have to useaddMessageListener(MessageListener)orremoveMessageListener(MessageListener)to add or remove message listeners, andsetStateListener(MessageListener)to set listener that will participate in state transfer. -
MessageListenerAdapter
Create instance of this class.mainListeneris a main listener instance that received message notifications and can get and set group state.- Parameters:
mainListener- instance ofMessageListenerthat will provide state messages.
-
-
Method Details
-
getState
public byte[] getState()Get state from state listener if present.- Specified by:
getStatein interfaceMessageListener- Returns:
- current state of the group state or
nullif no state listeners were registered.
-
getState
Description copied from interface:ExtendedMessageListenerAllows an application to provide a partial state as a byte array- Specified by:
getStatein interfaceExtendedMessageListener- Parameters:
state_id- id of the partial state requested- Returns:
- partial state for the given state_id
-
getState
Description copied from interface:ExtendedMessageListenerAllows an application to write a state through a provided OutputStream. An application is obligated to always close the given OutputStream reference.- Specified by:
getStatein interfaceExtendedMessageListener- Parameters:
ostream- the OutputStream- See Also:
-
getState
Description copied from interface:ExtendedMessageListenerAllows an application to write a partial state through a provided OutputStream. An application is obligated to always close the given OutputStream reference.- Specified by:
getStatein interfaceExtendedMessageListener- Parameters:
state_id- id of the partial state requestedostream- the OutputStream- See Also:
-
receive
Receive message from group. This method will send this message to each message listener that was registered in this adapter.- Specified by:
receivein interfaceMessageListener- Parameters:
msg- message to distribute within message listeners.
-
setState
public void setState(byte[] state) Set state of ths group. This method will delegate call to state listener if it was previously registered.- Specified by:
setStatein interfaceMessageListener- Parameters:
state-
-
setState
Description copied from interface:ExtendedMessageListenerAllows an application to read a partial state indicated by state_id from a given state byte array parameter.- Specified by:
setStatein interfaceExtendedMessageListener- Parameters:
state_id- id of the partial state requestedstate- partial state for the given state_id
-
setState
Description copied from interface:ExtendedMessageListenerAllows an application to read a state through a provided InputStream. An application is obligated to always close the given InputStream reference.- Specified by:
setStatein interfaceExtendedMessageListener- Parameters:
istream- the InputStream- See Also:
-
setState
Description copied from interface:ExtendedMessageListenerAllows an application to read a partial state through a provided InputStream. An application is obligated to always close the given InputStream reference.- Specified by:
setStatein interfaceExtendedMessageListener- Parameters:
state_id- id of the partial state requestedistream- the InputStream- See Also:
-
addMessageListener
Add message listener to this adapter. This method registerslistenerfor message notification.Note, state notification will not be used.
-
removeMessageListener
Remove message listener from this adapter. This method deregisterslistenerfrom message notification. -
setStateListener
Registerlistenerfor state notification events. There can be only one state listener per adapter.
-