Did this page help you?

   Yes   No   Tell us about it...

com.amazonaws.services.simpleworkflow.flow.spring
Class SpringWorkflowWorker

java.lang.Object
  extended by com.amazonaws.services.simpleworkflow.flow.spring.SpringWorkflowWorker
All Implemented Interfaces:
Suspendable, SuspendableWorker, WorkerBase, WorkerLifecycle, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class SpringWorkflowWorker
extends java.lang.Object
implements WorkerBase, org.springframework.context.SmartLifecycle

To be used with Spring. Assumes that injected implementation bean has "workflow" scope. Otherwise the same object instance will be reused for multiple decisions which is guaranteed to break replay if any instance fields are used.


Constructor Summary
SpringWorkflowWorker()
           
SpringWorkflowWorker(AmazonSimpleWorkflow service, java.lang.String domain, java.lang.String taskListToPoll)
           
 
Method Summary
 void addWorkflowImplementation(java.lang.Object workflowImplementation)
           
 boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
           
 DataConverter getDataConverter()
           
 java.lang.String getDomain()
           
 long getDomainRetentionPeriodInDays()
           
 java.lang.String getIdentity()
           
 int getMaximumPollRateIntervalMilliseconds()
           
 double getMaximumPollRatePerSecond()
           
 int getPhase()
           
 double getPollBackoffCoefficient()
           
 long getPollBackoffInitialInterval()
           
 long getPollBackoffMaximumInterval()
           
 int getPollThreadCount()
           
 AmazonSimpleWorkflow getService()
           
 java.lang.String getTaskListToPoll()
          Task list name that given worker polls for tasks.
 long getTerminationTimeoutSeconds()
           
 java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
           
 java.lang.Iterable<java.lang.Object> getWorkflowImplementations()
           
 java.lang.Iterable<WorkflowType> getWorkflowTypesToRegister()
           
 boolean isAutoStartup()
           
 boolean isDisableAutoStartup()
           
 boolean isDisableServiceShutdownOnStop()
           
 boolean isDisableTypeRegistrationOnStart()
           
 boolean isRegisterDomain()
           
 boolean isRunning()
           
 void registerTypesToPoll()
          Try to register every type (activity or workflow depending on worker) that are configured with the worker.
 void resumePolling()
          Allow new poll requests.
 void setDataConverter(DataConverter converter)
           
 void setDisableAutoStartup(boolean disableAutoStartup)
           
 void setDisableServiceShutdownOnStop(boolean disableServiceShutdownOnStop)
          When set to false (which is default) at the beginning of the worker shutdown AmazonSimpleWorkflow.shutdown() is called.
 void setDisableTypeRegistrationOnStart(boolean disableTypeRegistrationOnStart)
          When set to true disables types registration on start even if SkipTypeRegistration is not specified.
 void setDomain(java.lang.String domain)
           
 void setDomainRetentionPeriodInDays(long domainRetentionPeriodInDays)
          Value of DomainRetentionPeriodInDays parameter passed to AmazonSimpleWorkflow.registerDomain(com.amazonaws.services.simpleworkflow.model.RegisterDomainRequest) call.
 void setIdentity(java.lang.String identity)
          Set the identity that worker specifies in the poll requests.
 void setMaximumPollRateIntervalMilliseconds(int maximumPollRateIntervalMilliseconds)
          The sliding window interval used to measure the poll rate.
 void setMaximumPollRatePerSecond(double maximumPollRatePerSecond)
          Maximum number of poll request to the task list per second allowed.
 void setPhase(int startPhase)
           
 void setPollBackoffCoefficient(double backoffCoefficient)
           
 void setPollBackoffInitialInterval(long backoffInitialInterval)
          Failed poll requests are retried after an interval defined by an exponential backoff algorithm.
 void setPollBackoffMaximumInterval(long backoffMaximumInterval)
           
 void setPollThreadCount(int threadCount)
          Defines how many concurrent threads are used by the given worker to poll the specified task list.
 void setRegisterDomain(boolean registerDomain)
          Should domain be registered on startup.
 void setService(AmazonSimpleWorkflow service)
           
 void setTaskListToPoll(java.lang.String taskListToPoll)
           
 void setTerminationTimeoutSeconds(long terminationTimeoutSeconds)
           
 void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
          Handler notified about poll request and other unexpected failures.
 void setWorkflowImplementations(java.lang.Iterable<java.lang.Object> workflowImplementations)
           
 void shutdown()
           
 boolean shutdownAndAwaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
           
 void shutdownNow()
           
 void start()
           
 void stop()
           
 void stop(java.lang.Runnable callback)
           
 void stopNow()
           
 void suspendPolling()
          Do not make new poll requests.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpringWorkflowWorker

public SpringWorkflowWorker()

SpringWorkflowWorker

public SpringWorkflowWorker(AmazonSimpleWorkflow service,
                            java.lang.String domain,
                            java.lang.String taskListToPoll)
Method Detail

getService

public AmazonSimpleWorkflow getService()
Specified by:
getService in interface WorkerBase

setService

