KickJava   Java API By Example, From Geeks To Geeks.

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


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

41 public class ContainerResourceImpl
42 extends org.omg.CORBA.LocalObject JavaDoc
43 implements ContainerResource
44 {
45   // ==================================================================
46
//
47
// Internal state.
48
//
49
// ==================================================================
50
/**
51    * Reference on the related container
52    */

53   protected ContainerLocal the_container_;
54   
55   /**
56    * Reference on the coordinator of the current resource
57    */

58   protected Coordinator the_coordinator_;
59   
60   /**
61    * Reference to the associated listener
62    *
63    */

64   protected ContainerListenerTransaction the_listener_;
65   
66   /**
67    * Reference to the resource manager
68    *
69    */

70   protected ResourceManagerLocal the_resource_manager_;
71   
72   /**
73    * List of not committed homes
74    */

75   protected org.objectweb.ccm.util.Vector homes_;
76   
77   
78   // ==================================================================
79
//
80
// Constructor.
81
//
82
// ==================================================================
83
/**
84    * The constructor.
85    *
86    ** @param component_server reference to the component server
87    ** @param coordinator reference to the current coordinator
88    ** @param resource reference to the ResourceManager of the current transaction
89    */

90   public
91   ContainerResourceImpl (ContainerListenerTransaction listener,
92                          ContainerLocal container,
93                          Coordinator coordinator,
94                          ResourceManagerLocal resource_manager)
95   {
96     the_container_ = container ;
97     homes_ = new org.objectweb.ccm.util.Vector();
98     register(listener, coordinator, resource_manager);
99   }
100   
101   // ==================================================================
102
//
103
// Internal methods.
104
//
105
// ==================================================================
106
protected void
107   register(ContainerListenerTransaction listener,
108            Coordinator coordinator,
109            ResourceManagerLocal resource_manager)
110   {
111     the_listener_ = listener;
112     the_coordinator_ = coordinator;
113     the_resource_manager_ = resource_manager;
114     
115     the_listener_.add_resource(this);
116     the_resource_manager_.add_container(this);
117   }
118   
119   
120   protected void
121   unregister( )
122   {
123     try {
124       the_coordinator_ = null ;
125       the_listener_.remove_resource(this);
126       the_resource_manager_.remove_container (this);
127     } catch ( org.omg.Components.RemoveFailure ex ) { }
128   }
129   
130
131   
132   /**
133    * Add the list of current Container to the componentserver
134    *
135    */

136   protected void
137   commit_add ()
138   {
139     for (int i=0 ; i < homes_.size() ; i++) {
140       CCMHome home_ref = (CCMHome) homes_.elementAt(i) ;
141       the_container_.add_home (home_ref);
142     }
143   }
144   
145   /**
146    * Desactivate the current resource
147    *
148    */

149   protected void
150   removeItself()
151   {
152     unregister();
153   }
154   
155   // ==================================================================
156
//
157
// Public methods.
158
//
159
// ==================================================================
160

161   // ==================================================================
162
//
163
// Methods for the ::plugins::deployment::ContainerEvents interface.
164
//
165
// ==================================================================
166

167   //
168
// IDL:omg.org/plugins/deployment/ContainerEvents/on_create:1.0
169
//
170
/**
171    * Event sent after the create function is called on Container object
172    *
173    * @param ref the object created
174    */

175   public void
176   on_create (CCMHome ref)
177   {
178     homes_.addElement (ref);
179   }
180   
181   //
182
// IDL:omg.org/plugins/deployment/ContainerEvents/on_add:1.0
183
//
184
/**
185    * Event sent after the add function is called on Container object
186    *
187    * @param ref the object added
188    */

189   public void
190   on_add (CCMHome ref) { }
191   
192   //
193
// IDL:omg.org/plugins/deployment/ContainerEvents/on_remove:1.0
194
//
195
/**
196    * Event sent before the remove function is called on Container object
197    *
198    * @param ref the object removed
199    */

200   public void
201   on_remove (CCMHome ref) { }
202     
203   //
204
// IDL:omg.org/plugins/deployment/ContainerEvents/on_destroy:1.0
205
//
206
/**
207    * Event sent before the destruction of the related Container object
208    *
209    */

210   public void
211   on_destroy () { }
212
213   // ==================================================================
214
//
215
// Methods for the CosTransactions::Resource interface.
216
//
217
// ==================================================================
218
//
219
// IDL:omg.org/CosTransaction/Resource/prepare:1.0
220
//
221
/**
222    * Vote request preparing the commit phase
223    *
224    * @return the vote for the resource
225    */

226   public org.omg.CosTransactions.Vote
227   prepare()
228     throws org.omg.CosTransactions.HeuristicMixed,
229     org.omg.CosTransactions.HeuristicHazard
230   {
231     return org.omg.CosTransactions.Vote.VoteCommit;
232   }
233   
234   //
235
// IDL:omg.org/CosTransaction/Resource/rollback:1.0
236
//
237
/**
238    * Rollback all operations registered by the resource
239    *
240    */

241   public void
242   rollback()
243     throws org.omg.CosTransactions.HeuristicCommit,
244     org.omg.CosTransactions.HeuristicMixed,
245     org.omg.CosTransactions.HeuristicHazard
246   {
247     for (int i=0 ; i<homes_.size() ; i++) {
248       CCMHome home_ref = (CCMHome) homes_.elementAt(i) ;
249       try {
250         home_ref.remove_home();
251       } catch (org.omg.Components.RemoveFailure ex) { }
252     }
253     removeItself();
254   }
255   
256   //
257
// IDL:omg.org/CosTransaction/Resource/commit:1.0
258
//
259
/**
260    * Commit all operations registered by the resource
261    *
262    */

263   public void
264   commit()
265     throws org.omg.CosTransactions.NotPrepared,
266     org.omg.CosTransactions.HeuristicRollback,
267     org.omg.CosTransactions.HeuristicMixed,
268     org.omg.CosTransactions.HeuristicHazard
269   {
270     commit_add ();
271     removeItself();
272   }
273   
274   //
275
// IDL:omg.org/CosTransaction/Resource/commit_one_phase:1.0
276
//
277
/**
278    * One phase commit of all operations registered by the resource
279    *
280    */

281   public void
282   commit_one_phase()
283     throws org.omg.CosTransactions.HeuristicHazard
284   {
285     commit_add ();
286     removeItself();
287   }
288   
289   //
290
// IDL:omg.org/CosTransaction/Resource/forget:1.0
291
//
292
/**
293    * Delete the current resource from the resource manager
294    *
295    */

296   public void
297   forget()
298   {
299     removeItself();
300   }
301   
302   // ==================================================================
303
//
304
// Methods for the ::plugins::deployment::transaction::ContainerResource interface.
305
//
306
// ==================================================================
307
//
308
// IDL:omg.org/plugins/deployment/transaction/ContainerResource/get_container:1.0
309
//
310
/**
311    * Provide the reference of the related container
312    *
313    * @return reference to the container
314    */

315   public org.objectweb.openccm.Deployment.ContainerLocal
316   get_container ()
317   {
318     return the_container_;
319   }
320   
321   // ==================================================================
322
//
323
// Methods for the ::plugins::deployment::transaction::CosCoordinator interface.
324
//
325
// ==================================================================
326
//
327
// IDL:omg.org/plugins/deployment/transaction/ContainerResource/coordinator:1.0
328
//
329
/**
330    * Provide the reference of the transaction coordinator
331    *
332    * @return reference on the coordinator
333    */

334   public Coordinator
335     coordinator()
336   {
337     return the_coordinator_;
338   }
339 }
340
341
342
343
344
345
346
347
Popular Tags