View Javadoc

1   /*
2    * $Id: AbstractXAResourceManager.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.util.xa;
12  
13  import java.util.HashMap;
14  import java.util.Map;
15  
16  import javax.transaction.xa.Xid;
17  
18  /**
19   * @author <a href="mailto:gnt@codehaus.org">Guillaume Nodet</a>
20   * @version $Revision: 7976 $
21   */
22  public abstract class AbstractXAResourceManager extends AbstractResourceManager
23  {
24  
25      protected Map suspendedContexts = new HashMap();
26      protected Map activeContexts = new HashMap();
27  
28      public AbstractXAResourceManager()
29      {
30          super();
31      }
32  
33      protected boolean includeBranchInXid()
34      {
35          return true;
36      }
37  
38      AbstractTransactionContext getTransactionalResource(Xid xid)
39      {
40          AbstractTransactionContext context = getActiveTransactionalResource(xid);
41          if (context != null)
42          {
43              return context;
44          }
45          else
46          {
47              return getSuspendedTransactionalResource(xid);
48          }
49      }
50  
51      AbstractTransactionContext getActiveTransactionalResource(Xid xid)
52      {
53          return (AbstractTransactionContext) activeContexts.get(xid);
54      }
55  
56      AbstractTransactionContext getSuspendedTransactionalResource(Xid xid)
57      {
58          return (AbstractTransactionContext) suspendedContexts.get(xid);
59      }
60  
61      void addActiveTransactionalResource(Xid xid, AbstractTransactionContext context)
62      {
63          activeContexts.put(xid, context);
64      }
65  
66      void addSuspendedTransactionalResource(Xid xid, AbstractTransactionContext context)
67      {
68          suspendedContexts.put(xid, context);
69      }
70  
71      void removeActiveTransactionalResource(Xid xid)
72      {
73          activeContexts.remove(xid);
74      }
75  
76      void removeSuspendedTransactionalResource(Xid xid)
77      {
78          suspendedContexts.remove(xid);
79      }
80  
81  }