KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > plugins > transaction > deployment > TransactionManagerImpl


1 /*================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Romain Rouvoy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.plugins.transaction.deployment;
28
29
30 /**
31  * This class implements
32  * ::plugins::deployment::transaction::TransactionManagerLocal
33  *
34  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
35  *
36  * @version 0.3
37  */

38 public class TransactionManagerImpl
39 implements TransactionManagerLocal
40 {
41   // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46
/**
47    * List of the transactions started
48    *
49    */

50   protected org.objectweb.ccm.util.Vector transactions_;
51   
52   // ==================================================================
53
//
54
// Constructor.
55
//
56
// ==================================================================
57
/**
58    * Default Constructor
59    *
60    */

61   public
62   TransactionManagerImpl()
63   {
64     transactions_ = new org.objectweb.ccm.util.Vector ();
65   }
66   
67   
68   // ==================================================================
69
//
70
// Internal methods.
71
//
72
// ==================================================================
73
/**
74    * Create a new resource manager
75    */

76   protected ResourceManagerLocal
77   create_manager (org.omg.CosTransactions.Coordinator coordinator)
78   {
79     try {
80       ResourceManagerImpl _resource = new ResourceManagerImpl (coordinator, this);
81       transactions_.add (_resource);
82       ResourceManager _res_ref = _resource._this (org.objectweb.openccm.corba.TheORB.getORB());
83       coordinator.register_resource( _res_ref );
84       
85       return _resource;
86     } catch (org.omg.CosTransactions.Inactive ex) { }
87     return null;
88   }
89   
90   // ==================================================================
91
//
92
// Public methods.
93
//
94
// ==================================================================
95

96   // ==================================================================
97
//
98
// Methods for the TransactionManagerLocal interface.
99
//
100
// ==================================================================
101
//
102
// JAVA:TransactionManagerLocal/getCurrent
103
//
104
/**
105    * Provide the current resource manager
106    *
107    * @return instance of the current resource manager
108    */

109   public ResourceManagerLocal
110   getCurrent()
111   {
112     try {
113       org.omg.CORBA.Object JavaDoc _obj = org.objectweb.openccm.corba.TheORB.getORB()
114                                      .resolve_initial_references("TransactionCurrent");
115       org.omg.CosTransactions.Current _current =
116         org.omg.CosTransactions.CurrentHelper.narrow( _obj );
117       org.omg.CosTransactions.Control _control =
118         _current.get_control();
119       org.omg.CosTransactions.Coordinator _coordinator =
120         _control.get_coordinator();
121       
122       java.util.Iterator JavaDoc _iterator = transactions_.iterator();
123       
124       while (_iterator.hasNext()) {
125         ResourceManagerLocal _resource = (ResourceManagerLocal) _iterator.next ();
126         if ( _coordinator.is_same_transaction( _resource.coordinator() ) )
127           return _resource;
128       }
129       return create_manager (_coordinator);
130     } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc ex) {
131     } catch (org.omg.CosTransactions.Unavailable ex) {
132     }
133     return null;
134   }
135   
136   //
137
// JAVA:TransactionManagerLocal/remove_manager
138
//
139
/**
140    * Remove the resource manager from the transaction manager
141    *
142    * @param resource manager to remove
143    *
144    * @exception Components::RemoveFailure
145    */

146   public void
147   remove_manager(ResourceManagerLocal ref)
148     throws org.omg.Components.RemoveFailure
149   {
150     transactions_.remove (ref);
151   }
152 }
153
154
155
156
157
158
159
Popular Tags