Class WebThreadAffinityExecutive
- java.lang.Object
-
- net.officefloor.web.executive.WebThreadAffinityExecutive
-
- All Implemented Interfaces:
BackgroundScheduler
,ExecutionStrategy
,Executive
,TeamOversight
public class WebThreadAffinityExecutive extends java.lang.Object implements Executive, BackgroundScheduler, ExecutionStrategy, TeamOversight
WebThread
affinityExecutive
.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description WebThreadAffinityExecutive(CpuCore[] cpuCores, ExecutiveSourceContext context)
Instantiate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.Executor
createExecutor(ProcessIdentifier processIdentifier)
Creates anExecutor
that MUST execute theRunnable
in a differentThread
to the caller.ProcessIdentifier
createProcessIdentifier(ExecutiveOfficeContext officeContext)
Creates a newProcessIdentifier
.Team
createTeam(ExecutiveContext context)
Creates theTeam
.ExecutionStrategy[]
getExcutionStrategies()
Obtains theExecutionStrategy
strategies.java.lang.String
getExecutionStrategyName()
Obtains the name of theExecutionStrategy
.TeamOversight
getTeamOversight()
Obtains theTeamOversight
.java.util.concurrent.ThreadFactory[]
getThreadFactories()
<T extends java.lang.Throwable>
ProcessManagermanageExecution(Execution<T> execution)
Manages theExecution
.void
schedule(long delay, java.lang.Runnable runnable)
Schedules theRunnable
to be executed after the delay.void
schedule(ProcessIdentifier processIdentifier, long delay, java.lang.Runnable runnable)
Schedules theRunnable
to execute so many milliseconds in the future.void
startManaging(ExecutiveStartContext context)
Starts managing theOfficeFloor
.void
stopManaging()
Stops managing theOfficeFloor
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.officefloor.frame.api.executive.Executive
createThread, getOfficeManager, processComplete
-
-
-
-
Constructor Detail
-
WebThreadAffinityExecutive
public WebThreadAffinityExecutive(CpuCore[] cpuCores, ExecutiveSourceContext context)
Instantiate.- Parameters:
cpuCores
-CpuCore
instances.context
-ExecutiveSourceContext
.
-
-
Method Detail
-
getExcutionStrategies
public ExecutionStrategy[] getExcutionStrategies()
Description copied from interface:Executive
Obtains theExecutionStrategy
strategies.- Specified by:
getExcutionStrategies
in interfaceExecutive
- Returns:
ExecutionStrategy
instances.
-
getTeamOversight
public TeamOversight getTeamOversight()
Description copied from interface:Executive
Obtains theTeamOversight
.- Specified by:
getTeamOversight
in interfaceExecutive
- Returns:
TeamOversight
.
-
startManaging
public void startManaging(ExecutiveStartContext context) throws java.lang.Exception
Description copied from interface:Executive
Starts managing theOfficeFloor
.- Specified by:
startManaging
in interfaceExecutive
- Parameters:
context
-ExecutiveStartContext
.- Throws:
java.lang.Exception
- If fails to start managing.
-
manageExecution
public <T extends java.lang.Throwable> ProcessManager manageExecution(Execution<T> execution) throws T extends java.lang.Throwable
Description copied from interface:Executive
Manages the
Execution
.The
Thread.currentThread()
will provide the inboundThread
.- Specified by:
manageExecution
in interfaceExecutive
- Type Parameters:
T
- Type ofThrowable
thrown.- Parameters:
execution
-Execution
to be undertaken.- Returns:
ProcessManager
for theProcessState
.- Throws:
T
- Propagation of failure fromExecution
.T extends java.lang.Throwable
-
createProcessIdentifier
public ProcessIdentifier createProcessIdentifier(ExecutiveOfficeContext officeContext)
Description copied from interface:Executive
Creates a newProcessIdentifier
.- Specified by:
createProcessIdentifier
in interfaceExecutive
- Parameters:
officeContext
-ExecutiveOfficeContext
.- Returns:
- New
ProcessIdentifier
.
-
createExecutor
public java.util.concurrent.Executor createExecutor(ProcessIdentifier processIdentifier)
Description copied from interface:Executive
Creates an
Executor
that MUST execute theRunnable
in a differentThread
to the caller.This is used in various places within
OfficeFloor
:- By
ManagedFunction
in executingRunnable
in anotherThread
- To avoid stack over flow issues, the stack call chain is broken by
invoking further
FunctionState
delegation in anotherThread
. This allows further depth to a thread stack than offered by a singleThread
.
- Specified by:
createExecutor
in interfaceExecutive
- Parameters:
processIdentifier
-ProcessIdentifier
ofProcessState
requiring theExecutor
.- Returns:
Executor
that will executeRunnable
instances in a differentThread
to caller.
- By
-
schedule
public void schedule(ProcessIdentifier processIdentifier, long delay, java.lang.Runnable runnable)
Description copied from interface:Executive
Schedules the
Runnable
to execute so many milliseconds in the future.Note that the
Executive
may determine theProcessState
complete and not execute theRunnable
.- Specified by:
schedule
in interfaceExecutive
- Parameters:
processIdentifier
-ProcessIdentifier
of theProcessState
requiring the scheduled execution.delay
- Delay in milliseconds to execute theRunnable
.runnable
-Runnable
to execute.
-
stopManaging
public void stopManaging() throws java.lang.Exception
Description copied from interface:Executive
Stops managing theOfficeFloor
.- Specified by:
stopManaging
in interfaceExecutive
- Throws:
java.lang.Exception
- If fails to stop managing.
-
schedule
public void schedule(long delay, java.lang.Runnable runnable)
Description copied from interface:BackgroundScheduler
Schedules theRunnable
to be executed after the delay.- Specified by:
schedule
in interfaceBackgroundScheduler
- Parameters:
delay
- Delay in milliseconds.runnable
-Runnable
.
-
getExecutionStrategyName
public java.lang.String getExecutionStrategyName()
Description copied from interface:ExecutionStrategy
Obtains the name of theExecutionStrategy
.- Specified by:
getExecutionStrategyName
in interfaceExecutionStrategy
- Returns:
- Name of the
ExecutionStrategy
.
-
getThreadFactories
public java.util.concurrent.ThreadFactory[] getThreadFactories()
Description copied from interface:ExecutionStrategy
- Specified by:
getThreadFactories
in interfaceExecutionStrategy
- Returns:
ThreadFactory
instances.
-
createTeam
public Team createTeam(ExecutiveContext context) throws java.lang.Exception
Description copied from interface:TeamOversight
Creates the
Team
.This is expected to delegate to the
TeamSource
to create theTeam
. However, theExecutive
may decide to wrap theTeam
or provide multipleTeam
instances with assigning algorithm (such as taking advantage ofThread
affinity). The choice is, however, ultimately left to theExecutive
to manage theTeam
instances.- Specified by:
createTeam
in interfaceTeamOversight
- Parameters:
context
-ExecutiveContext
.- Returns:
Team
.- Throws:
java.lang.Exception
- If fails to configure theTeamSource
.
-
-