View Javadoc

1   /*
2    * $Id: AbstractXAResourceManager.java 8077 2007-08-27 20:15:25Z aperepel $
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  public abstract class AbstractXAResourceManager extends AbstractResourceManager
19  {
20  
21      protected Map suspendedContexts = new HashMap();
22      protected Map activeContexts = new HashMap();
23  
24      public AbstractXAResourceManager()
25      {
26          super();
27      }
28  
29      protected boolean includeBranchInXid()
30      {
31          return true;
32      }
33  
34      AbstractTransactionContext getTransactionalResource(Xid xid)
35      {
36          AbstractTransactionContext context = getActiveTransactionalResource(xid);
37          if (context != null)
38          {
39              return context;
40          }
41          else
42          {
43              return getSuspendedTransactionalResource(xid);
44          }
45      }
46  
47      AbstractTransactionContext getActiveTransactionalResource(Xid xid)
48      {
49          return (AbstractTransactionContext) activeContexts.get(xid);
50      }
51  
52      AbstractTransactionContext getSuspendedTransactionalResource(Xid xid)
53      {
54          return (AbstractTransactionContext) suspendedContexts.get(xid);
55      }
56  
57      void addActiveTransactionalResource(Xid xid, AbstractTransactionContext context)
58      {
59          activeContexts.put(xid, context);
60      }
61  
62      void addSuspendedTransactionalResource(Xid xid, AbstractTransactionContext context)
63      {
64          suspendedContexts.put(xid, context);
65      }
66  
67      void removeActiveTransactionalResource(Xid xid)
68      {
69          activeContexts.remove(xid);
70      }
71  
72      void removeSuspendedTransactionalResource(Xid xid)
73      {
74          suspendedContexts.remove(xid);
75      }
76  
77  }