com.sun.sgs.impl.io
Class SocketConnection

java.lang.Object
  extended by com.sun.sgs.impl.io.SocketConnection
All Implemented Interfaces:
FilterListener, Connection

public class SocketConnection
extends Object
implements Connection, FilterListener

This is a socket implementation of an Connection using the Apache MINA framework. It uses a MINA IoSession to handle the IO transport.


Constructor Summary
SocketConnection(ConnectionListener listener, CompleteMessageFilter filter, org.apache.mina.common.IoSession session)
          Construct a new SocketConnection with the given listener, filter, and session.
 
Method Summary
 void close()
          Asynchronously closes this connection, freeing any resources in use.
 void filteredMessageReceived(org.apache.mina.common.ByteBuffer buf)
          Dispatches a complete message to this connection's ConnectionListener.
(package private)  ConnectionListener getConnectionListener()
          Returns the ConnectionListener for this connection.
(package private)  CompleteMessageFilter getFilter()
          Returns the IOFilter associated with this connection.
 void sendBytes(byte[] message)
          Asynchronously sends data on this connection.
 void sendUnfiltered(org.apache.mina.common.ByteBuffer buf)
          Sends the given MINA buffer out on the associated IoSession.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnection

SocketConnection(ConnectionListener listener,
                 CompleteMessageFilter filter,
                 org.apache.mina.common.IoSession session)
Construct a new SocketConnection with the given listener, filter, and session.

Parameters:
listener - the ConnectionListener for the Connection
filter - the CompleteMessageFilter for the Connection
session - the IoSession for the Connection
Method Detail

sendBytes

public void sendBytes(byte[] message)
               throws IOException
Asynchronously sends data on this connection.

The specified byte array must not be modified after invoking this method; if the byte array is modified, then this method may have unpredictable results.

This implementation prepends the length of the given byte array as a 4-byte int in network byte-order, and sends it out on the underlying MINA IoSession.

Specified by:
sendBytes in interface Connection
Parameters:
message - the data to send
Throws:
IOException - if the session is not connected

close

public void close()
           throws IOException
Asynchronously closes this connection, freeing any resources in use. The connection should not be considered closed until disconnected is invoked on the listener.

This implementation closes the underlying IoSession.

Specified by:
close in interface Connection
Throws:
IOException - if the session is not connected

filteredMessageReceived

public void filteredMessageReceived(org.apache.mina.common.ByteBuffer buf)
Dispatches a complete message to this connection's ConnectionListener.

Specified by:
filteredMessageReceived in interface FilterListener
Parameters:
buf - a MINA ByteBuffer containing the message to dispatch

sendUnfiltered

public void sendUnfiltered(org.apache.mina.common.ByteBuffer buf)
Sends the given MINA buffer out on the associated IoSession.

Specified by:
sendUnfiltered in interface FilterListener
Parameters:
buf - the MINA ByteBuffer to send

getConnectionListener

ConnectionListener getConnectionListener()
Returns the ConnectionListener for this connection.

Returns:
the listener associated with this connection

getFilter

CompleteMessageFilter getFilter()
Returns the IOFilter associated with this connection.

Returns:
the associated filter

Project Darkstar, Version 0.9.8
2013-07-29 20:18:36

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