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

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

final class StreamConnectionIO
extends ConnectionIO

StreamConnectionIO implements the ConnectionIO abstraction for a connection accessible through standard (blocking) I/O streams, i.e. java.io.OutputStream and java.io.InputStream.

Author:
Sun Microsystems, Inc.

Nested Class Summary
private  class StreamConnectionIO.Reader
           
private  class StreamConnectionIO.Writer
           
 
Field Summary
private  InputStream in
           
private  ReadableByteChannel inChannel
           
private  ByteBuffer inputBuffer
          buffer for reading incoming data from connection
private static Logger logger
          mux logger
private  OutputStream out
          I/O streams for underlying connection
private  WritableByteChannel outChannel
          channels wrapped around underlying I/O streams
private static int RECEIVE_BUFFER_SIZE
           
private  LinkedList sendQueue
          queue of buffers of data to be sent over connection, interspersed with IOFuture objects that need to be notified in sequence
private static Executor systemThreadPool
          pool of threads for executing tasks in system thread group: used for I/O (reader and writer) threads
 
Fields inherited from class com.sun.jini.jeri.internal.mux.ConnectionIO
mux
 
Constructor Summary
StreamConnectionIO(Mux mux, OutputStream out, InputStream in)
          Creates a new StreamConnectionIO for the connection represented by the supplied OutputStream and InputStream pair.
 
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 drainQueue(LinkedList queue)
           
(package private)  IOFuture futureSend(ByteBuffer first, ByteBuffer second)
          Sends the sequence of bytes contained in the supplied buffers to the underlying connection.
static ReadableByteChannel newChannel(InputStream in)
          The following two methods are modifications of their equivalents in java.nio.channels.Channels with the assumption that the supplied byte buffers are backed by arrays, so no additional copying is required.
static WritableByteChannel newChannel(OutputStream out)
           
(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

systemThreadPool

private static final Executor systemThreadPool
pool of threads for executing tasks in system thread group: used for I/O (reader and writer) threads


logger

private static final Logger logger
mux logger


out

private final OutputStream out
I/O streams for underlying connection


in

private final InputStream in

outChannel

private final WritableByteChannel outChannel
channels wrapped around underlying I/O streams


inChannel

private final ReadableByteChannel inChannel

sendQueue

private LinkedList sendQueue
queue of buffers of data to be sent over connection, interspersed with IOFuture objects that need to be notified in sequence


inputBuffer

private final ByteBuffer inputBuffer
buffer for reading incoming data from connection

Constructor Detail

StreamConnectionIO

StreamConnectionIO(Mux mux,
                   OutputStream out,
                   InputStream in)
Creates a new StreamConnectionIO for the connection represented by the supplied OutputStream and InputStream pair.

Method Detail

start

void start()
     throws IOException
Starts processing connection data. This method starts asynchronous actions to read and write from the connection.

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

drainQueue

private void drainQueue(LinkedList queue)

newChannel

public static ReadableByteChannel newChannel(InputStream in)
The following two methods are modifications of their equivalents in java.nio.channels.Channels with the assumption that the supplied byte buffers are backed by arrays, so no additional copying is required.


newChannel

public static WritableByteChannel newChannel(OutputStream out)


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