KickJava   Java API By Example, From Geeks To Geeks.

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


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.CCMHomeLocal;
30 import org.omg.Components.CCMObject ;
31 import org.omg.CosTransactions.Coordinator ;
32
33 /**
34  * Transaction implementation for the
35  * ::plugins::transaction::deployment::CCMHomeResource interface.
36  *
37  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
38  *
39  * @version 0.3
40  */

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

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

58   protected Coordinator the_coordinator_;
59   
60   /**
61    * Reference to the resource manager
62    *
63    */

64   protected CCMHomeListenerTransaction 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 objects
74    */

75   protected org.objectweb.ccm.util.Vector objects_;
76   
77
78   // ==================================================================
79
//
80
// Constructor.
81
//
82
// ==================================================================
83

84   /**
85    ** The constructor.
86    **
87    ** @param home reference to the home
88    ** @param coordinator reference to the current coordinator
89    ** @param resource reference to the ResourceManager of the current transaction
90    **
91    **/

92   public
93   CCMHomeResourceImpl(CCMHomeListenerTransaction listener,
94                       CCMHomeLocal home,
95                       Coordinator coordinator,
96                       ResourceManagerLocal manager)
97   {
98     the_home_ = home;
99     objects_ = new org.objectweb.ccm.util.Vector ();
100     register(listener, coordinator, manager);
101   }
102   
103   // ==================================================================
104
//
105
// Internal methods.
106
//
107
// ==================================================================
108
protected void
109   register(CCMHomeListenerTransaction listener,
110            Coordinator coordinator,
111            ResourceManagerLocal resource_manager)
112   {
113     the_listener_ = listener;
114     the_coordinator_ = coordinator;
115     the_resource_manager_ = resource_manager;
116     
117     the_listener_.add_resource(this);
118     the_resource_manager_.add_home(this);
119   }
120   
121   
122   protected void
123   unregister( )
124   {
125     try {
126       the_coordinator_ = null ;
127       the_listener_.remove_resource(this);
128       the_resource_manager_.remove_home (this);
129     } catch ( org.omg.Components.RemoveFailure ex ) { }
130   }
131   
132   
133   /**
134    * apply the modification to the associated home
135    *
136    */

137   protected void
138   commit_add ()
139   {
140     for (int i = 0; i < objects_.size(); i++) {
141       CCMObject obj_ref = (CCMObject) objects_.elementAt(i) ;
142       //the_home_.add_object (obj_ref);
143
}
144   }
145   
146   /**
147    * Deactivate the current resource
148    *
149    */

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

162   // ==================================================================
163
//
164
// Methods for the ::plugins::deployment::CCMHomeEvents interface.
165
//
166
// ==================================================================
167
//
168
// IDL:omg.org/Deployment/listener/CCMHomeEvents/on_create:1.0
169
//
170
/**
171    * Event sent after the create function is called on CCMHome object
172    *
173    * @param ref the object created
174    */

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

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

202   public void
203   on_remove (CCMObject ref)
204   {
205   }
206   
207   //
208
// IDL:omg.org/Deployment/listener/CCMHomeEvents/on_destroy:1.0
209
//
210
/**
211    * Event sent before the destruction of the related CCMHome object
212    *
213    */

214   public void
215   on_destroy ()
216   {
217   }
218   
219   // ==================================================================
220
//
221
// Methods for the CosTransactions::Resource interface.
222
//
223
// ==================================================================
224
//
225
// IDL:omg.org/CosTransaction/Resource/prepare:1.0
226
//
227
/**
228    * prepare the commit phase : first part of the 2-commit phase
229    *
230    * @return a vote determining the strategy to apply (Commit, Rollback or Read-Only)
231    *
232    */

233   public org.omg.CosTransactions.Vote
234   prepare()
235     throws org.omg.CosTransactions.HeuristicMixed,
236     org.omg.CosTransactions.HeuristicHazard
237   {
238     return org.omg.CosTransactions.Vote.VoteCommit;
239   }
240   
241   //
242
// IDL:omg.org/CosTransaction/Resource/rollback:1.0
243
//
244
/**
245    * rollback the transaction started : second part of the 2-commit-phase
246    *
247    */

248   public void
249   rollback()
250     throws org.omg.CosTransactions.HeuristicCommit,
251     org.omg.CosTransactions.HeuristicMixed,
252     org.omg.CosTransactions.HeuristicHazard
253   {
254     for (int i = 0; i < objects_.size(); i++) {
255       CCMObject obj_ref = (CCMObject) objects_.elementAt(i) ;
256       try {
257         obj_ref.remove();
258       } catch (org.omg.Components.RemoveFailure ex) { }
259     }
260     removeItself();
261   }
262   
263   //
264
// IDL:omg.org/CosTransaction/Resource/commit:1.0
265
//
266
/**
267    * Commit the the transaction started : second part of the 2-commit-phase
268    *
269    */

270   public void
271   commit()
272     throws org.omg.CosTransactions.NotPrepared,
273     org.omg.CosTransactions.HeuristicRollback,
274     org.omg.CosTransactions.HeuristicMixed,
275     org.omg.CosTransactions.HeuristicHazard
276   {
277     commit_add();
278     removeItself();
279   }
280   
281   
282   //
283
// IDL:omg.org/CosTransaction/Resource/commit_one_phase:1.0
284
//
285
/**
286    * Commit the the transaction started : 1-commit phase
287    *
288    */

289   public void
290   commit_one_phase()
291     throws org.omg.CosTransactions.HeuristicHazard
292   {
293     commit_add();
294     removeItself();
295   }
296   
297   
298   //
299
// IDL:omg.org/CosTransaction/Resource/forget:1.0
300
//
301
/**
302    * Cancel the transaction started
303    *
304    */

305   public void
306   forget()
307   {
308     removeItself();
309   }
310   
311   
312   // ==================================================================
313
//
314
// Methods for the ::plugins::deployment::transaction::CCMHomeResource interface.
315
//
316
// ==================================================================
317
//
318
// IDL:omg.org/Deployment/listener/transaction/CCMHomeResource/get_home:1.0
319
//
320
/**
321    * provide the reference of the associated home
322    *
323    * @return reference to the home
324    *
325    */

326   public org.objectweb.openccm.Deployment.CCMHomeLocal
327   get_home()
328   {
329     return the_home_;
330   }
331   
332   // ==================================================================
333
//
334
// Methods for the ::plugins::deployment::transaction::CosCoordinator interface.
335
//
336
// ==================================================================
337
//
338
// IDL:omg.org/Deployment/listener/transaction/CCMHomeResource/coordinator:1.0
339
//
340
/**
341    * Provide a reference to the coordinator of the associated transaction
342    *
343    * @return specific coordinator
344    */

345   public Coordinator
346   coordinator()
347   {
348     return the_coordinator_;
349   }
350 }
351
352
353
354
355
Popular Tags