com.amazon.carbonado.capability
Class ResyncCapability.Listener<S>

java.lang.Object
  extended by com.amazon.carbonado.Trigger<S>
      extended by com.amazon.carbonado.capability.ResyncCapability.Listener<S>
Enclosing interface:
ResyncCapability

public static class ResyncCapability.Listener<S>
extends Trigger<S>

Trigger which is invoked as storables get re-sync'd. Callbacks are invoked in the scope of the resync transaction. If any unchecked exception is thrown, the immediate changes are rolled back and the entire repository resync operation is aborted.

The listener implementation should return quickly from the callback methods, to avoid lingering transactions. If the listener is used to invoke special repair operations, they should be placed into a task queue. A separate thread can then perform the repairs outside the resync transaction.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.amazon.carbonado.Trigger
Trigger.Abort
 
Constructor Summary
ResyncCapability.Listener()
           
 
Method Summary
 void afterDelete(S oldStorable, Object state)
          Called right after a bogus storable has been successfully deleted.
 void afterInsert(S newStorable, Object state)
          Called right after a sync'd storable has been successfully inserted.
 void afterUpdate(S newStorable, Object state)
          Called right after a sync'd storable has been successfully updated.
 Object beforeDelete(S oldStorable)
          Called before a bogus storable is to be deleted.
 Object beforeInsert(S newStorable)
          Called before a sync'd storable is to be inserted.
 Object beforeUpdate(S newStorable)
          Called before a sync'd storable is to be updated.
 Object beforeUpdate(S oldStorable, S newStorable)
          Overloaded version of beforeUpdate method which is passed the storable in it's out-of-sync and sync'd states.
 void failedDelete(S oldStorable, Object state)
          Called when a delete operation failed because an exception was thrown.
 void failedInsert(S newStorable, Object state)
          Called when an insert operation failed because an exception was thrown.
 void failedUpdate(S newStorable, Object state)
          Called when an update operation failed because an exception was thrown.
 
Methods inherited from class com.amazon.carbonado.Trigger
abortTry, afterLoad, afterTryDelete, afterTryInsert, afterTryUpdate, beforeTryDelete, beforeTryInsert, beforeTryUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResyncCapability.Listener

public ResyncCapability.Listener()
Method Detail

beforeInsert

public Object beforeInsert(S newStorable)
                    throws PersistException
Called before a sync'd storable is to be inserted. Changes can be made to the storable at this point, possibly to define independent properties.

Overrides:
beforeInsert in class Trigger<S>
Parameters:
newStorable - sync'd storable before being inserted
Returns:
arbitrary state object, passed to afterInsert or failedInsert method
Throws:
PersistException

afterInsert

public void afterInsert(S newStorable,
                        Object state)
                 throws PersistException
Called right after a sync'd storable has been successfully inserted.

Overrides:
afterInsert in class Trigger<S>
Parameters:
newStorable - sync'd storable after being inserted
state - object returned by beforeInsert method
Throws:
PersistException

failedInsert

public void failedInsert(S newStorable,
                         Object state)
Called when an insert operation failed because an exception was thrown. The main purpose of this method is to allow any necessary clean-up to occur on the optional state object.

Overrides:
failedInsert in class Trigger<S>
Parameters:
newStorable - sync'd storable which failed to be inserted
state - object returned by beforeInsert method, but it may be null

beforeUpdate

public Object beforeUpdate(S newStorable)
                    throws PersistException
Called before a sync'd storable is to be updated. Changes can be made to the storable at this point, possibly to update independent properties.

Overrides:
beforeUpdate in class Trigger<S>
Parameters:
newStorable - sync'd storable before being updated
Returns:
arbitrary state object, passed to afterUpdate or failedUpdate method
Throws:
PersistException

beforeUpdate

public Object beforeUpdate(S oldStorable,
                           S newStorable)
                    throws PersistException
Overloaded version of beforeUpdate method which is passed the storable in it's out-of-sync and sync'd states. Changes can be made to the storable at this point, possibly to update independent properties.

The default implementation calls the single argument beforeUpdate method, only passing the newly sync'd storable.

Parameters:
oldStorable - storable prior to being sync'd
newStorable - sync'd storable before being updated
Throws:
PersistException

afterUpdate

public void afterUpdate(S newStorable,
                        Object state)
                 throws PersistException
Called right after a sync'd storable has been successfully updated.

Overrides:
afterUpdate in class Trigger<S>
Parameters:
newStorable - sync'd storable after being updated
state - optional object returned by beforeUpdate method
Throws:
PersistException

failedUpdate

public void failedUpdate(S newStorable,
                         Object state)
Called when an update operation failed because an exception was thrown. The main purpose of this method is to allow any necessary clean-up to occur on the optional state object.

Overrides:
failedUpdate in class Trigger<S>
Parameters:
newStorable - sync'd storable which failed to be updated
state - object returned by beforeUpdate method, but it may be null

beforeDelete

public Object beforeDelete(S oldStorable)
                    throws PersistException
Called before a bogus storable is to be deleted.

Overrides:
beforeDelete in class Trigger<S>
Parameters:
oldStorable - bogus storable before being deleted
Returns:
arbitrary state object, passed to afterDelete or failedDelete method
Throws:
PersistException

afterDelete

public void afterDelete(S oldStorable,
                        Object state)
                 throws PersistException
Called right after a bogus storable has been successfully deleted.

Overrides:
afterDelete in class Trigger<S>
Parameters:
oldStorable - bogus storable after being deleted
state - optional object returned by beforeDelete method
Throws:
PersistException

failedDelete

public void failedDelete(S oldStorable,
                         Object state)
Called when a delete operation failed because an exception was thrown. The main purpose of this method is to allow any necessary clean-up to occur on the optional state object.

Overrides:
failedDelete in class Trigger<S>
Parameters:
oldStorable - bogus storable which failed to be deleted
state - object returned by beforeDelete method, but it may be null


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.