com.oracle.coherence.patterns.command.internal
Class CommandExecutor

java.lang.Object
  extended by com.oracle.coherence.patterns.command.internal.CommandExecutor
All Implemented Interfaces:
CommandExecutorMBean

public class CommandExecutor
extends Object
implements CommandExecutorMBean

An CommandExecutor is responsible for coordinating and executing Commands (represented as CommandExecutionRequests) for a single Context.

Included in this responsibility is the recovery and potential re-execution of CommandExecutionRequests (in-the-originally-submitted-order). Such recovery may be due to Coherence load-balancing or recovering cache partitions.

Internally CommandExecutors operate as a FiniteStateMachine (see CommandExecutor.State for details on states).

CommandExecutors state transitions are driven by 'events' raised by the ContextBackingMapListener or through requests made by the SubmitCommandExecutionRequestProcessor.

All CommandExecutors are monitorable through JMX. They are automatically registered and de-registered when they created and stopped (respectively).

Copyright (c) 2008-2016. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.

Author:
Brian Oliver, Simon Bisson
See Also:
CommandExecutionRequest, CommandSubmitter, CommandExecutorMBean, SubmitCommandExecutionRequestProcessor

Nested Class Summary
static class CommandExecutor.CommandExecutorEvent
          The types of events the CommandExecutor FiniteStateMachine will accept.
static class CommandExecutor.State
          The set of possible CommandExecutor.States for a CommandExecutor.
 
Constructor Summary
CommandExecutor(Identifier ctxIdentifier, com.tangosol.net.PartitionedService svcPartition, ScheduledExecutorService executorService)
          Internal Constructor.
 
Method Summary
 SubmissionOutcome acceptCommandExecutionRequest(CommandExecutionRequest commandExecutionRequest, com.tangosol.net.BackingMapManagerContext ctxBackingMapManagerContext)
          Accepts the specified CommandExecutionRequest for execution by this CommandExecutor.
 Identifier getContextIdentifier()
          Returns the Identifier of the Context for which this CommandExecutor is coordinating CommandExecutionRequest execution.
 String getContextIdentity()
          Returns the Context Identifier as a string.
 long getContextVersion()
          Returns the version number of the Context that the CommandExecutor is managing.
 double getLocalAverageCommandExecutionDuration()
          Returns the average execution time (in milliseconds) for the Commands executed locally by the current owner of the Context (ie: local CommandExecutor).
 double getLocalCommandExecutionServiceDuration()
          Returns the local command execution service duration (in milliseconds).
 long getLocalCommandsExecuted()
          Returns the number of Commands that have been executed locally by the current owner of the Context (ie: local CommandExecutor).
 long getLocalCommandsSubmitted()
          Returns the number of Commands that have been submitted locally to the current owner of the Context (ie: local CommandExecutor).
 double getLocalLastCommandExecutionDuration()
          Returns the execution time (in milliseconds) for the last Command executed locally by the current owner of the Context (ie: the local CommandExecutor)
 double getLocalMaximumCommandExecutionDuration()
          Returns the maximum time (in milliseconds) that a Command has taken to execute locally by the current owner of the Context (ie: the local CommandExecutor)
 double getLocalMinimumCommandExecutionDuration()
          Returns the minimum time (in milliseconds) that a Command has taken to execute locally by the current owner of the Context (ie: the local CommandExecutor)
 String getMBeanName()
          Returns the cluster-wide uniquely generated JMX bean name for the CommandExecutor.
 CommandExecutor.State getState()
          Obtains the current CommandExecutor.State of the CommandExecutor.
 String getStatus()
          Returns the current CommandExecutor.State of the CommandExecutor.
 long getTicketIssuerId()
          Returns the current id that is being used to issue Tickets.
 long getTotalCommandExecutionDuration()
          Returns the total time (in milliseconds) that the Commands executed thus far have taken to execute.
 long getTotalCommandExecutionWaitingDuration()
          Returns the total time (in milliseconds) that the Commands executed thus far have waited to execute (ie: the queuing time).
 long getTotalCommandsExecuted()
          Returns the total number of Commands for the Context that have been executed (regardless of the owner)
 long getTotalCommandsPendingExecution()
          Returns the total number of Commands that are yet to be executed
 Instruction onDelaying(CommandExecutor.State previousState, CommandExecutor.State newState, Event event, ExecutionContext context)
          Handles when the CommandExecutor has to delay execution of CommandExecutionRequests due to doubt of context ownership
 Instruction onExecuting(CommandExecutor.State previousState, CommandExecutor.State newState, Event event, ExecutionContext context)
          Executes one or more CommandExecutionRequests that are currently waiting to be executed for the command context.
 Instruction onScheduled(CommandExecutor.State previousState, CommandExecutor.State newState, Event event, ExecutionContext context)
          Handles when the CommandExecutor schedules to execute CommandExecutionRequests.
 Instruction onStarting(CommandExecutor.State previousState, CommandExecutor.State newState, Event event, ExecutionContext context)
          Starts ups, initializes, recovers and schedules the CommandExecutor to start processing CommandExecutionRequests.
 Instruction onStopping(CommandExecutor.State previousState, CommandExecutor.State newState, Event event, ExecutionContext context)
          Handles the shutdown/stopping process, afterwhich no further requests will be processed.
 void start()
          Starts up, initializes, recovers and schedules the CommandExecutor to start processing CommandExecutionRequests.
 void stop()
          Immediately stops the CommandExecutor from executing any further CommandExecutionRequests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandExecutor

