KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > concurrency > LockSetFactoryImpl


1 package org.jacorb.concurrency;
2
3
4
5 /*
6
7  * JacORB concurrency control service - a free CCS for JacORB
8
9  *
10
11  * Copyright (C) 1999-2004 LogicLand group, Viacheslav Tararin.
12
13  *
14
15  * This library is free software; you can redistribute it and/or
16
17  * modify it under the terms of the GNU Library General Public
18
19  * License as published by the Free Software Foundation; either
20
21  * version 2 of the License, or (at your option) any later version.
22
23  *
24
25  * This library is distributed in the hope that it will be useful,
26
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30
31  * Library General Public License for more details.
32
33  *
34
35  * You should have received a copy of the GNU Library General Public
36
37  * License along with this library; if not, write to the Free
38
39  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40
41  */

42
43
44
45 import org.omg.CosConcurrencyControl.*;
46
47 import org.omg.CosTransactions.*;
48
49 import org.omg.PortableServer.POA JavaDoc;
50
51 import java.util.*;
52
53
54 public class LockSetFactoryImpl extends LockSetFactoryPOA {
55
56     public static final int REQUEST = 1;
57
58     public static final int SATISFIED = 2;
59
60     public static final int COMMIT = 3;
61
62     public static final int ROLLBACK = 4;
63
64     public static final int NO_TRANS = 5;
65
66     public static final int REJECT = 6;
67
68
69
70 /* -------------------------------------------------------------------------- */
71
72     private Hashtable coordinators = new Hashtable();
73
74     private POA JavaDoc poa;
75
76 /* -------------------------------------------------------------------------- */
77
78     public LockSetFactoryImpl( POA JavaDoc poa ){
79
80         this.poa = poa;
81
82     };
83
84 /* -------------------------------------------------------------------------- */
85
86
87
88     public LockSet create(){
89
90         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
91
92     };
93
94 /* -------------------------------------------------------------------------- */
95
96     public LockSet create_related(LockSet which){
97
98         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
99
100     };
101
102 /* -------------------------------------------------------------------------- */
103
104     public TransactionalLockSet create_transactional(){
105
106         TransactionalLockSetImpl ls = new TransactionalLockSetImpl( this );
107
108         try {
109
110             return TransactionalLockSetHelper.narrow( poa.servant_to_reference( ls ) );
111
112         } catch ( Exception JavaDoc e ){
113
114             e.printStackTrace( System.out );
115
116             throw new org.omg.CORBA.INTERNAL JavaDoc();
117
118         }
119
120     };
121
122 /* -------------------------------------------------------------------------- */
123
124     public TransactionalLockSet create_transactional_related(TransactionalLockSet which){
125
126         TransactionalLockSetImpl ls = new TransactionalLockSetImpl( this );
127
128         ls.add_related( which );
129
130         try {
131
132             return TransactionalLockSetHelper.narrow( poa.servant_to_reference( ls ) );
133
134         } catch ( Exception JavaDoc e ){
135
136             e.printStackTrace( System.out );
137
138             throw new org.omg.CORBA.INTERNAL JavaDoc();
139
140         }
141
142     };
143
144 /* -------------------------------------------------------------------------- */
145
146     synchronized TransactionCoordinator get_transaction_coordinator( Coordinator current ){
147
148         if( coordinators.containsKey( current.get_transaction_name() ) ){
149
150             return (TransactionCoordinator)coordinators.get( current.get_transaction_name() );
151
152         } else {
153
154             TransactionCoordinator c = new TransactionCoordinator( this, current, poa );
155
156             try {
157
158                Resource res = ResourceHelper.narrow( poa.servant_to_reference( c ) );
159
160                current.register_resource( res );
161
162             } catch ( Exception JavaDoc e ){
163
164                 e.printStackTrace( System.out );
165
166             }
167
168             coordinators.put( current.get_transaction_name(), c );
169
170             return c;
171
172         }
173
174
175
176     };
177
178 /* -------------------------------------------------------------------------- */
179
180     synchronized void remove_me( TransactionCoordinator i_am ){
181
182         coordinators.remove( i_am.get_coordinator() );
183
184         try {
185
186             byte [] ObjId = poa.servant_to_id( i_am );
187
188             poa.deactivate_object( ObjId );
189
190         } catch ( Exception JavaDoc e ){
191
192             e.printStackTrace( System.out );
193
194             throw new org.omg.CORBA.INTERNAL JavaDoc();
195
196         }
197
198     }
199
200 /* -------------------------------------------------------------------------- */
201
202     synchronized void remove_me( TransactionalLockSetImpl i_am ){
203
204         Enumeration enumeration = coordinators.elements();
205
206         while( enumeration.hasMoreElements() ){
207
208             TransactionCoordinator tc = (TransactionCoordinator)enumeration.nextElement();
209
210             tc.remove_coordinator( i_am );
211
212         }
213
214         try {
215
216             byte [] ObjId = poa.servant_to_id( i_am );
217
218             poa.deactivate_object( ObjId );
219
220         } catch ( Exception JavaDoc e ){
221
222             e.printStackTrace( System.out );
223
224             throw new org.omg.CORBA.INTERNAL JavaDoc();
225
226         }
227
228     };
229
230 };
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Popular Tags