gcsImplementations.spreadGcs
Class SpreadGcsConnection

java.lang.Object
  extended by gcs.GcsConnection
      extended by gcsImplementations.spreadGcs.SpreadGcsConnection

public class SpreadGcsConnection
extends GcsConnection

Spread back-end implementation of the GcsConnection.

Author:
tkob
See Also:
GcsConnection

Constructor Summary
SpreadGcsConnection()
           
 
Method Summary
 void add(GcsAdvancedMessageListener listener)
          Sets up the GcsAdvancedMessageListener listener.
 void add(GcsBasicMessageListener listener)
          Sets up the GcsBasicMessageListener listener.
 void connect(GcsSettings settings, java.lang.String privateName, boolean priority, boolean groupMembership)
          Allows connecting to the RestGroups server.
 void disconnect()
          Allows disconnecting from the RestGroups server.
 GcsGroup getPrivateGroup()
          Returns the GcsGroup object representing the private group for this connection.
 void multicast(GcsMessage message)
          Sends the message encapsulated in the GcsMessage object to groups specified in this object.
 void multicast(GcsMessage[] messages)
          Sends multiple messages encapsulated in the GcsMessage objects to groups specified inside those objects.
 boolean poll()
          Checks for unread messages for this connection.
 GcsMessage receive()
          Returns next unread message for this connection if available.
 GcsMessage[] receive(int numMessages)
          Returns next numMessages for this connection if available.
 void remove(GcsAdvancedMessageListener listener)
          Deactivates the GcsAdvancedMessageListener listener for this connection.
 void remove(GcsBasicMessageListener listener)
          Deactivates the GcsBasicMessageListener listener for this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpreadGcsConnection

public SpreadGcsConnection()
Method Detail

add

public void add(GcsAdvancedMessageListener listener)
         throws GcsException
Description copied from class: GcsConnection
Sets up the GcsAdvancedMessageListener listener. Once it is done, every time a membership or regular message is received GcsAdvancedMessageListener.membershipMessageReceived(GcsMessage) or GcsAdvancedMessageListener.regularMessageReceived(GcsMessage) method is called, respectively.

Specified by:
add in class GcsConnection
Parameters:
listener - object implementing the GcsAdvancedMessageListener interface
Throws:
GcsException
See Also:
GcsConnection.remove(GcsAdvancedMessageListener)

add

public void add(GcsBasicMessageListener listener)
         throws GcsException
Description copied from class: GcsConnection
Sets up the GcsBasicMessageListener listener. Once it is done, every time a regular message is received, GcsBasicMessageListener.messageReceived(GcsMessage) method is called. Membership messages are omitted.

Specified by:
add in class GcsConnection
Parameters:
listener - object implementing the GcsBasicMessageListener interface
Throws:
GcsException
See Also:
GcsConnection.remove(GcsBasicMessageListener)

connect

public void connect(GcsSettings settings,
                    java.lang.String privateName,
                    boolean priority,
                    boolean groupMembership)
             throws GcsException
Description copied from class: GcsConnection
Allows connecting to the RestGroups server. Once the connection is established the GcsConnection object can be used to send and receive messages through the RestGroups communication system.

Specified by:
connect in class GcsConnection
Parameters:
settings - stores parameters concerning the RestGroups server
privateName - name describing this connections user
priority - defines if this is a priority connection
groupMembership - defines if the membership messages are being received on this connection
Throws:
GcsException - if the connection could not be established

disconnect

public void disconnect()
                throws GcsException
Description copied from class: GcsConnection
Allows disconnecting from the RestGroups server.

Specified by:
disconnect in class GcsConnection
Throws:
GcsException - if difficulties during disconnecting from the RestGroups server were encountered or the connection has not been established

getPrivateGroup

public GcsGroup getPrivateGroup()
                         throws GcsException
Description copied from class: GcsConnection
Returns the GcsGroup object representing the private group for this connection.

Specified by:
getPrivateGroup in class GcsConnection
Returns:
the private group object for this connection
Throws:
GcsException

multicast

public void multicast(GcsMessage message)
               throws GcsException
Description copied from class: GcsConnection
Sends the message encapsulated in the GcsMessage object to groups specified in this object.

Specified by:
multicast in class GcsConnection
Parameters:
message - a message to be send
Throws:
GcsException - if errors were encountered during sending the message or the connection is broken

multicast

public void multicast(GcsMessage[] messages)
               throws GcsException
Description copied from class: GcsConnection
Sends multiple messages encapsulated in the GcsMessage objects to groups specified inside those objects.

Specified by:
multicast in class GcsConnection
Parameters:
messages - array of messages to be send
Throws:
GcsException - if errors were encountered during sending the messages or the connection is broken

poll

public boolean poll()
             throws GcsException
Description copied from class: GcsConnection
Checks for unread messages for this connection.

Specified by:
poll in class GcsConnection
Returns:
true if there is at least one unread message, false otherwise
Throws:
GcsException - if errors were encountered during checking for new messages or the connection is broken

receive

public GcsMessage receive()
                   throws GcsException,
                          java.io.InterruptedIOException
Description copied from class: GcsConnection
Returns next unread message for this connection if available. It blocks otherwise.

Specified by:
receive in class GcsConnection
Returns:
received message
Throws:
GcsException - if errors were encountered during reception of the message or the connection is broken
java.io.InterruptedIOException

receive

public GcsMessage[] receive(int numMessages)
                     throws GcsException,
                            java.io.InterruptedIOException
Description copied from class: GcsConnection
Returns next numMessages for this connection if available. It blocks otherwise.

Specified by:
receive in class GcsConnection
Parameters:
numMessages - number of messages to be returned
Returns:
array of unread messages
Throws:
GcsException - if errors were encountered during reception of the messages or the connection is broken
java.io.InterruptedIOException

remove

public void remove(GcsAdvancedMessageListener listener)
            throws GcsException
Description copied from class: GcsConnection
Deactivates the GcsAdvancedMessageListener listener for this connection. Once its done, both membership and regular messages will be stored on the server until the listener will be setup again or method GcsConnection.receive() (GcsConnection.receive(int)) called.

Specified by:
remove in class GcsConnection
Parameters:
listener - the listener to be removed from this connection
Throws:
GcsException - if errors were encountered during removal of the listener or if it was never set up.
See Also:
GcsConnection.add(GcsAdvancedMessageListener)

remove

public void remove(GcsBasicMessageListener listener)
            throws GcsException
Description copied from class: GcsConnection
Deactivates the GcsBasicMessageListener listener for this connection. Once its done, regular messages will be stored on the server until the listener will be setup again or method (GcsConnection.receive() ( GcsConnection.receive(int)) called.

Specified by:
remove in class GcsConnection
Parameters:
listener - the listener to be removed from this connection
Throws:
GcsException - if errors were encountered during removal of the listener or if it was never set up.
See Also:
GcsConnection.add(GcsBasicMessageListener)