public void setService(AmazonSimpleWorkflow service)

getDomain

public java.lang.String getDomain()
Specified by:
getDomain in interface WorkerBase

setDomain

public void setDomain(java.lang.String domain)

isRegisterDomain

public boolean isRegisterDomain()
Specified by:
isRegisterDomain in interface WorkerBase

setRegisterDomain

public void setRegisterDomain(boolean registerDomain)
Description copied from interface: WorkerBase
Should domain be registered on startup. Default is false. When enabled #setDomainRetentionPeriodInDays(Long) property is required.

Specified by:
setRegisterDomain in interface WorkerBase

getDomainRetentionPeriodInDays

public long getDomainRetentionPeriodInDays()
Specified by:
getDomainRetentionPeriodInDays in interface WorkerBase

setDomainRetentionPeriodInDays

public void setDomainRetentionPeriodInDays(long domainRetentionPeriodInDays)
Description copied from interface: WorkerBase
Value of DomainRetentionPeriodInDays parameter passed to AmazonSimpleWorkflow.registerDomain(com.amazonaws.services.simpleworkflow.model.RegisterDomainRequest) call. Required when WorkerBase.isRegisterDomain() is true.

Specified by:
setDomainRetentionPeriodInDays in interface WorkerBase

getTaskListToPoll

public java.lang.String getTaskListToPoll()
Description copied from interface: WorkerBase
Task list name that given worker polls for tasks.

Specified by:
getTaskListToPoll in interface WorkerBase

setTaskListToPoll

public void setTaskListToPoll(java.lang.String taskListToPoll)

getDataConverter

public DataConverter getDataConverter()

setDataConverter

public void setDataConverter(DataConverter converter)

getMaximumPollRatePerSecond

public double getMaximumPollRatePerSecond()
Specified by:
getMaximumPollRatePerSecond in interface WorkerBase

setMaximumPollRatePerSecond

public void setMaximumPollRatePerSecond(double maximumPollRatePerSecond)
Description copied from interface: WorkerBase
Maximum number of poll request to the task list per second allowed. Default is 0 which means unlimited.

Specified by:
setMaximumPollRatePerSecond in interface WorkerBase
See Also:
WorkerBase.setMaximumPollRateIntervalMilliseconds(int)

getMaximumPollRateIntervalMilliseconds

public int getMaximumPollRateIntervalMilliseconds()
Specified by:
getMaximumPollRateIntervalMilliseconds in interface WorkerBase

setMaximumPollRateIntervalMilliseconds

public void setMaximumPollRateIntervalMilliseconds(int maximumPollRateIntervalMilliseconds)
Description copied from interface: WorkerBase
The sliding window interval used to measure the poll rate. Controls allowed rate burstiness. For example if allowed rate is 10 per second and poll rate interval is 100 milliseconds the poller is not going to allow more then one poll per 100 milliseconds. If poll rate interval is 10 seconds then 100 request can be emitted as fast as possible, but then the polling stops until 10 seconds pass.

Specified by:
setMaximumPollRateIntervalMilliseconds in interface WorkerBase
See Also:
WorkerBase.setMaximumPollRatePerSecond(double)

getUncaughtExceptionHandler

public java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
Specified by:
getUncaughtExceptionHandler in interface WorkerBase

setUncaughtExceptionHandler

public void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Description copied from interface: WorkerBase
Handler notified about poll request and other unexpected failures. The default implementation logs the failures using ERROR level.

Specified by:
setUncaughtExceptionHandler in interface WorkerBase

getIdentity

public java.lang.String getIdentity()
Specified by:
getIdentity in interface WorkerBase

setIdentity

public void setIdentity(java.lang.String identity)
Description copied from interface: WorkerBase
Set the identity that worker specifies in the poll requests. This value ends up stored in the identity field of the corresponding Start history event. Default is "pid"@"host".

Specified by:
setIdentity in interface WorkerBase
Parameters:
identity - maximum size is 256 characters.

getPollBackoffInitialInterval

public long getPollBackoffInitialInterval()
Specified by:
getPollBackoffInitialInterval in interface WorkerBase

setPollBackoffInitialInterval

public void setPollBackoffInitialInterval(long backoffInitialInterval)
Description copied from interface: WorkerBase
Failed poll requests are retried after an interval defined by an exponential backoff algorithm. See BackoffThrottler for more info.

Specified by:
setPollBackoffInitialInterval in interface WorkerBase
Parameters:
backoffInitialInterval - the interval between failure and the first retry. Default is 100.

getPollBackoffMaximumInterval

public long getPollBackoffMaximumInterval()
Specified by:
getPollBackoffMaximumInterval in interface WorkerBase

setPollBackoffMaximumInterval

public void setPollBackoffMaximumInterval(long backoffMaximumInterval)
Specified by:
setPollBackoffMaximumInterval in interface WorkerBase
Parameters:
backoffMaximumInterval - maximum interval between poll request retries. Default is 60000 (one minute).
See Also:
WorkerBase.setPollBackoffInitialInterval(long)

isDisableServiceShutdownOnStop

