com.sun.jini.jeri.internal.mux
Class ConnectionIO

java.lang.Object
  extended by com.sun.jini.jeri.internal.mux.ConnectionIO
Direct Known Subclasses:
SocketChannelConnectionIO, StreamConnectionIO

abstract class ConnectionIO
extends Object

ConnectionIO is an abstraction over a bi-directional byte stream connection that provides the following features: - methods for sending sequences of bytes over the connection atomically (with respect to other threads) and asynchronously, with the option of receiving a notification when a given sequence has been written (i.e. when the buffer used to pass the sequence may again be used) - callbacks invoked on the host Mux object to process data that has been received over the connection, whenever new data arrives The ConnectionIO API uses java.nio.ByteBuffer objects to represent sequences of bytes for writing or reading. The abstraction is intended to be implementable for both blocking streams (requiring separate read and write threads per connection) and non-blocking selectable channels (using a select-based I/O event handler for completing I/O operations that would otherwise block).

Author:
Sun Microsystems, Inc.

Field Summary
(package private)  Mux mux
          the Mux object associated with this instance
 
Constructor Summary
ConnectionIO(Mux mux)
          Constructs a new instance.
 
Method Summary
(package private) abstract  void asyncSend(ByteBuffer buffer)
          Sends the sequence of bytes contained in the supplied buffer to the underlying connection.
(package private) abstract  void asyncSend(ByteBuffer first, ByteBuffer second)
          Sends the sequence of bytes contained in the supplied buffers to the underlying connection.
(package private) abstract  IOFuture futureSend(ByteBuffer first, ByteBuffer second)
          Sends the sequence of bytes contained in the supplied buffers to the underlying connection.
(package private) abstract  void start()
          Start whatever asynchronous activities are required for implementing this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mux

final Mux mux
the Mux object associated with this instance

Constructor Detail

ConnectionIO

ConnectionIO(Mux mux)
Constructs a new instance. The supplied Mux object is used in the following ways: - its processIncomingData method is invoked whenever new data is received over the connection. - its muxLock field is used for mutual exclusion of instance state, as well as for notification of state changes. This lock is shared so that the muxDown field, and notifications of changes to it, are integrated with other state change notifications.

Method Detail

start

abstract void start()
             throws IOException
Start whatever asynchronous activities are required for implementing this instance. This method must be invoked before invoking any of the "send" methods, and data read from the connection will only be dispatched to the Mux object after this method has been invoked.

Throws:
IOException

asyncSend

abstract void asyncSend(ByteBuffer buffer)
Sends the sequence of bytes contained in the supplied buffer to the underlying connection. The sequence of bytes is the contents of the buffer between its current position and its limit. This sequence is guaranteed to be written atomically with respect to other threads invoking this instance's "send" methods. The actual writing to the underlying connection, including access to the buffer's contents and other state, is asynchronous with the invocation of this method; therefore, the supplied buffer must not be mutated even after this method has returned.


asyncSend

abstract void asyncSend(ByteBuffer first,
                        ByteBuffer second)
Sends the sequence of bytes contained in the supplied buffers to the underlying connection. The sequence of bytes is the contents of the first buffer between its current position and its limit, followed by the contents of the second buffer between its current position and its limit. This sequence is guaranteed to be written atomically with respect to other threads invoking this instance's "send" methods. The actual writing to the underlying connection, including access to the buffers' contents and other state, is asynchronous with the invocation of this method; therefore, the supplied buffers must not be mutated even after this method has returned.


futureSend

abstract IOFuture futureSend(ByteBuffer first,
                             ByteBuffer second)
Sends the sequence of bytes contained in the supplied buffers to the underlying connection. The sequence of bytes is the contents of the first buffer between its current position and its limit, followed by the contents of the second buffer between its current position and its limit. This sequence is guaranteed to be written atomically with respect to other threads invoking this instance's "send" methods. The actual writing to the underlying connection, including access to the buffers' contents and other state, is asynchronous with the invocation of this method; therefore, the supplied buffers must not be mutated even after this method has returned, until it is guaranteed that use of the buffers has completed. The returned IOFuture object can be used to wait until the write has definitely completed (or will definitely not complete due to some failure). After the write has completed, each buffers' position will have been incremented to its limit (which will not have changed).



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.