com.sun.grizzly.strategies
Class LeaderFollowerStrategy

java.lang.Object
  extended by com.sun.grizzly.strategies.LeaderFollowerStrategy
All Implemented Interfaces:
Strategy<Boolean>

public class LeaderFollowerStrategy
extends Object
implements Strategy<Boolean>

Strategy, which executes Processors in a current threads, and resumes selector thread logic in separate thread.

Author:
Alexey Stashok

Constructor Summary
LeaderFollowerStrategy(Executor sameThreadProcessorExecutor, Executor workerThreadProcessorExecutor)
           
LeaderFollowerStrategy(NIOTransport transport)
           
 
Method Summary
 void executeProcessor(Boolean strategyContext, ProcessorRunnable processorRunnable)
          Execute ProcessorRunnable task.
 Executor getProcessorExecutor(Boolean strategyContext)
           
 boolean isTerminateThread(Boolean strategyContext)
          This method may be called by runner Thread after task will be executed.
 Boolean prepare(Connection connection, IOEvent ioEvent)
          Prepare Strategy for processing IOEvent, occured on the Connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeaderFollowerStrategy

public LeaderFollowerStrategy(NIOTransport transport)

LeaderFollowerStrategy

public LeaderFollowerStrategy(Executor sameThreadProcessorExecutor,
                              Executor workerThreadProcessorExecutor)
Method Detail

prepare

public Boolean 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.

Specified by:
prepare in interface Strategy<Boolean>
Parameters:
connection - Connection, on which IOEvent occured.
ioEvent - IOEvent.
Returns:
context/state, associated with the IOEvent processing.

executeProcessor

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

Specified by:
executeProcessor in interface Strategy<Boolean>
Parameters:
strategyContext - context object, initialized on "prepare" phase.
processorRunnable - the ProcessorRunnable task to be executed.
Throws:
IOException

isTerminateThread

public boolean isTerminateThread(Boolean 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.

Specified by:
isTerminateThread in interface Strategy<Boolean>
Parameters:
strategyContext - Strategy context, initialized on "prepare" phase.
Returns:
true, to instruct caller to release the current Thread, or false otherwise.
See Also:
LeaderFollowerStrategy

getProcessorExecutor

public Executor getProcessorExecutor(Boolean strategyContext)


Copyright © 2009 SUN Microsystems. All Rights Reserved.