public boolean isDisableServiceShutdownOnStop()
Specified by:
isDisableServiceShutdownOnStop in interface WorkerBase

setDisableServiceShutdownOnStop

public void setDisableServiceShutdownOnStop(boolean disableServiceShutdownOnStop)
Description copied from interface: WorkerBase
When set to false (which is default) at the beginning of the worker shutdown AmazonSimpleWorkflow.shutdown() is called. It causes all outstanding long poll request to disconnect. But also causes all future request (for example activity completions) to SWF fail.

Specified by:
setDisableServiceShutdownOnStop in interface WorkerBase

setDisableTypeRegistrationOnStart

public void setDisableTypeRegistrationOnStart(boolean disableTypeRegistrationOnStart)
Description copied from interface: WorkerBase
When set to true disables types registration on start even if SkipTypeRegistration is not specified. Types still can be registered by calling WorkerBase.registerTypesToPoll().

Specified by:
setDisableTypeRegistrationOnStart in interface WorkerBase

isDisableTypeRegistrationOnStart

public boolean isDisableTypeRegistrationOnStart()
Specified by:
isDisableTypeRegistrationOnStart in interface WorkerBase

getPollBackoffCoefficient

public double getPollBackoffCoefficient()
Specified by:
getPollBackoffCoefficient in interface WorkerBase

setPollBackoffCoefficient

public void setPollBackoffCoefficient(double backoffCoefficient)
Specified by:
setPollBackoffCoefficient in interface WorkerBase
Parameters:
backoffCoefficient - coefficient that defines how fast retry interval grows in case of poll request failures. Default is 2.0.
See Also:
WorkerBase.setPollBackoffInitialInterval(long)

getPollThreadCount

public int getPollThreadCount()
Specified by:
getPollThreadCount in interface WorkerBase

setPollThreadCount

public void setPollThreadCount(int threadCount)
Description copied from interface: WorkerBase
Defines how many concurrent threads are used by the given worker to poll the specified task list. Default is 1. Note that in case of ActivityWorker two separate threads pools are used. One for polling and another one for executing activities. The size of the activity execution thread pool is defined through ActivityWorker.setTaskExecutorThreadPoolSize(int).

Specified by:
setPollThreadCount in interface WorkerBase

suspendPolling

public void suspendPolling()
Description copied from interface: Suspendable
Do not make new poll requests. Outstanding long polls still can return tasks after this method was called.

Specified by:
suspendPolling in interface Suspendable

resumePolling

public void resumePolling()
Description copied from interface: Suspendable
Allow new poll requests.

Specified by:
resumePolling in interface Suspendable

getWorkflowTypesToRegister

public java.lang.Iterable<WorkflowType> getWorkflowTypesToRegister()

start

public void start()
Specified by:
start in interface WorkerLifecycle
Specified by:
start in interface org.springframework.context.Lifecycle

shutdown

public void shutdown()
Specified by:
shutdown in interface WorkerLifecycle

shutdownNow

public void shutdownNow()
Specified by:
shutdownNow in interface WorkerLifecycle

shutdownAndAwaitTermination

public boolean shutdownAndAwaitTermination(long timeout,
                                           java.util.concurrent.TimeUnit unit)
                                    throws java.lang.InterruptedException
Specified by:
shutdownAndAwaitTermination in interface WorkerLifecycle
Throws:
java.lang.InterruptedException

stopNow

public void stopNow()

awaitTermination

public boolean awaitTermination(long timeout,
                                java.util.concurrent.TimeUnit unit)
                         throws java.lang.InterruptedException
Specified by:
awaitTermination in interface WorkerLifecycle
Throws:
java.lang.InterruptedException

setWorkflowImplementations

public void setWorkflowImplementations(java.lang.Iterable<java.lang.Object> workflowImplementations)
                                throws java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

getWorkflowImplementations

public java.lang.Iterable<java.lang.Object> getWorkflowImplementations()

addWorkflowImplementation

public void addWorkflowImplementation(java.lang.Object workflowImplementation)
                               throws java.lang.InstantiationException,
                                      java.lang.IllegalAccessException
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

stop

public void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

isRunning

public boolean isRunning()
Specified by:
isRunning in interface WorkerBase
Specified by:
isRunning in interface org.springframework.context.Lifecycle

getPhase

public int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased
Returns:
default is 0

setPhase

public void setPhase(int startPhase)

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

getTerminationTimeoutSeconds

public long getTerminationTimeoutSeconds()

setTerminationTimeoutSeconds

public void setTerminationTimeoutSeconds(long terminationTimeoutSeconds)

isDisableAutoStartup

public boolean isDisableAutoStartup()

setDisableAutoStartup

public void setDisableAutoStartup(boolean disableAutoStartup)

stop

public void stop(java.lang.Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle

registerTypesToPoll

public void registerTypesToPoll()
Description copied from interface: WorkerBase
Try to register every type (activity or workflow depending on worker) that are configured with the worker.

Specified by:
registerTypesToPoll in interface WorkerBase
See Also:
WorkerBase.setDisableTypeRegistrationOnStart(boolean)


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.