Class EfsActivator
EfsActivator is responsible for starting, enabling,
disabling, and stopping agents
according to a given Workflow.
An activator may be created either programmatically using
EfsActivator.Builder or by
loading a typesafe
configuration from a file.
Please see org.efs.activator package documentation for
a detailed description on how to use EfsActivator.
EfsActivator is thread-safe but can only process a
single workflow at a time. That workflow must be either
run to completion or terminated
prior to initiating
another workflow.
- Author:
- Charles W. Rapp
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder class used to create an activator. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIllegalStateExceptionmessage when execution is called but there is not workflow in progress (""no workflow in-progress"").static final StringNullPointerExceptionmessage for a null agent is "agent is null".static final StringNullPointerExceptionmessage for a null callback is "callback is null".static final StringStand-alone executed steps are named "standalone-step". -
Method Summary
Modifier and TypeMethodDescriptionagentState(String agentName) Returns named agent's current state.voidagentState(String agentName, EfsAgentState state) Forcibly sets named agent's state.static EfsActivator.Builderbuilder()Returns a newBuilderinstance.voidderegisterListener(Consumer<ActivatorEvent> callback, IEfsAgent agent) Retracts registered agent from activator state listening.voidexecute(String agentName, EfsAgentState beginState, EfsAgentState endState, Duration transitionTime) Executes a single explicit step on a given agent.booleanExecutes next stage in workflow.booleanExecutes next step in workflow.booleanExecutes all remaining stages and steps in this workflow.voidinitializeWorkflow(String workflowName) Sets workflow to be executed.booleanisRegisteredListener(IEfsAgent agent) Returnstrueif agent is a registered activator listener andfalseotherwise.static EfsActivatorloadActivator(String fileName) Returns activator based on configuration loaded from given file name.voidregisterListener(Consumer<ActivatorEvent> callback, IEfsAgent agent) Registers agent for listening to activator state changes.voidsetWorkflowStage(int stageIndex, int stepIndex) Sets workflow position to given stage and step index.voidTerminates an in-progress workflow.workflow()Returns current, in-progress workflow name.
-
Field Details
-
NO_WORKFLOW_IN_PROGRESS
IllegalStateExceptionmessage when execution is called but there is not workflow in progress (""no workflow in-progress"").- See Also:
-
NULL_AGENT
NullPointerExceptionmessage for a null agent is "agent is null".- See Also:
-
NULL_CALLBACK
NullPointerExceptionmessage for a null callback is "callback is null".- See Also:
-
STAND_ALONE_STEP
Stand-alone executed steps are named "standalone-step".- See Also:
-
-
Method Details
-
workflow
Returns current, in-progress workflow name. If there is no workflow in progress, then returnsNO_WORKFLOW_IN_PROGRESS.- Returns:
- name of workflow currently in-progress.
-
agentState
Returns named agent's current state.- Parameters:
agentName- agent's unique name.- Returns:
- agent's current state.
- Throws:
IllegalStateException- ifagentNameeither references an un-registered agent or the agent does not implementIEfsActivateAgent.
-
isRegisteredListener
Returnstrueif agent is a registered activator listener andfalseotherwise.- Parameters:
agent- check if this agent is registered as an activator listener.- Returns:
trueifagentis a registered activator listener.
-
initializeWorkflow
Sets workflow to be executed. This method must be successfully called prior to calling the following workflow execution methods:This activator may not have an in-progress workflow when attempting initialize a workflow.
Note:
execute(String, EfsAgentState, EfsAgentState, Duration)may always be called whether a workflow is in progress or not.- Parameters:
workflowName- set in place this activator workflow.- Throws:
IllegalArgumentException- ifworkflowNameis eithernull, an empty string, or does not reference a known workflow.IllegalStateException- if this activator already has an in-progress workflow.- See Also:
-
setWorkflowStage
public void setWorkflowStage(int stageIndex, int stepIndex) Sets workflow position to given stage and step index.- Parameters:
stageIndex- set current stage to this index.stepIndex- set current step within stage to this index.- Throws:
IllegalStateException- if there is no workflow in-progress.IndexOutOfBoundsException- if eitherstageIndexorstepIndexis out-of-bounds.
-
agentState
Forcibly sets named agent's state. Use this method with care! This method should be used only when an activation step fails but it is determined that named agent is actually in the target state. Using this method indiscriminately will result in activator no longer able to correctly change an agent's state.- Parameters:
agentName- set this agent's state.state- agent's current state.- Throws:
NullPointerException- ifstateisnull.IllegalArgumentException- ifagentNameis eithernull, an empty string, or does not reference a known agent.
-
terminateWorkflow
public void terminateWorkflow()Terminates an in-progress workflow. No further executions are possible exceptexecute(String, EfsAgentState, EfsAgentState, Duration).- See Also:
-
registerListener
Registers agent for listening to activator state changes.ActivatorEvents are delivered to agent via the given callback.Please note that an agent may only have one current registration. If the agent is
de-registered, then it may register again.- Parameters:
callback- agent callback lambda.agent- agent listening to activator changes.- Throws:
NullPointerException- if eithercalbackoragentisnull.IllegalStateException- ifagentis already registered.- See Also:
-
deregisterListener
Retracts registered agent from activator state listening. Does nothing if agent is not currently registered.- Parameters:
callback- agent callback lambda.agent- agent listening to activator changes.- Throws:
NullPointerException- if eithercalbackoragentisnull.- See Also:
-
executeNextStep
public boolean executeNextStep()Executes next step in workflow. Returnstrueif workflow is completed after successfully completing step.- Returns:
trueif workflow is completed.- Throws:
IllegalStateException- if there is no activation in progress or the activation fails.
-
executeNextStage
public boolean executeNextStage()Executes next stage in workflow. Returnstrueif workflow is completed after successfully completing stage.- Returns:
trueif workflow is completed.- Throws:
IllegalStateException- if there is no activation in progress or the activation fails.
-
executeWorkflow
public boolean executeWorkflow()Executes all remaining stages and steps in this workflow.- Returns:
true.- Throws:
IllegalStateException- if there is no activation in progress or the activation fails.
-
execute
public void execute(String agentName, EfsAgentState beginState, EfsAgentState endState, Duration transitionTime) Executes a single explicit step on a given agent.This method may throw any number of
RuntimeExceptions either due to the given parameters being invalid (name does not reference a knownIEfsActivateAgent, begin and end states not being adjacent) or the step execution failing. You are advised to use a generalExceptioncatch when calling this method.- Parameters:
agentName- unique agent namebeginState- expected agent current state.endState- target agent state.transitionTime- time limit for state transition.- Throws:
IllegalStateException- if activation fails.
-
builder
Returns a newBuilderinstance.- Returns:
- new
Builderinstance.
-
loadActivator
Returns activator based on configuration loaded from given file name.- Parameters:
fileName- name of file containing efs activator definition.- Returns:
- activator loaded from configuration file.
- Throws:
com.typesafe.config.ConfigException- iffileNamecontain an invalid efs activator configuration.
-