org.rhq.core.pc.operation
Class OperationThreadPoolGateway

java.lang.Object
  extended by org.rhq.core.pc.operation.OperationThreadPoolGateway

public class OperationThreadPoolGateway
extends Object

This provides a queue-like structure that will submit operations to a thread pool for execution, or will store the operations until a time when they are allowed to be invoked. This class is used to enforce the rule that no two operations that are to be invoked on the same resource can run concurrently. This gateway will pass through all operations to its internal thread pool, unless an operation is already queued or running in the thread pool that is executing on a resource that the newly submitted operation needs to execute on. In this case, the second operation will be queued in this gateway until such time when the first operation is finished with the resource.

An analogy of this is shopping in a department store. Assume for this example a store has two departments - a jewelry department and a shoe department. There is one sales person per department. Two shoppers can concurrently buy different types of products - one shopper can be buying from the sales person in the jewelry department while, at the exact same time, the other shopper can be buying from the sales person in the shoe department. However, if both shoppers want to buy something from the shoe department, the second one has to wait until the first is finished with the shoe department's sales person. They cannot both buy something in the shoe department at the same time. In this analogy, a resource is a sales person, and a shopper's purchasing interaction is an operation invocation.

Author:
John Mazzitelli

Constructor Summary
OperationThreadPoolGateway(ThreadPoolExecutor threadPool)
          Constructor for OperationThreadPoolGateway.
 
Method Summary
 OperationInvocation getOperationInvocation(String jobId)
          Returns the operation invocation that is responsible for executing the operation identified with the given job ID.
 void operationCompleted(OperationInvocation operation)
          This is called by the OperationInvocation when it finished to notify this gateway that if there are any other pending operations for the resource, that the next one is allowed to be executed.
 void shutdown()
          Follows the same semantics as ExecutorService.shutdownNow().
 void submit(OperationInvocation operation)
          Submits the given operation to the gateway for execution within the thread pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OperationThreadPoolGateway

public OperationThreadPoolGateway(ThreadPoolExecutor threadPool)
Constructor for OperationThreadPoolGateway. When an OperationInvocation passes through this gateway, it will be submitted for execution in the given thread pool.

Parameters:
threadPool -
Method Detail

shutdown

public void shutdown()
Follows the same semantics as ExecutorService.shutdownNow(). All operations previously submitted to the thread pool (that is, those operations that passed the gateway into the thread pool) will be canceled (or, at least, a best attempt will be made to cancel them). No additional operations will be allowed to be submitted to the gateway or the internal thread pool (including those that are queued in this gateway but not yet submitted to the thread pool). Any queued operations sitting in this gateway will be immediately canceled.


getOperationInvocation

public OperationInvocation getOperationInvocation(String jobId)
Returns the operation invocation that is responsible for executing the operation identified with the given job ID.

Parameters:
jobId - identifies the specific operation invocation to return
Returns:
the operation invocation associated with the given job ID or null if not found

submit

public void submit(OperationInvocation operation)
Submits the given operation to the gateway for execution within the thread pool. If the operation's resource already has an operation submitted to the thread pool, this gateway will hold onto the given operation until that previous operation has finished. This ensures that no two operations can be invoked on the same resource concurrently.

Parameters:
operation -
Throws:
IllegalStateException - if the gateway has been shutdown

operationCompleted

public void operationCompleted(OperationInvocation operation)
This is called by the OperationInvocation when it finished to notify this gateway that if there are any other pending operations for the resource, that the next one is allowed to be executed.

Parameters:
operation - the operation that has just completed


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.