org.indi.reactor
Class OutputQueue

java.lang.Object
  extended by org.indi.reactor.SimpleEventHandler
      extended by org.indi.reactor.OutputQueue
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel, EventHandler

public class OutputQueue
extends SimpleEventHandler
implements java.nio.channels.WritableByteChannel

An Output queue that can filled with as many ByteBuffers as requiered. It is registered with a reactor and associated with a SelectableChannel. It empties itself though the channel as the the channel is detected writable by the reactor.

Author:
Dirk Hünniger

Field Summary
protected  boolean active
          true if data if waiting in the queue to be writen into the channel.
protected  boolean dead
          false until onClose has been called.
protected  java.util.Queue<java.nio.ByteBuffer> queue
          The queue containing the ByteBuffers to be written into the channel.
 
Fields inherited from class org.indi.reactor.SimpleEventHandler
channel, reactor, registeredOperations
 
Constructor Summary
OutputQueue(Reactor r, java.nio.channels.SelectableChannel ch)
          class constructor
 
Method Summary
 void close()
          close the channel.
 boolean isOpen()
          return whether the channel is open.
 void onClose()
          Called by the reactor when the channel is deregistered
 void onWrite()
          Called by the reactor when channel is ready for writing.
 int write(java.nio.ByteBuffer src)
          Put a new ByteBuffer into the queue.
 
Methods inherited from class org.indi.reactor.SimpleEventHandler
channel, onAccept, onConnect, onRead, register
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

protected java.util.Queue<java.nio.ByteBuffer> queue
The queue containing the ByteBuffers to be written into the channel.


active

protected boolean active
true if data if waiting in the queue to be writen into the channel.


dead

protected boolean dead
false until onClose has been called. (usually to be called by the reactor)

Constructor Detail

OutputQueue

public OutputQueue(Reactor r,
                   java.nio.channels.SelectableChannel ch)
class constructor

Parameters:
r - the reactor to register with.
ch - the SelectableChannel to write the information to
Method Detail

onWrite

public void onWrite()
             throws java.io.IOException
Called by the reactor when channel is ready for writing.

Specified by:
onWrite in interface EventHandler
Overrides:
onWrite in class SimpleEventHandler
Throws:
java.io.IOException
See Also:
EventHandler.onWrite()

write

public int write(java.nio.ByteBuffer src)
Put a new ByteBuffer into the queue. It will be writen to the channel as soon as it becomes writable.

Specified by:
write in interface java.nio.channels.WritableByteChannel
Returns:
the number of Byte put into the queue. -1 if failed.

isOpen

public boolean isOpen()
return whether the channel is open. (part of the channel interface)

Specified by:
isOpen in interface java.nio.channels.Channel

close

public void close()
close the channel. (part of the channel interface)

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel

onClose

public void onClose()
Called by the reactor when the channel is deregistered

Specified by:
onClose in interface EventHandler
Overrides:
onClose in class SimpleEventHandler
See Also:
EventHandler.onClose()


Copyright © 2008. All Rights Reserved.