org.glassfish.grizzly
Interface Strategy<E>

All Known Implementing Classes:
LeaderFollowerStrategy, SameThreadStrategy, SimpleDynamicStrategy, WorkerThreadStrategy

public interface Strategy<E>

Strategy is responsible for making decision how ProcessorRunnable task will be run: in current thread, worker thread. Strategy can make any other processing decisions.

Author:
Alexey Stashok

Method Summary
 void executeProcessor(E strategyContext, ProcessorRunnable processorRunnable)
          Execute ProcessorRunnable task.
 boolean isTerminateThread(E strategyContext)
          This method may be called by runner Thread after task will be executed.
 E prepare(Connection connection, IOEvent ioEvent)
          Prepare Strategy for processing IOEvent, occured on the Connection.
 

Method Detail

prepare

E prepare(Connection connection,
          IOEvent ioEvent)
Prepare Strategy for processing IOEvent, occured on the Connection. At this phase Strategy may initialize and return context data, which will be passed further into executeProcessor and isTerminateThread methods.

Parameters:
connection - Connection, on which IOEvent occured.
ioEvent - IOEvent.
Returns:
context/state, associated with the IOEvent processing.

executeProcessor

void executeProcessor(E strategyContext,
                      ProcessorRunnable processorRunnable)
                      throws IOException
Execute ProcessorRunnable task.

Parameters:
strategyContext - context object, initialized on "prepare" phase.
processorRunnable - the ProcessorRunnable task to be executed.
Throws:
IOException

isTerminateThread

boolean isTerminateThread(E strategyContext)
This method may be called by runner Thread after task will be executed. Strategy may instruct the caller to release current thread, after task execution will be completed.

Parameters:
strategyContext - Strategy context, initialized on "prepare" phase.
Returns:
true, to instruct caller to release the current Thread, or false otherwise.
See Also:
LeaderFollowerStrategy


Copyright © 2009 SUN Microsystems. All Rights Reserved.