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

java.lang.Object
  extended by com.sun.jini.jeri.internal.mux.ConnectionIO
      extended by com.sun.jini.jeri.internal.mux.SocketChannelConnectionIO

final class SocketChannelConnectionIO
extends ConnectionIO

SocketChannelConnectionIO implements the ConnectionIO abstraction for a connection accessible through a java.nio.channels.SocketChannel, and thus supports non-blocking I/O.

Author:
Sun Microsystems, Inc.

Nested Class Summary
private  class SocketChannelConnectionIO.Handler
           
 
Field Summary
private  ByteBuffer[] bufferPair
           
private  SocketChannel channel
          socket channel for underlying connection
private static String detailMessage4854354
          detail message of IOException thrown when 4854354 occurs
private  ByteBuffer inputBuffer
          buffer for reading incoming data from connection
private static int IOV_MAX
           
private  SelectionManager.Key key
           
private static Logger logger
          mux logger
private  LinkedList notifyQueue
          queue of alternating buffers (that are in sendQueue) and IOFuture objects that need to be notified when those buffers are written
private  ByteBuffer[] preallocBufferArray
           
private static int RECEIVE_BUFFER_SIZE
           
private static SelectionManager selectionManager
          selection manager used by this implementation
private  LinkedList sendQueue
          queue of buffers of data to be sent over connection
 
Fields inherited from class com.sun.jini.jeri.internal.mux.ConnectionIO
mux
 
Constructor Summary
SocketChannelConnectionIO(Mux mux, SocketChannel channel)
          Creates a new SocketChannelConnectionIO for the connection represented by the supplied SocketChannel.
 
Method Summary
(package private)  void asyncSend(ByteBuffer buffer)
          Sends the sequence of bytes contained in the supplied buffer to the underlying connection.
(package private)  void asyncSend(ByteBuffer first, ByteBuffer second)
          Sends the sequence of bytes contained in the supplied buffers to the underlying connection.
private  void drainNotifyQueue()
           
(package private)  IOFuture futureSend(ByteBuffer first, ByteBuffer second)
          Sends the sequence of bytes contained in the supplied buffers to the underlying connection.
private  void handleReadReady()
           
private  void handleWriteReady()
           
(package private)  void start()
          Starts processing connection data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECEIVE_BUFFER_SIZE

private static final int RECEIVE_BUFFER_SIZE
See Also:
Constant Field Values

IOV_MAX

private static final int IOV_MAX
See Also:
Constant Field Values

logger

private static final Logger logger
mux logger


selectionManager

private static final SelectionManager selectionManager
selection manager used by this implementation


detailMessage4854354

private static final String detailMessage4854354
detail message of IOException thrown when 4854354 occurs

See Also:
Constant Field Values

channel

private final SocketChannel channel
socket channel for underlying connection


key

private final SelectionManager.Key key

sendQueue

private final LinkedList sendQueue
queue of buffers of data to be sent over connection


notifyQueue

private final LinkedList notifyQueue
queue of alternating buffers (that are in sendQueue) and IOFuture objects that need to be notified when those buffers are written


inputBuffer

private final ByteBuffer inputBuffer
buffer for reading incoming data from connection


bufferPair

private final ByteBuffer[] bufferPair

preallocBufferArray

private final ByteBuffer[] preallocBufferArray
Constructor Detail

SocketChannelConnectionIO

SocketChannelConnectionIO(Mux mux,
                          SocketChannel channel)
                    throws IOException
Creates a new SocketChannelConnectionIO for the connection represented by the supplied SocketChannel.

Throws:
IOException
Method Detail

start

void start()
     throws IOException
Starts processing connection data.

Specified by:
start in class ConnectionIO
Throws:
IOException

asyncSend

void asyncSend(ByteBuffer buffer)
Description copied from class: ConnectionIO
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.

Specified by:
asyncSend in class ConnectionIO

asyncSend

void asyncSend(ByteBuffer first,
               ByteBuffer second)
Description copied from class: ConnectionIO
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.

Specified by:
asyncSend in class ConnectionIO

futureSend

IOFuture futureSend(ByteBuffer first,
                    ByteBuffer second)
Description copied from class: ConnectionIO
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).

Specified by:
futureSend in class ConnectionIO

handleWriteReady

private void handleWriteReady()

drainNotifyQueue

private void drainNotifyQueue()

handleReadReady

private void handleReadReady()


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