public TimerTask cancel ( Serializable taskID ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Canceling task with timer id " + taskID ) ; } TimerTask task = localRunningTasks . get ( taskID ) ; if ( task != null ) { // remove task data new TimerTaskCacheData ( taskID , baseFqn , cluster ) . remove ( ) ; final SetTimerAfterTxCommitRunnable setAction = task . getSetTimerTransactionalAction ( ) ; if ( setAction != null ) { // we have a tx action scheduled to run when tx commits, to set the timer, lets simply cancel it setAction . cancel ( ) ; } else { // do cancellation AfterTxCommitRunnable runnable = new CancelTimerAfterTxCommitRunnable ( task , this ) ; if ( txManager != null ) { try { Transaction tx = txManager . getTransaction ( ) ; if ( tx != null ) { TransactionContext txContext = TransactionContextThreadLocal . getTransactionContext ( ) ; if ( txContext == null ) { txContext = new TransactionContext ( ) ; tx . registerSynchronization ( new TransactionSynchronization ( txContext ) ) ; } txContext . put ( taskID , runnable ) ; } else { runnable . run ( ) ; } } catch ( Throwable e ) { throw new RuntimeException ( "Unable to register tx synchronization object" , e ) ; } } else { runnable . run ( ) ; } } } else { // not found locally // if there is a tx context there may be a set timer action there if ( txManager != null ) { try { Transaction tx = txManager . getTransaction ( ) ; if ( tx != null ) { TransactionContext txContext = TransactionContextThreadLocal . getTransactionContext ( ) ; if ( txContext != null ) { final AfterTxCommitRunnable r = txContext . remove ( taskID ) ; if ( r != null ) { task = r . task ; // remove from cluster new TimerTaskCacheData ( taskID , baseFqn , cluster ) . remove ( ) ; } } } } catch ( Throwable e ) { throw new RuntimeException ( "Failed to check tx context." , e ) ; } } } return task ; }
Cancels a local running task with the specified ID .