public CommandExecutor(Identifier ctxIdentifier,
                       com.tangosol.net.PartitionedService svcPartition,
                       ScheduledExecutorService executorService)
Internal Constructor. NOTE: To construct a CommandExecutor for your application, you should use a ContextsManager.

Parameters:
ctxIdentifier -
Method Detail

getContextIdentifier

public Identifier getContextIdentifier()
Returns the Identifier of the Context for which this CommandExecutor is coordinating CommandExecutionRequest execution. Context Identifiers are unique across a cluster.


getState

public CommandExecutor.State getState()
Obtains the current CommandExecutor.State of the CommandExecutor.


getMBeanName

public String getMBeanName()
Returns the cluster-wide uniquely generated JMX bean name for the CommandExecutor.


getContextIdentity

public String getContextIdentity()
Description copied from interface: CommandExecutorMBean
Returns the Context Identifier as a string.

Specified by:
getContextIdentity in interface CommandExecutorMBean

getContextVersion

public long getContextVersion()
Description copied from interface: CommandExecutorMBean
Returns the version number of the Context that the CommandExecutor is managing.

Specified by:
getContextVersion in interface CommandExecutorMBean

getStatus

public String getStatus()
Description copied from interface: CommandExecutorMBean
Returns the current CommandExecutor.State of the CommandExecutor.

Specified by:
getStatus in interface CommandExecutorMBean

getTicketIssuerId

public long getTicketIssuerId()
Description copied from interface: CommandExecutorMBean
Returns the current id that is being used to issue Tickets.

NOTE: If another CommandExecutor is created for same Context with the same Identifier in the cluster (due to recovery / load-balancing of Contexts), a new Ticket issuer id will be allocated to the new CommandExecutor. This ensures that for each instance of a CommandExecutor, the Ticket issuer id will be different, thus allowing us to "order" Commands send to particular CommandExecutors.

Specified by:
getTicketIssuerId in interface CommandExecutorMBean

getTotalCommandsPendingExecution

public long getTotalCommandsPendingExecution()
Description copied from interface: CommandExecutorMBean
Returns the total number of Commands that are yet to be executed

Specified by:
getTotalCommandsPendingExecution in interface CommandExecutorMBean

getLocalCommandsSubmitted

public long getLocalCommandsSubmitted()
Description copied from interface: CommandExecutorMBean
Returns the number of Commands that have been submitted locally to the current owner of the Context (ie: local CommandExecutor).

Specified by:
getLocalCommandsSubmitted in interface CommandExecutorMBean

getLocalCommandsExecuted

public long getLocalCommandsExecuted()
Description copied from interface: CommandExecutorMBean
Returns the number of Commands that have been executed locally by the current owner of the Context (ie: local CommandExecutor).

Specified by:
getLocalCommandsExecuted in interface CommandExecutorMBean

getLocalAverageCommandExecutionDuration

public double getLocalAverageCommandExecutionDuration()
Description copied from interface: CommandExecutorMBean
Returns the average execution time (in milliseconds) for the Commands executed locally by the current owner of the Context (ie: local CommandExecutor).

Specified by:
getLocalAverageCommandExecutionDuration in interface CommandExecutorMBean

getLocalLastCommandExecutionDuration

public double getLocalLastCommandExecutionDuration()
Description copied from interface: CommandExecutorMBean
Returns the execution time (in milliseconds) for the last Command executed locally by the current owner of the Context (ie: the local CommandExecutor)

Specified by:
getLocalLastCommandExecutionDuration in interface CommandExecutorMBean

getLocalCommandExecutionServiceDuration

public double getLocalCommandExecutionServiceDuration()
Description copied from interface: CommandExecutorMBean
Returns the local command execution service duration (in milliseconds). This includes the time to get the command as well as the time to execute the command.

Specified by:
getLocalCommandExecutionServiceDuration in interface CommandExecutorMBean

getLocalMinimumCommandExecutionDuration

