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