com.faunos.util.net
Class AsynchStagelet

java.lang.Object
  extended by com.faunos.util.net.AsynchStagelet
All Implemented Interfaces:
Handlet, Stagelet

public abstract class AsynchStagelet
extends Object
implements Stagelet

A skeletal implementation of an asynchronous stagelet. An instance starts out in the IoState.PROCESSING state. Later, when the task is completed, a stagelet representing the completion of the task is pushed onto the stack.

Author:
Babak Farhang
See Also:
init(HandletContext), nextStage()

Field Summary
protected  StageletStack stack
           
 
Constructor Summary
protected AsynchStagelet(StageletStack stack)
           
 
Method Summary
 void discard()
          Does nothing.
 IoState init(HandletContext context)
          Asynchronously invokes the nextStage() method, pushes the returned stagelet onto the stack, initializes it, and notifies the container that it is done processing.
protected abstract  Stagelet nextStage()
          Returns the next stage which will be pushed onto the stack.
 IoState read(ScatteringByteChannel in)
          Not implemented.
 IoState state()
          Returns DONE, if unwound; PROCESSING, otherwise.
 IoState unwind(IoState preState)
          Sets the state to DONE.
 IoState write(GatheringByteChannel out)
          Not implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stack

protected final StageletStack stack
Constructor Detail

AsynchStagelet

protected AsynchStagelet(StageletStack stack)
Method Detail

unwind

public IoState unwind(IoState preState)
Sets the state to DONE.

Specified by:
unwind in interface Stagelet
Parameters:
preState - the state of the previous stage prior to its flipping to DONE
Returns:
DONE

discard

public void discard()
Does nothing.

Specified by:
discard in interface Handlet

init

public IoState init(HandletContext context)
Asynchronously invokes the nextStage() method, pushes the returned stagelet onto the stack, initializes it, and notifies the container that it is done processing.

This method returns immediately.

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

read

public IoState read(ScatteringByteChannel in)
             throws IOException
Not implemented.

Specified by:
read in interface Handlet
Throws:
UnsupportedOperationException
IOException
See Also:
state()

state

public IoState state()
Returns DONE, if unwound; PROCESSING, otherwise.

Specified by:
state in interface Handlet

write

public IoState write(GatheringByteChannel out)
              throws IOException
Not implemented.

Specified by:
write in interface Handlet
Throws:
UnsupportedOperationException
IOException
See Also:
state()

nextStage

protected abstract Stagelet nextStage()
Returns the next stage which will be pushed onto the stack. This method is invoked asynchronously and the returned stagelet is the end result of that execution. The returned stagelet will be in either of the IoState.READING or IoState.WRITING states.

See Also:
init(HandletContext)


SourceForge.net Logo