use of javax.enterprise.concurrent.ManagedExecutorService in project Payara by payara.
the class AsynchronousInterceptor method intercept.
@AroundInvoke
public Object intercept(InvocationContext invocationContext) throws Exception {
Object proceededInvocationContext = null;
// Get the configured ManagedExecutorService from the Fault Tolerance Service
FaultToleranceService faultToleranceService = Globals.getDefaultBaseServiceLocator().getService(FaultToleranceService.class);
ManagedExecutorService managedExecutorService = faultToleranceService.getManagedExecutorService();
InvocationManager invocationManager = Globals.getDefaultBaseServiceLocator().getService(InvocationManager.class);
Config config = null;
try {
config = ConfigProvider.getConfig();
} catch (IllegalArgumentException ex) {
logger.log(Level.INFO, "No config could be found", ex);
}
try {
// Attempt to proceed the InvocationContext with Asynchronous semantics if Fault Tolerance is enabled
if (faultToleranceService.isFaultToleranceEnabled(faultToleranceService.getApplicationName(invocationManager, invocationContext), config)) {
Callable callable = () -> {
return invocationContext.proceed();
};
logger.log(Level.FINER, "Proceeding invocation asynchronously");
proceededInvocationContext = new FutureDelegator(managedExecutorService.submit(callable));
} else {
// If fault tolerance isn't enabled, just proceed as normal
logger.log(Level.FINE, "Fault Tolerance not enabled for {0}, proceeding normally without asynchronous.", faultToleranceService.getApplicationName(invocationManager, invocationContext));
proceededInvocationContext = invocationContext.proceed();
}
} catch (Exception ex) {
// If an exception was thrown, check if the method is annotated with @Fallback
// We should only get here if executing synchronously, as the exception wouldn't get thrown in this thread
Fallback fallback = FaultToleranceCdiUtils.getAnnotation(beanManager, Fallback.class, invocationContext);
// If the method was annotated with Fallback, attempt it, otherwise just propagate the exception upwards
if (fallback != null) {
logger.log(Level.FINE, "Fallback annotation found on method - falling back from Asynchronous");
FallbackPolicy fallbackPolicy = new FallbackPolicy(fallback, config, invocationContext);
proceededInvocationContext = fallbackPolicy.fallback(invocationContext);
} else {
throw ex;
}
}
return proceededInvocationContext;
}
use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.
the class HungTasksTerminationTestCase method testManagedScheduledExecutorServiceHungTasksCancellationOperation.
/**
* Tests the 'on demand' hung task termination, through a management operation, works on a ManagedScheduledExecutorService.
* @throws Exception
*/
@Test
public void testManagedScheduledExecutorServiceHungTasksCancellationOperation() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup the executor
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationOperation(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
}
}
use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.
the class HungTasksTerminationTestCase method testManagedScheduledExecutorServiceHungTasksCancellationPeriodic.
/**
* Tests the 'periodic' hung task termination works on a ManagedScheduledExecutorService.
* @throws Exception
*/
@Test
public void testManagedScheduledExecutorServiceHungTasksCancellationPeriodic() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD).set(HUNG_TASK_CANCELLATION_PERIOD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
// lookup the executor
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationPeriodic(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
}
}
use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.
the class HungTasksTerminationTestCase method testManagedExecutorServiceHungTasksCancellationOperation.
/**
* Tests the 'on demand' hung task termination, through a management operation, works on a ManagedExecutorService.
* @throws Exception
*/
@Test
public void testManagedExecutorServiceHungTasksCancellationOperation() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationOperation(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
}
}
use of javax.enterprise.concurrent.ManagedExecutorService in project wildfly by wildfly.
the class HungTasksTerminationTestCase method testManagedExecutorServiceHungTasksCancellationPeriodic.
/**
* Tests the 'periodic' hung task termination works on a ManagedExecutorService.
* @throws Exception
*/
@Test
public void testManagedExecutorServiceHungTasksCancellationPeriodic() throws Exception {
final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
// add
final ModelNode addOperation = Util.createAddOperation(pathAddress);
final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
addOperation.get(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD).set(HUNG_TASK_THRESHOLD_TEST_VALUE);
addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD).set(HUNG_TASK_CANCELLATION_PERIOD_TEST_VALUE);
final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
try {
final ManagedExecutorService executorService = InitialContext.doLookup(jndiName);
Assert.assertNotNull(executorService);
testHungTasksCancellationPeriodic(pathAddress, executorService);
} finally {
// remove
final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
}
}
Aggregations