View Javadoc

1   /*
2    * $Id: TransactionNotification.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.context.notification;
12  
13  import org.mule.api.context.notification.BlockingServerEvent;
14  import org.mule.api.context.notification.ServerNotification;
15  import org.mule.api.transaction.Transaction;
16  
17  public class TransactionNotification extends ServerNotification implements BlockingServerEvent
18  {
19      /**
20       * Serial version
21       */
22      private static final long serialVersionUID = -3245036187011582121L;
23      public static final int TRANSACTION_BEGAN = TRANSACTION_EVENT_ACTION_START_RANGE + 1;
24      public static final int TRANSACTION_COMMITTED = TRANSACTION_EVENT_ACTION_START_RANGE + 2;
25      public static final int TRANSACTION_ROLLEDBACK = TRANSACTION_EVENT_ACTION_START_RANGE + 3;
26  
27      static
28      {
29          registerAction("begin", TRANSACTION_BEGAN);
30          registerAction("commit", TRANSACTION_COMMITTED);
31          registerAction("rollback", TRANSACTION_ROLLEDBACK);
32      }
33  
34      /**
35       * Ideally, that should've been a transaction's XID, but we'd need to resort to all kinds of reflection tricks to
36       * get it. Still, toString() typically outputs a class name followed by the XID, so that's good enough.
37       */
38      private String transactionStringId;
39  
40      public TransactionNotification(Transaction transaction, int action)
41      {
42          super(transaction.getId(), action, transaction.getId());
43          this.transactionStringId = transaction.getId();
44      }
45  
46      public String getTransactionStringId()
47      {
48          return this.transactionStringId;
49      }
50  
51      @Override
52      public String toString()
53      {
54          return EVENT_NAME + "{" + "action=" + getActionName(action) + ", transactionStringId=" + transactionStringId
55                 + ", timestamp=" + timestamp + "}";
56      }
57  
58  }