gcs
Class GcsMessageListener

java.lang.Object
  extended by gcs.GcsMessageListener
All Implemented Interfaces:
GcsAdvancedMessageListener
Direct Known Subclasses:
SpreadGcsMessageListener

public abstract class GcsMessageListener
extends java.lang.Object
implements GcsAdvancedMessageListener

GcsMessageListener object allows blocking reception of messages through the listener message reception system. It is accomplished by calling getNewMessages() method. It activates the listener and blocks until at least one message is available or stopListener() is called. Upon new message arrival the listener is deactivated and message retrieved by the client.

Author:
tkob

Field Summary
protected  boolean active
           
protected  ProfileEntity mySessionReference
           
protected  java.util.List<GcsMessage> newMessages
           
protected  boolean quitting
           
 
Constructor Summary
protected GcsMessageListener(ProfileEntity mySessionReference)
          Constructor.
 
Method Summary
protected abstract  void activateListener()
          Sets up the listener from the connection.
protected abstract  void deactivateListener()
          Removes the listener from the connection.
abstract  java.util.List<GcsMessage> getNewMessages()
          Used for retrieving new messages.
abstract  boolean isActive()
          Used to check the state of the GcsMessageListener.
abstract  void stopListener()
          Deactivates the listener and causes the getNewMessages() to continue when it is blocked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gcs.GcsAdvancedMessageListener
membershipMessageReceived, regularMessageReceived
 

Field Detail

mySessionReference

protected ProfileEntity mySessionReference

newMessages

protected java.util.List<GcsMessage> newMessages

quitting

protected boolean quitting

active

protected boolean active
Constructor Detail

GcsMessageListener

protected GcsMessageListener(ProfileEntity mySessionReference)
Constructor. The ProfileEntity reference given by the argument is used for retrieving the GcsConnection necessary for the listener to be set up or later removed.

Parameters:
mySessionReference -
Method Detail

activateListener

protected abstract void activateListener()
                                  throws GcsException
Sets up the listener from the connection.

Throws:
GcsException - if the listener can not be set up

deactivateListener

protected abstract void deactivateListener()
                                    throws GcsException
Removes the listener from the connection.

Throws:
GcsException

getNewMessages

public abstract java.util.List<GcsMessage> getNewMessages()
                                                   throws GcsException
Used for retrieving new messages. It returns when at least one message is avaliable or the stopListener() is called.

Returns:
list of new messages
Throws:
GcsException - if problem were encountered during reception of the messages

stopListener

public abstract void stopListener()
                           throws GcsException
Deactivates the listener and causes the getNewMessages() to continue when it is blocked.

Throws:
GcsException - if listener could not be deactivated

isActive

public abstract boolean isActive()
Used to check the state of the GcsMessageListener.

Returns:
true if the listener is set up, false otherwise