com.faunos.util.net
Class StageletStack

java.lang.Object
  extended by com.faunos.util.net.StageletStack
All Implemented Interfaces:
Handlet
Direct Known Subclasses:
HttpHandlet

public class StageletStack
extends Object
implements Handlet

A Handlet filter that implements something like a call stack.

Author:
Babak Farhang

Constructor Summary
protected StageletStack()
          To be overridden by subclasses.
  StageletStack(Stagelet root)
          Creates a new instance with the given root stage.
 
Method Summary
 Stagelet current()
          Returns the stagelet currently at the top of the stack.
 void discard()
          Discards the instance.
 IoState init(HandletContext context)
          Initializes the handlet.
protected  Object lock()
          Returns the object synchronized on while stagelets are pushed on and popped off the stack.
 void push(Stagelet stage)
          Pushes the given stage onto this stack.
 IoState read(ScatteringByteChannel in)
          Reads from the specified channel and returns the possibly new state of the instance.
 IoState state()
          Returns the state of the handlet.
 IoState write(GatheringByteChannel out)
          Writes to the specified channel and returns the possibly new state of the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StageletStack

protected StageletStack()
To be overridden by subclasses. The overriding class must eventually call push(Stagelet) before returning from the constructor; otherwise the object will be in an invalid state.


StageletStack

public StageletStack(Stagelet root)
Creates a new instance with the given root stage.

Note there is a little chicken and egg problem, here. The root stagelet must be stack-aware. In particular, it must be aware of this instance. And of course, since the stack instance is yet to be created, root cannot be a properly constructed (configured) object prior to invocation. Which is why we also expose a protected constructor.

Method Detail

lock

protected final Object lock()
Returns the object synchronized on while stagelets are pushed on and popped off the stack.


push

public void push(Stagelet stage)
Pushes the given stage onto this stack. Successive invocations with the same stage input parameter has the same effect as a single invocation. (However, if the invocations are interleaved with other pushed Stagelets, then each invocation will still count.)

There is no direct mechanism for popping stagelets off the stack. Rather, when the topmost stagelet on the stack is IoState.DONE, it is automatically popped off the stack.


current

public final Stagelet current()
Returns the stagelet currently at the top of the stack.


init

public IoState init(HandletContext context)
Description copied from interface: Handlet
Initializes the handlet.

Specified by:
init in interface Handlet
Parameters:
context - the context supplied by the instance's container (e.g. server

state

public IoState state()
Description copied from interface: Handlet
Returns the state of the handlet.

Specified by:
state in interface Handlet

read

public IoState read(ScatteringByteChannel in)
             throws IOException
Description copied from interface: Handlet
Reads from the specified channel and returns the possibly new state of the instance. Note that if the return value is IoState.PROCESSING, then a later invocation of Handlet.state() may return a value other than PROCESSING, if the asynchronous task completes before the call to state().

The implementation must read from the channel in non-blocking manner. The behavior of this method is undefined if the state of the instance is not IoState.READING.

Specified by:
read in interface Handlet
Throws:
IOException

write

public IoState write(GatheringByteChannel out)
              throws IOException
Description copied from interface: Handlet
Writes to the specified channel and returns the possibly new state of the instance. Note that if the return value is IoState.PROCESSING, then a later invocation of Handlet.state() may return a value other than PROCESSING, if the asynchronous task completes before the call to state().

The implementation must write to the channel in non-blocking manner. The behavior of this method is undefined if the state of the instance is not IoState.WRITING.

Specified by:
write in interface Handlet
Throws:
IOException

discard

public void discard()
Description copied from interface: Handlet
Discards the instance.

Specified by:
discard in interface Handlet


SourceForge.net Logo