KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.openccm.plugins.transaction.deployment.util.*;
30 import org.omg.CosTransactions.Coordinator ;
31
32 /**
33  * This class implements the OMG IDL
34  * ::plugins::deployment::transaction::ResourceManager interface.
35  *
36  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
37  *
38  * @version 0.3
39  */

40 public class ResourceManagerImpl
41 extends ResourceManagerPOA
42 implements ResourceManagerLocal
43 {
44   // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49
/**
50    * number of resources list available
51    */

52   protected static int resources_count_=3;
53   
54   /**
55    * array of list of Resources available
56    *
57    * index 0 : home resources
58    * index 1 : container resources
59    * index 2 : component server resources
60    */

61   protected ResourceVector[] resources_;
62   
63   /**
64    * reference to the transaction manager
65    */

66   protected TransactionManagerLocal OTSManager_;
67
68   /**
69    * reference to the transaction coordinator
70    */

71   protected Coordinator coordinator_;
72   
73   // ==================================================================
74
//
75
// Constructor.
76
//
77
// ==================================================================
78
/**
79    * Constructor with parameters
80    *
81    * @param coordinator the transaction coordinator
82    * @param manager the transaction manager
83    */

84   public
85   ResourceManagerImpl (Coordinator coordinator,
86                        TransactionManagerLocal manager)
87   {
88     coordinator_ = coordinator;
89     OTSManager_ = manager;
90     resources_ = new ResourceVector[resources_count_];
91     for (int i=0 ; i < resources_count_ ; i++)
92       resources_[i] = new ResourceVector();
93   }
94   
95   // ==================================================================
96
//
97
// Internal methods.
98
//
99
// ==================================================================
100
/**
101    * Apply a specific treatment on each list
102    *
103    * @param action action to execute
104    *
105    */

106   protected void
107   apply(ResourceTreatment action)
108     throws Exception JavaDoc
109   {
110     for (int i=1 ; i<=resources_count_ ; i++)
111       resources_[resources_count_-i].apply(action);
112   }
113   
114   /**
115    * Apply a specific treatment on each list
116    *
117    * @param action action to execute
118    *
119    */

120   protected void
121   reverse_apply(ResourceTreatment action)
122     throws Exception JavaDoc
123   {
124     for (int i=0 ; i < resources_count_ ; i++)
125       resources_[i].apply(action);
126   }
127     
128   /**
129    * Desactivate the current resource
130    *
131    */

132   protected void
133   removeItself()
134   {
135     try {
136       OTSManager_.remove_manager (this);
137     } catch ( org.omg.Components.RemoveFailure ex ){ }
138     try {
139       _poa().deactivate_object( _poa().servant_to_id( this ) );
140     } catch ( org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc ex ){
141     } catch ( org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc ex ) {
142     } catch ( org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc ex ) {
143     }
144   }
145   
146   // ==================================================================
147
//
148
// Public methods.
149
//
150
// ==================================================================
151

152   // ==================================================================
153
//
154
// Methods for the ResourceManagerLocal interface.
155
//
156
// ==================================================================
157
//
158
// JAVA:ResourceManagerLocal/add_component_server
159
//
160
/**
161    * Add a new Component Server Resource in the Resource Manager
162    *
163    * @param ref reference of the ComponentServerResource to register
164    *
165    */

166   public void
167   add_component_server (ComponentServerResource ref)
168   {
169     resources_[2].addElement (ref);
170   }
171   
172   //
173
// JAVA:ResourceManagerLocal/add_container
174
//
175
/**
176    * Add a new Container Resource in the Resource Manager
177    *
178    * @param ref reference of the ComponentServerResource to register
179    *
180    */

181   public void
182   add_container (ContainerResource ref)
183   {
184     resources_[1].addElement (ref);
185   }
186   
187   //
188
// JAVA:ResourceManagerLocal/add_home
189
//
190
/**
191    * Add a new Home Resource in the Resource Manager
192    *
193    * @param ref reference of the ComponentServerResource to register
194    *
195    */

196   public void
197   add_home (CCMHomeResource ref)
198   {
199     resources_[0].addElement (ref);
200   }
201   
202   //
203
// JAVA:ResourceManagerLocal/remove_component_server
204
//
205
/**
206    * Remove a Component Server Resource from the Resource Manager
207    *
208    * @param ref reference of the ComponentServerResource to remove
209    *
210    */

211   public void
212   remove_component_server(ComponentServerResource ref)
213     throws org.omg.Components.RemoveFailure
214   {
215     resources_[2].removeElement (ref);
216   }
217   
218   //
219
// JAVA:ResourceManagerLocal/remove_container
220
//
221
/**
222    * Remove a new Container Resource in the Resource Manager
223    *
224    * @param ref reference of the ComponentServerResource to register
225    *
226    */

227   public void
228   remove_container (ContainerResource ref)
229     throws org.omg.Components.RemoveFailure
230   {
231     resources_[1].removeElement (ref);
232   }
233   
234   //
235
// JAVA:ResourceManagerLocal/remove_home
236
//
237
/**
238    * Remove a new Home Resource in the Resource Manager
239    *
240    * @param ref reference of the ComponentServerResource to register
241    *
242    */

243   public void
244   remove_home (CCMHomeResource ref)
245     throws org.omg.Components.RemoveFailure
246   {
247     resources_[0].removeElement (ref);
248   }
249   
250   // ==================================================================
251
//
252
// Methods for the CosTransactions::Resource interface.
253
//
254
// ==================================================================
255
//
256
// IDL:omg.org/CosTransaction/Resource/prepare:1.0
257
//
258
/**
259    * Vote request preparing the commit phase
260    *
261    * @return the vote for the resource
262    */

263   public org.omg.CosTransactions.Vote
264   prepare()
265     throws org.omg.CosTransactions.HeuristicMixed,
266     org.omg.CosTransactions.HeuristicHazard
267   {
268     try {
269       ResourcePrepare _vote = new ResourcePrepare();
270       apply(_vote);
271       return _vote.final_vote();
272     } catch (Exception JavaDoc ex) {
273       return org.omg.CosTransactions.Vote.VoteRollback;
274     }
275   }
276   
277   //
278
// IDL:omg.org/CosTransaction/Resource/rollback:1.0
279
//
280
/**
281    * Rollback all operations registered by the resource
282    *
283    */

284   public void
285   rollback()
286     throws org.omg.CosTransactions.HeuristicCommit,
287     org.omg.CosTransactions.HeuristicMixed,
288     org.omg.CosTransactions.HeuristicHazard
289   {
290     try
291     {
292       reverse_apply(new ResourceRollback());
293     } catch (org.omg.CosTransactions.HeuristicCommit ex) {
294       throw ex;
295     } catch (org.omg.CosTransactions.HeuristicMixed ex) {
296       throw ex;
297     } catch (org.omg.CosTransactions.HeuristicHazard ex) {
298       throw ex;
299     } catch (Exception JavaDoc ex) { }
300     removeItself();
301   }
302   
303   //
304
// IDL:omg.org/CosTransaction/Resource/commit:1.0
305
//
306
/**
307    * Commit all operations registered by the resource
308    *
309    */

310   public void
311   commit()
312     throws org.omg.CosTransactions.NotPrepared,
313     org.omg.CosTransactions.HeuristicRollback,
314     org.omg.CosTransactions.HeuristicMixed,
315     org.omg.CosTransactions.HeuristicHazard
316   {
317     try {
318       apply(new ResourceCommit());
319     } catch (org.omg.CosTransactions.NotPrepared ex) {
320       throw ex;
321     } catch (org.omg.CosTransactions.HeuristicRollback ex) {
322       throw ex;
323     } catch (org.omg.CosTransactions.HeuristicMixed ex) {
324       throw ex;
325     } catch (org.omg.CosTransactions.HeuristicHazard ex) {
326       throw ex;
327     } catch (Exception JavaDoc ex) { }
328     removeItself();
329   }
330   
331   //
332
// IDL:omg.org/CosTransaction/Resource/commit_one_phase:1.0
333
//
334
/**
335    * One phase commit of all operations registered by the resource
336    *
337    */

338   public void
339   commit_one_phase()
340     throws org.omg.CosTransactions.HeuristicHazard
341   {
342     try {
343       apply(new ResourceCommitOnePhase());
344     } catch(org.omg.CosTransactions.HeuristicHazard ex) {
345       throw ex;
346     } catch (Exception JavaDoc ex) { }
347     removeItself();
348   }
349   
350   //
351
// IDL:omg.org/CosTransaction/Resource/forget:1.0
352
//
353
/**
354    * Delete the current resource from the resource manager
355    *
356    */

357   public void
358   forget()
359   {
360     removeItself();
361   }
362   
363   // ==================================================================
364
//
365
// Methods for the ::plugins::deployment::transaction::CosCoordinator interface.
366
//
367
// ==================================================================
368
//
369
// IDL:omg.org/plugins/deployment/transaction/ResourceManager/coordinator:1.0
370
//
371
//
372
// JAVA:ResourceManagerLocal/coordinator
373
//
374
/**
375    * Provide the reference of the transaction coordinator
376    *
377    * @return reference on the coordinator
378    */

379   public Coordinator
380   coordinator()
381   {
382     return coordinator_;
383   }
384 }
385
386
Popular Tags