KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

58   protected Coordinator the_coordinator_;
59   
60   /**
61    * Reference on the listener
62    */

63   protected ComponentServerListenerTransaction the_listener_;
64    
65   /**
66    * Reference to the resource manager
67    */

68   protected ResourceManagerLocal the_resource_manager_;
69   
70   /**
71    * The list of the sub resources
72    */

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

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

134   protected void
135   commit_add ()
136   {
137     for (int i=0 ; i<containers_.size() ; i++) {
138       Container cont_ref = (Container) containers_.elementAt(i);
139       the_component_server_.add_container (cont_ref);
140     }
141   }
142   
143   /**
144    * Desactivate the current resource
145    *
146    */

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

159   // ==================================================================
160
//
161
// Methods for the ::plugins::deployment::ComponentServerEvents interface.
162
//
163
// ==================================================================
164
//
165
// IDL:omg.org/plugins/deployment/ComponentServerEvents/on_create:1.0
166
//
167
/**
168    * Event sent after the create function is called on ComponentServer object
169    *
170    * @param ref the object created
171    */

172   public void
173   on_create (Container cont_ref)
174   {
175     containers_.addElement (cont_ref);
176   }
177   
178   //
179
// IDL:omg.org/plugins/deployment/ComponentServerEvents/on_add:1.0
180
//
181
/**
182    * Event sent after the add function is called on ComponentServer object
183    *
184    * @param ref the object added
185    */

186   public void
187   on_add (Container cont_ref) {}
188   
189   //
190
// IDL:omg.org/plugins/deployment/ComponentServerEvents/on_remove:1.0
191
//
192
/**
193    * Event sent before the remove function is called on ComponentServer object
194    *
195    * @param ref the object removed
196    */

197   public void
198   on_remove (Container cont_ref) {}
199   
200   //
201
// IDL:omg.org/plugins/deployment/ComponentServerEvents/on_destroy:1.0
202
//
203
/**
204    * Event sent before the destruction of the related ComponentServer object
205    *
206    */

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

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

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

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

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

293   public void
294   forget()
295   {
296     removeItself();
297   }
298   
299   // ==================================================================
300
//
301
// Methods for the ::plugins::deployment::transaction::ComponentServerResource interface.
302
//
303
// ==================================================================
304
//
305
// IDL:omg.org/plugins/deployment/transaction/ComponentServerResource/get_component_server:1.0
306
//
307
/**
308    * Provide the reference of the related component server
309    *
310    * @return reference to the component server
311    */

312   public org.objectweb.openccm.Deployment.ComponentServerLocal
313   get_component_server ()
314   {
315     return the_component_server_;
316   }
317   
318   // //
319
// // IDL:omg.org/plugins/deployment/transaction/ComponentServerResource/remove_container_resource:1.0
320
// //
321
// /**
322
// * Unregister a sub resource from the component server resource
323
// *
324
// * @param resource the resource to unregister
325
// */
326
// public void
327
// remove_container_resource(ContainerResource resource)
328
// throws org.omg.Components.RemoveFailure
329
// {
330
// containers_.removeElement (resource);
331
// }
332

333   // ==================================================================
334
//
335
// Methods for the ::plugins::deployment::transaction::CosCoordinator interface.
336
//
337
// ==================================================================
338
//
339
// IDL:omg.org/plugins/deployment/transaction/ComponentServerResource/coordinator:1.0
340
//
341
/**
342    * Provide the reference of the transaction coordinator
343    *
344    * @return reference on the coordinator
345    */

346   public Coordinator
347   coordinator()
348   {
349     return the_coordinator_;
350   }
351 }
352
353
354
355
356
357
358
359
360
361
362
Popular Tags