com.cloudtran.coherence
Class DefaultManagerEventListener

java.lang.Object
  extended by com.cloudtran.coherence.DefaultManagerEventListener
All Implemented Interfaces:
ManagerEventListener

public class DefaultManagerEventListener
extends Object
implements ManagerEventListener

This is a default implementation of the ManagerEventListener.

It is also useful as an abstract base class for your own event listener. See the doHospital* methods for hospital actions.


Constructor Summary
DefaultManagerEventListener()
           
 
Method Summary
 boolean committing(ManagerEvent event, NamedSemaphore semaphore)
          This event is called once the preCommit() method returns successfully.
 void complete(ManagerEvent event)
          This event is called once all actions on this transaction (log, commit to the grid and persist) have completed.
 boolean doHospitalAction(Hospital.HospitalData hospitalData)
          Prints the message and data related to a fatal condition in transaction processing.
 boolean doTransactionLog(ManagerEvent event, boolean persisted, NamedSemaphore loggingSemaphore)
          This event is called when transaction logging is to be performed.
 void preCommit(ManagerEvent event)
          This event is called before the committing state.
 void rollback(ManagerEvent event)
          This event is called when an abort has been called.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultManagerEventListener

public DefaultManagerEventListener()
Method Detail

preCommit

public void preCommit(ManagerEvent event)
               throws TransactionExceptionNonRetriable
Description copied from interface: ManagerEventListener
This event is called before the committing state.

You can do further validation at this point. To abort the transaction, throw a RuntimeException. If this method returns normally, the transaction will commit.

This is an in-manager operation and is performance critical for the whole transaction manager. Do not make any access to caches or any external resource - this should be done by the client application during normal processing. Only write to disk in exceptional circumstances, such as fatal error conditions.

Specified by:
preCommit in interface ManagerEventListener
Parameters:
event - The ManagerEvent object
Throws:
TransactionExceptionNonRetriable - to indicate that the transaction cannot be committed. It will be rolled back.

committing

public boolean committing(ManagerEvent event,
                          NamedSemaphore semaphore)
Description copied from interface: ManagerEventListener
This event is called once the preCommit() method returns successfully. When this method is called, the transaction is in COMMITTING state and is guaranteed to commit.

The CloudTran replicator uses this event to relay the transaction (using event.gridObjects) to another grid transactionally. If you want to do your own replication, listen for this event and return true from your handler.

Do not do any persistence-related operations here - they should be done in the persister.

Specified by:
committing in interface ManagerEventListener
Parameters:
event - The ManagerEvent object
semaphore - A semaphore for the committing() method to release when its work is done. If this method returns true, it *must* release the semaphore in a timely fashion. If this method returns false, it must *not* release the semaphore.
Returns:
True if the method has handled the action on behalf of the manager: the manager will not call the committing() method any other event listeners.

complete

public void complete(ManagerEvent event)
Description copied from interface: ManagerEventListener
This event is called once all actions on this transaction (log, commit to the grid and persist) have completed.

It does not include transactions have been aborted

Specified by:
complete in interface ManagerEventListener
Parameters:
event - The ManagerEvent object

rollback

public void rollback(ManagerEvent event)
Description copied from interface: ManagerEventListener
This event is called when an abort has been called.

The abort process can not be guaranteed to have finished when this event is called.

Specified by:
rollback in interface ManagerEventListener
Parameters:
event - The ManagerEvent object

doTransactionLog

public boolean doTransactionLog(ManagerEvent event,
                                boolean persisted,
                                NamedSemaphore loggingSemaphore)
Description copied from interface: ManagerEventListener
This event is called when transaction logging is to be performed.

The doTransactionLog() method should not hold up the manager by calling logging synchronously. Instead, it should put the event onto a log queue and return immediately. When the asynchronous logging action has completed, it should release the passed semaphore.

If no ManagerEventListener handles the doLog event (i.e. returns true to this method), then the manager will perform the built-in logging.

Specified by:
doTransactionLog in interface ManagerEventListener
Parameters:
event - The ManagerEvent object
loggingSemaphore - A semaphore for the committing event to release when its work is done. If this method returns true, it *must* release the semaphore in a timely fashion. If this method returns false, it must *not* release the semaphore.
Returns:
True if the method has handled the action on behalf of the manager: the manager will not call the doLog() method of any other event listeners or do the standard CloudTran logging.

doHospitalAction

public boolean doHospitalAction(Hospital.HospitalData hospitalData)
Prints the message and data related to a fatal condition in transaction processing.

Then: in production mode, halts the manager JVM by executing System.exit(1); in non-production mode, simply returns - in the hope we can limp along.

The reason for "limping along" is that, by completing what we can of the transaction, there will be less damage to other transactions; it may be better to keep the grid alive.

Specified by:
doHospitalAction in interface ManagerEventListener
Parameters:
hospitalData - the data for the ReplicatorPut errors.
Returns:
True if the method has handled the action on behalf of the manager: the manager will not call any further event listeners to process the event.