com.sun.sgs.impl.client.simple
Class SimpleClientConnection

java.lang.Object
  extended by com.sun.sgs.impl.client.simple.SimpleClientConnection
All Implemented Interfaces:
ClientConnection, ConnectionListener

 class SimpleClientConnection
extends Object
implements ClientConnection, ConnectionListener

A ClientConnection is the central point of communication with the server. This SimpleClientConnection uses an Connection for its transport. All outbound messages to the server go out via the Connection.send. Incoming messages come in on the ConnectionListener.messageReceived callback and are dispatched to the appropriate callback on either the associated ClientConnectionListener.


Constructor Summary
SimpleClientConnection(ClientConnectionListener listener)
          Creates a new connection implementation.
 
Method Summary
 void bytesReceived(Connection conn, byte[] message)
          Notifies this listener that data arrives on a connection.
 void connected(Connection conn)
          Notifies this listener that the connection is established, either actively from a Connector or passively by an Acceptor.
 void disconnect()
          Asynchronously closes the connection, freeing any resources in use.
 void disconnected(Connection conn)
          Notifies this listener that the connection has been closed, or that it could not be initiated (e.g., when a Connector fails to connect).
 void exceptionThrown(Connection conn, Throwable exception)
          Notifies this listener that a network exception has occurred on the connection.
 void sendMessage(ByteBuffer message)
          Asynchronously sends data to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleClientConnection

SimpleClientConnection(ClientConnectionListener listener)
Creates a new connection implementation.

Parameters:
listener - the listener to receive notification of events
Method Detail

disconnect

public void disconnect()
                throws IOException
Asynchronously closes the connection, freeing any resources in use. The connection should not be considered closed until ClientConnectionListener.disconnected(boolean, byte[]) is invoked.

This implementation disconnects the underlying Connection.

Specified by:
disconnect in interface ClientConnection
Throws:
IOException - if there was a synchronous problem closing the connection

sendMessage

public void sendMessage(ByteBuffer message)
                 throws IOException
Asynchronously sends data to the server.

The specified byte buffer must not be modified after invoking this method; otherwise this method may have unpredictable results.

Specified by:
sendMessage in interface ClientConnection
Parameters:
message - the message data to send
Throws:
IOException - if there was a synchronous problem sending the message

connected

public void connected(Connection conn)
Notifies this listener that the connection is established, either actively from a Connector or passively by an Acceptor. This indicates that the connection is ready for use, and data may be sent and received on it.

This implementation notifies the associated ClientConnectionListener.

Specified by:
connected in interface ConnectionListener
Parameters:
conn - the Connection that has become connected.

disconnected

public void disconnected(Connection conn)
Notifies this listener that the connection has been closed, or that it could not be initiated (e.g., when a Connector fails to connect).

This implementation notifies the associated ClientConnectionListener.

Specified by:
disconnected in interface ConnectionListener
Parameters:
conn - the Connection that has disconnected

exceptionThrown

public void exceptionThrown(Connection conn,
                            Throwable exception)
Notifies this listener that a network exception has occurred on the connection.

Specified by:
exceptionThrown in interface ConnectionListener
Parameters:
conn - the Connection on which the exception occured
exception - the thrown exception

bytesReceived

public void bytesReceived(Connection conn,
                          byte[] message)
Notifies this listener that data arrives on a connection. The message is not guaranteed to be a single, whole message; this method is responsible for message reassembly unless the connection itself guarantees that only complete messages are delivered.

This implementation forwards the message to the associated ClientConnectionListener.

Specified by:
bytesReceived in interface ConnectionListener
Parameters:
conn - the Connection on which the message arrived
message - the received message bytes

Project Darkstar, Version 0.9.9.7
2013-07-29 20:58:27

Copyright © 2007-2013 Sun Microsystems, Inc. All rights reserved