super.registerOperations(resourceRegistration);
resourceRegistration.registerOperationHandler(SUSPEND, new AbstractTimerHandler() {
@Override
void executeRuntime(OperationContext context, ModelNode operation) throws OperationFailedException {
final TimerImpl timer = getTimer(context, operation);
timer.suspend();
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
timer.scheduleTimeout(true);
}
});
}
});
resourceRegistration.registerOperationHandler(ACTIVATE, new AbstractTimerHandler() {
@Override
void executeRuntime(OperationContext context, ModelNode operation) throws OperationFailedException {
final TimerImpl timer = getTimer(context, operation);
if (!timer.isActive()) {
timer.scheduleTimeout(true);
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
timer.suspend();
}
});
} else {
throw EjbLogger.ROOT_LOGGER.timerIsActive(timer);
}
}
});
resourceRegistration.registerOperationHandler(CANCEL, new AbstractTimerHandler() {
@Override
void executeRuntime(OperationContext context, ModelNode operation) throws OperationFailedException {
final TimerImpl timer = getTimer(context, operation);
// this is TX aware
timer.cancel();
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
});
resourceRegistration.registerOperationHandler(TRIGGER, new AbstractTimerHandler() {
@Override
void executeRuntime(OperationContext context, ModelNode operation) throws OperationFailedException {
// This will invoke timer in 'management-handler-thread'
final TimerImpl timer = getTimer(context, operation);
timer.invoke();
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
});
}