org.glassfish.grizzly.strategies
Class SimpleDynamicStrategy

java.lang.Object
  extended by org.glassfish.grizzly.strategies.SimpleDynamicStrategy
All Implemented Interfaces:
Strategy<SimpleDynamicStrategy.DynamicStrategyContext>

public class SimpleDynamicStrategy
extends Object
implements Strategy<SimpleDynamicStrategy.DynamicStrategyContext>

Simple dynamic strategy, which switches I/O processing strategies, basing on statistics. This implementation takes in consideration number of SelectionKeys, which were selected last time by Selector. SimpleDynamicStrategy is able to use 3 strategies underneath: SameThreadStrategy, LeaderFollowerStrategy, WorkerThreadStrategy. And is able to switch between them basing on corresponding thresholds (threshold represents the number of selected SelectionKeys). So the strategy is getting applied following way: SameThreadStrategy --(leader-follower threshold)--> LeaderFollowerStrategy --(worker-thread threshold)--> WorkerThreadStrategy.

Author:
Alexey Stashok

Nested Class Summary
static class SimpleDynamicStrategy.DynamicStrategyContext
           
 
Constructor Summary
SimpleDynamicStrategy(Executor sameThreadProcessorExecutor, Executor workerThreadProcessorExecutor)
           
SimpleDynamicStrategy(NIOTransport transport)
           
 
Method Summary
 void executeProcessor(SimpleDynamicStrategy.DynamicStrategyContext strategyContext, ProcessorRunnable processorRunnable)
          Execute ProcessorRunnable task.
 int getLeaderFollowerThreshold()
          Returns the number of SelectionKeys, which should be selected from a Selector, to make it apply LeaderFollowerStrategy.
 int getWorkerThreadThreshold()
          Returns the number of SelectionKeys, which should be selected from a Selector, to make it apply WorkerThreadStrategy.
 boolean isTerminateThread(SimpleDynamicStrategy.DynamicStrategyContext strategyContext)
          This method may be called by runner Thread after task will be executed.
 SimpleDynamicStrategy.DynamicStrategyContext prepare(Connection connection, IOEvent ioEvent)
          Prepare Strategy for processing IOEvent, occured on the Connection.
 void setLeaderFollowerThreshold(int leaderFollowerThreshold)
          Set the number of SelectionKeys, which should be selected from a Selector, to make it apply LeaderFollowerStrategy.
 void setWorkerThreadThreshold(int workerThreadThreshold)
          Set the number of SelectionKeys, which should be selected from a Selector, to make it apply WorkerThreadStrategy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDynamicStrategy

public SimpleDynamicStrategy(NIOTransport transport)

SimpleDynamicStrategy

public SimpleDynamicStrategy(Executor sameThreadProcessorExecutor,
                             Executor workerThreadProcessorExecutor)
Method Detail

prepare

public SimpleDynamicStrategy.DynamicStrategyContext 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<SimpleDynamicStrategy.DynamicStrategyContext>
Parameters:
connection - Connection, on which IOEvent occured.
ioEvent - IOEvent.
Returns:
context/state, associated with the IOEvent processing.

executeProcessor

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

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

isTerminateThread

public boolean isTerminateThread(SimpleDynamicStrategy.DynamicStrategyContext 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<SimpleDynamicStrategy.DynamicStrategyContext>
Parameters:
strategyContext - Strategy context, initialized on "prepare" phase.
Returns:
true, to instruct caller to release the current Thread, or false otherwise.
See Also:
LeaderFollowerStrategy

getLeaderFollowerThreshold

public int getLeaderFollowerThreshold()
Returns the number of SelectionKeys, which should be selected from a Selector, to make it apply LeaderFollowerStrategy.

Returns:
the number of SelectionKeys, which should be selected from a Selector, to make it apply LeaderFollowerStrategy.

setLeaderFollowerThreshold

public void setLeaderFollowerThreshold(int leaderFollowerThreshold)
Set the number of SelectionKeys, which should be selected from a Selector, to make it apply LeaderFollowerStrategy.

Parameters:
leaderFollowerThreshold - the number of SelectionKeys, which should be selected from a Selector, to make it apply LeaderFollowerStrategy.

getWorkerThreadThreshold

public int getWorkerThreadThreshold()
Returns the number of SelectionKeys, which should be selected from a Selector, to make it apply WorkerThreadStrategy.

Returns:
the number of SelectionKeys, which should be selected from a Selector, to make it apply WorkerThreadStrategy.

setWorkerThreadThreshold

public void setWorkerThreadThreshold(int workerThreadThreshold)
Set the number of SelectionKeys, which should be selected from a Selector, to make it apply WorkerThreadStrategy.

Parameters:
workerThreadThreshold - the number of SelectionKeys, which should be selected from a Selector, to make it apply WorkerThreadStrategy.


Copyright © 2009 SUN Microsystems. All Rights Reserved.