Triggers are defined on Managed Objects by implementing interfaces. The interfaces used are:
Delete triggers are invoked when a Managed Object is deleted. The object is still valid when the delete trigger is called.
Compensation triggers are invoked on the Managed Object that caused a state conflict restoring a node following a multi-master scenario. Compensation triggers are only called on the node where the merge is occurring (see the TIBCO ActiveSpaces® Transactions Architect's Guide). When the compensation trigger is called, the object fields contain the data in conflict. This data will be replaced with the data from the remote node after the trigger completes execution.
Example 5.12. Triggers
// $Revision: 1.1.2.3 $ package com.kabira.snippets.managedobjects; import com.kabira.platform.DeleteTrigger; import com.kabira.platform.ManagedObject; import com.kabira.platform.Transaction; import com.kabira.platform.Transaction.Rollback; import com.kabira.platform.annotation.Managed; /** * Delete trigger * <p> * <h2> Target Nodes</h2> * <ul> * <li> <b>domainnode</b> = A * </ul> */ public class Triggers { // // Managed object that implements a delete trigger @Managed private static class MyObject implements DeleteTrigger { private MyObject() { } String value; @Override public void uponDelete() { System.out.println("uponDelete: Deleting object"); } } /** * Main entry point * @param args Not used */ public static void main(String [] args) { new Transaction("Triggers") { @Override protected void run() throws Rollback { MyObject myObject = new MyObject(); ManagedObject.delete(myObject); } }.execute(); } }
When this snippet is run it outputs:
uponDelete: Deleting object