This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

1. Removed CONTEXTUAL_CALLBACK_HINT execution property. 2. Added clar…

…ification that passing null to intf or interfaces argument in ContextService.createContextualProxy method would throw IllegalArgumentException. 3. Replaced ContextService.USE_PARENT_TRANSACTION with ManagedTask.TRANSACTION. 4. Added task argument to all ManagedTaskListener methods.

svn path=/trunk/; revision=23
  • Loading branch information...
alai8 committed Feb 15, 2013
1 parent 514c0df commit 3fcf39af8c091fb0cb5243316c777b6b3ac85a01
@@ -80,29 +80,6 @@
*/
public interface ContextService {
/**
* An execution property that disables the normal transaction
* suspension and {@code UserTransaction} access from the proxied methods. This is
* useful only when the proxy method is invoked to run on the same thread.
* This property will be ignored when the proxy object is submitted for
* execution asynchronously on a different thread, such as if it is specified
* in the execution properties of a {@link ManagedTask} which is submitted to
* an {@link java.util.concurrent.Executor} or any of its subclasses.
* <p>
* If "false" (the default if unspecified), any transaction that is
* currently active on the thread will be suspended and a UserTransaction
* (accessible in the local JNDI namespace as "java:comp/UserTransaction")
* will be available. When the proxied method returns the original
* transaction is restored.
* <p>
* If "true", the proxied method will run within the transaction (if any) of
* the current thread. A UserTransaction will only be available if it is
* also available in the container thread (for example, a Servlet or Bean
* Managed Transaction EJB).
* <P>
*/
public final String USE_PARENT_TRANSACTION = "javax.enterprise.concurrent.USE_PARENT_TRANSACTION";
/**
* Creates a new contextual object proxy for the input object instance.
* <p>
@@ -147,8 +124,9 @@
* @param instance the instance of the object to proxy.
* @param intf the interface that the proxy should implement.
* @return a proxy for the input object that implements the specified interface.
* @throws java.lang.IllegalArgumentException - if the instance does not implement the specified
* interface or there is not an accessible default constructor.
* @throws java.lang.IllegalArgumentException - if the {@code intf} argument
* is null, the instance does not implement the specified
* interface, or there is not an accessible default constructor.
*
*/
public <T> T createContextualProxy(T instance, Class<T> intf);
@@ -195,8 +173,9 @@
* @param interfaces the interfaces that the proxy should implement.
* @return a proxy for the input object that implements all of the specified
* interfaces.
* @throws java.lang.IllegalArgumentException - if the instance does not implement
* all the specified interfaces or there is not an accessible default constructor.
* @throws java.lang.IllegalArgumentException - if the {@code interfaces}
* argument is null, the instance does not implement
* all the specified interfaces, or there is not an accessible default constructor.
*
*/
public Object createContextualProxy(Object instance, Class<?>... interfaces);
@@ -288,9 +267,9 @@
* @param intf the interface that the proxy should implement.
* @return a proxy for the input object that implements the specified interface.
*
* @throws java.lang.IllegalArgumentException - if the instance does not
* implement the specified interface or there is not an accessible
* default constructor.
* @throws java.lang.IllegalArgumentException - if the {@code intf} argument
* null, the instance does not implement the specified interface, or there is
* not an accessible default constructor.
*/
public <T> T createContextualProxy(T instance,
Map<String, String> executionProperties,
@@ -310,9 +289,9 @@
* @return a proxy for the input object that implements all of the specified
* interfaces.
*
* @throws java.lang.IllegalArgumentException - if the instance does not
* implement all the specified interfaces or there is not an
* accessible default constructor.
* @throws java.lang.IllegalArgumentException - if the {@code interfaces}
* argument is null, the instance does not implement all the specified
* interfaces, or there is not an accessible default constructor.
*/
public Object createContextualProxy(Object instance,
Map<String, String> executionProperties,
@@ -68,13 +68,33 @@
/**
* Execution property to be returned in {@link #getExecutionProperties()} or
* {@link ContextService#createContextualProxy(java.lang.Object, java.util.Map, java.lang.Class) ContextService.createContextualProxy()}
* to provide a hint about whether the methods in {@link ManagedTaskListener} and
* {@link Trigger} associated with this task needs to be called under the same
* context as the task. Any values other than "true" means the methods will be
* run with unspecified context.
* to inform the Java&trade; EE Product Provider under which transaction
* should the task or proxy method of contextual proxy object be executed
* in.
*
* Valid values are:
* <p>
* "SUSPEND" (the default if unspecified) - Any transaction that is currently
* active on the thread will be suspended and a
* {@link javax.transaction.UserTransaction} (accessible in the local
* JNDI namespace as "java:comp/UserTransaction") will be available. The
* original transaction, if any was active on the thread, will be resumed
* when the task or contextual proxy object method returns.
*
* <p>
* "USE_TRANSACTION_OF_EXECUTION_THREAD" - The contextual proxy object method
* will run within the transaction (if any) of the execution thread. A
* {@link javax.transaction.UserTransaction} will only be available if it is
* also available in the execution thread (for example, when the proxy method
* is invoked from a Servlet or Bean Managed Transaction EJB). When there is
* no existing transaction on the execution thread, such as when running tasks
* that are submitted to a {@link ManagedExecutorService} or a
* {@link ManagedScheduledExecutorService}, a
* {@link javax.transaction.UserTransaction} will be available.
* <P>
*/
public static final String CONTEXTUAL_CALLBACK_HINT = "javax.enterprise.concurrent.CONTEXTUAL_CALLBACK_HINT";
public final String TRANSACTION = "javax.enterprise.concurrent.TRANSACTION";
/**
* Execution property to be returned in {@link #getExecutionProperties()} or
* {@link ContextService#createContextualProxy(java.lang.Object, java.util.Map, java.lang.Class) ContextService.createContextualProxy()}
@@ -124,9 +124,11 @@
*
* @param future the <code>Future</code> instance that was created when the task was submitted.
* @param executor the executor used to run the associated Future.
* @param task the task that was submitted.
*/
public void taskSubmitted(java.util.concurrent.Future<?> future,
ManagedExecutorService executor);
ManagedExecutorService executor,
Object task);
/**
* Called when a task's Future has been cancelled anytime during the life of a task.
@@ -144,22 +146,27 @@ public void taskSubmitted(java.util.concurrent.Future<?> future,
*
* @param future the {@link Future} instance that was created when the task was submitted.
* @param executor the executor used to run the associated Future.
* @param task the task that was submitted.
* @param exception the cause of the task abort.
*/
public void taskAborted(java.util.concurrent.Future<?> future,
ManagedExecutorService executor,
Object task,
java.lang.Throwable exception);
/**
* Called when a submitted task has completed running, successful or otherwise after
* submitted.
* Called when a submitted task has completed running, either successfully or
* failed due to any exception thrown from the task, task being cancelled,
* rejected, or aborted.
*
* @param future the {@link Future} instance that was created when the task was submitted.
* @param executor the executor used to run the associated Future.
* @param task the task that was submitted.
* @param exception if not null, the exception that caused the task to fail.
*/
public void taskDone(java.util.concurrent.Future<?> future,
ManagedExecutorService executor,
Object task,
java.lang.Throwable exception);
/**
@@ -169,7 +176,9 @@ public void taskDone(java.util.concurrent.Future<?> future,
*
* @param future the {@link Future} instance that was created when the task was submitted.
* @param executor the executor used to run the associated Future.
* @param task the task that was submitted.
*/
public void taskStarting(java.util.concurrent.Future<?> future,
ManagedExecutorService executor);
ManagedExecutorService executor,
Object task);
}
@@ -47,17 +47,14 @@
* application developer (or may be supplied to the application
* externally) and is registered with a task when it is submitted
* to a {@link ManagedScheduledExecutorService} using any of the
* schedule methods. Each method will run with unspecified context unless
* {@link ManagedTask#CONTEXTUAL_CALLBACK_HINT} is specified to control whether
* or not these callback methods run under the same context in
* which the task runs.
* schedule methods. Each method will run with unspecified context.
* The methods can be made contextual through creating contextual
* proxy objects using {@link ContextService}.
* <p>
* Each Trigger instance will be invoked within the same process
* in which it was registered.
* <p>
* Trigger should be Serializable if it is to be used on a distributed
* {@code ManagedScheduledExecutorService}.
* <p>
*
* Example:
* <pre>
* &#47;**
@@ -96,7 +96,7 @@ public void testManagedTask_Runnable_executionProperties_ManagedTaskListener() {
public void testManagedTask_Runnable_ManagedTask() {
ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl();
Map<String, String> EXEC_PROPERTIES = new HashMap<>();
EXEC_PROPERTIES.put(ManagedTask.CONTEXTUAL_CALLBACK_HINT, "true");
EXEC_PROPERTIES.put("custom", "true");
EXEC_PROPERTIES.put(ManagedTask.LONGRUNNING_HINT, "false");
final String TASK_DESCRIPTION = "task1 description";
ManagedTaskRunnableImpl task = new ManagedTaskRunnableImpl(TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER);
@@ -112,7 +112,7 @@ public void testManagedTask_Runnable_ManagedTask() {
assertTrue(taskListener == managedTask.getManagedTaskListener());
assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.LONGRUNNING_HINT));
assertEquals(TASK_NAME, managedTask.getExecutionProperties().get(ManagedTask.IDENTITY_NAME));
assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.CONTEXTUAL_CALLBACK_HINT));
assertEquals("true", managedTask.getExecutionProperties().get("custom"));
}
/**
@@ -124,14 +124,14 @@ public void testManagedTask_Runnable_ManagedTask() {
public void testManagedTask_Runnable_ManagedTask_null_args() {
ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl();
Map<String, String> EXEC_PROPERTIES = new HashMap<>();
EXEC_PROPERTIES.put(ManagedTask.CONTEXTUAL_CALLBACK_HINT, "true");
EXEC_PROPERTIES.put("custom", "true");
final String TASK_DESCRIPTION = "task1 description";
ManagedTaskRunnableImpl task = new ManagedTaskRunnableImpl(TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER);
Runnable wrapped = ManagedExecutors.managedTask(task, null, null);
ManagedTask managedTask = (ManagedTask) wrapped;
assertTrue(TASK_LISTENER == managedTask.getManagedTaskListener());
assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.CONTEXTUAL_CALLBACK_HINT));
assertEquals("true", managedTask.getExecutionProperties().get("custom"));
}
/**
@@ -182,7 +182,7 @@ public void testManagedTask_Callable_ManagedTask() {
final String RESULT = "result";
ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl();
Map EXEC_PROPERTIES = new HashMap<>();
EXEC_PROPERTIES.put(ManagedTask.CONTEXTUAL_CALLBACK_HINT, "true");
EXEC_PROPERTIES.put("custom", "true");
EXEC_PROPERTIES.put(ManagedTask.LONGRUNNING_HINT, "false");
final String TASK_DESCRIPTION = "task1 description";
ManagedTaskCallableImpl<String> task = new ManagedTaskCallableImpl(RESULT, TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER);
@@ -198,7 +198,7 @@ public void testManagedTask_Callable_ManagedTask() {
assertTrue(taskListener == managedTask.getManagedTaskListener());
assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.LONGRUNNING_HINT));
assertEquals(TASK_NAME, managedTask.getExecutionProperties().get(ManagedTask.IDENTITY_NAME));
assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.CONTEXTUAL_CALLBACK_HINT));
assertEquals("true", managedTask.getExecutionProperties().get("custom"));
}
/**
@@ -211,14 +211,14 @@ public void testManagedTask_Callable_ManagedTask_null_args() {
final String RESULT = "result";
ManagedTaskListenerImpl TASK_LISTENER = new ManagedTaskListenerImpl();
Map EXEC_PROPERTIES = new HashMap<>();
EXEC_PROPERTIES.put(ManagedTask.CONTEXTUAL_CALLBACK_HINT, "true");
EXEC_PROPERTIES.put("custom", "true");
final String TASK_DESCRIPTION = "task1 description";
ManagedTaskCallableImpl<String> task = new ManagedTaskCallableImpl(RESULT, TASK_DESCRIPTION, EXEC_PROPERTIES, TASK_LISTENER);
Callable wrapped = ManagedExecutors.managedTask(task, null, null);
ManagedTask managedTask = (ManagedTask) wrapped;
assertTrue(TASK_LISTENER == managedTask.getManagedTaskListener());
assertEquals("true", managedTask.getExecutionProperties().get(ManagedTask.CONTEXTUAL_CALLBACK_HINT));
assertEquals("true", managedTask.getExecutionProperties().get("custom"));
}
@Test (expected = IllegalArgumentException.class)
@@ -331,19 +331,19 @@ public ManagedTaskListener getManagedTaskListener() {
static class ManagedTaskListenerImpl implements ManagedTaskListener {
@Override
public void taskSubmitted(Future<?> future, ManagedExecutorService executor) {
public void taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task) {
}
@Override
public void taskAborted(Future<?> future, ManagedExecutorService executor, Throwable exception) {
public void taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception) {
}
@Override
public void taskDone(Future<?> future, ManagedExecutorService executor, Throwable exception) {
public void taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception) {
}
@Override
public void taskStarting(Future<?> future, ManagedExecutorService executor) {
public void taskStarting(Future<?> future, ManagedExecutorService executor, Object task) {
}
}

0 comments on commit 3fcf39a

Please sign in to comment.