public double getLocalMinimumCommandExecutionDuration()
Description copied from interface: CommandExecutorMBean
Returns the minimum time (in milliseconds) that a Command has taken to execute locally by the current owner of the Context (ie: the local CommandExecutor)

Specified by:
getLocalMinimumCommandExecutionDuration in interface CommandExecutorMBean

getLocalMaximumCommandExecutionDuration

public double getLocalMaximumCommandExecutionDuration()
Description copied from interface: CommandExecutorMBean
Returns the maximum time (in milliseconds) that a Command has taken to execute locally by the current owner of the Context (ie: the local CommandExecutor)

Specified by:
getLocalMaximumCommandExecutionDuration in interface CommandExecutorMBean

getTotalCommandsExecuted

public long getTotalCommandsExecuted()
Description copied from interface: CommandExecutorMBean
Returns the total number of Commands for the Context that have been executed (regardless of the owner)

Specified by:
getTotalCommandsExecuted in interface CommandExecutorMBean

getTotalCommandExecutionDuration

public long getTotalCommandExecutionDuration()
Description copied from interface: CommandExecutorMBean
Returns the total time (in milliseconds) that the Commands executed thus far have taken to execute.

Specified by:
getTotalCommandExecutionDuration in interface CommandExecutorMBean

getTotalCommandExecutionWaitingDuration

public long getTotalCommandExecutionWaitingDuration()
Description copied from interface: CommandExecutorMBean
Returns the total time (in milliseconds) that the Commands executed thus far have waited to execute (ie: the queuing time).

Specified by:
getTotalCommandExecutionWaitingDuration in interface CommandExecutorMBean

onStarting

public Instruction onStarting(CommandExecutor.State previousState,
                              CommandExecutor.State newState,
                              Event event,
                              ExecutionContext context)
Starts ups, initializes, recovers and schedules the CommandExecutor to start processing CommandExecutionRequests.

Parameters:
previousState - the previous CommandExecutor.State
newState - the new CommandExecutor.State
Returns:
the Instruction to perform once the CommandExecutor is started.

start

public void start()
Starts up, initializes, recovers and schedules the CommandExecutor to start processing CommandExecutionRequests.


onScheduled

public Instruction onScheduled(CommandExecutor.State previousState,
                               CommandExecutor.State newState,
                               Event event,
                               ExecutionContext context)
Handles when the CommandExecutor schedules to execute CommandExecutionRequests.

Parameters:
previousState - the previous CommandExecutor.State
newState - the new CommandExecutor.State
Returns:
the Instruction to perform once the CommandExecutor is started.

onDelaying

public Instruction onDelaying(CommandExecutor.State previousState,
                              CommandExecutor.State newState,
                              Event event,
                              ExecutionContext context)
Handles when the CommandExecutor has to delay execution of CommandExecutionRequests due to doubt of context ownership

Parameters:
previousState - the previous CommandExecutor.State
newState - the new CommandExecutor.State
Returns:
the Instruction to perform once the CommandExecutor is started.

onStopping

public Instruction onStopping(CommandExecutor.State previousState,
                              CommandExecutor.State newState,
                              Event event,
                              ExecutionContext context)
Handles the shutdown/stopping process, afterwhich no further requests will be processed.

Parameters:
previousState - the previous CommandExecutor.State
newState - the new CommandExecutor.State
Returns:
the Instruction to perform once the CommandExecutor is started.

stop

public void stop()
Immediately stops the CommandExecutor from executing any further CommandExecutionRequests.


acceptCommandExecutionRequest

public SubmissionOutcome acceptCommandExecutionRequest(CommandExecutionRequest commandExecutionRequest,
                                                       com.tangosol.net.BackingMapManagerContext ctxBackingMapManagerContext)
Accepts the specified CommandExecutionRequest for execution by this CommandExecutor.

As part of this process, the CommandExecutionRequest is issued with a Ticket, has the instant in time the CommandExecutionRequest was accepted (queued), places the CommandExecutionRequest into the CommandExecutionRequests cache and queues the CommandExecutionRequest for execution.

If the Member in which this CommandExecutor is running no longer owns the Context to which the CommandExecutionRequest has been submitted (or ownership is in doubt), a Ticket.NONE is returned.

Parameters:
commandExecutionRequest - The CommandExecutionRequest to be accepted

onExecuting

public Instruction onExecuting(CommandExecutor.State previousState,
                               CommandExecutor.State newState,
                               Event event,
                               ExecutionContext context)
Executes one or more CommandExecutionRequests that are currently waiting to be executed for the command context.

Parameters:
previousState - the previous CommandExecutor.State
newState - the new CommandExecutor.State
Returns:
the Instruction to perform once the CommandExecutor is started.


Copyright © 2016. All rights reserved.