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.util.xa;
8   
9   import java.util.HashMap;
10  import java.util.Map;
11  
12  import javax.transaction.xa.Xid;
13  
14  public abstract class AbstractXAResourceManager extends AbstractResourceManager
15  {
16  
17      protected Map suspendedContexts = new HashMap();
18      protected Map activeContexts = new HashMap();
19  
20      public AbstractXAResourceManager()
21      {
22          super();
23      }
24  
25      protected boolean includeBranchInXid()
26      {
27          return true;
28      }
29  
30      AbstractTransactionContext getTransactionalResource(Xid xid)
31      {
32          AbstractTransactionContext context = getActiveTransactionalResource(xid);
33          if (context != null)
34          {
35              return context;
36          }
37          else
38          {
39              return getSuspendedTransactionalResource(xid);
40          }
41      }
42  
43      AbstractTransactionContext getActiveTransactionalResource(Xid xid)
44      {
45          return (AbstractTransactionContext) activeContexts.get(xid);
46      }
47  
48      AbstractTransactionContext getSuspendedTransactionalResource(Xid xid)
49      {
50          return (AbstractTransactionContext) suspendedContexts.get(xid);
51      }
52  
53      void addActiveTransactionalResource(Xid xid, AbstractTransactionContext context)
54      {
55          activeContexts.put(xid, context);
56      }
57  
58      void addSuspendedTransactionalResource(Xid xid, AbstractTransactionContext context)
59      {
60          suspendedContexts.put(xid, context);
61      }
62  
63      void removeActiveTransactionalResource(Xid xid)
64      {
65          activeContexts.remove(xid);
66      }
67  
68      void removeSuspendedTransactionalResource(Xid xid)
69      {
70          suspendedContexts.remove(xid);
71      }
72  
73  }