001: package org.jacorb.concurrency;
002:
003: /*
004:
005: * JacORB concurrency control service - a free CCS for JacORB
006:
007: *
008:
009: * Copyright (C) 1999-2004 LogicLand group, Viacheslav Tararin.
010:
011: *
012:
013: * This library is free software; you can redistribute it and/or
014:
015: * modify it under the terms of the GNU Library General Public
016:
017: * License as published by the Free Software Foundation; either
018:
019: * version 2 of the License, or (at your option) any later version.
020:
021: *
022:
023: * This library is distributed in the hope that it will be useful,
024:
025: * but WITHOUT ANY WARRANTY; without even the implied warranty of
026:
027: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
028:
029: * Library General Public License for more details.
030:
031: *
032:
033: * You should have received a copy of the GNU Library General Public
034:
035: * License along with this library; if not, write to the Free
036:
037: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
038:
039: */
040:
041: import org.omg.CosConcurrencyControl.*;
042:
043: import org.omg.CosTransactions.*;
044:
045: import org.omg.PortableServer.POA;
046:
047: import java.util.*;
048:
049: public class LockSetFactoryImpl extends LockSetFactoryPOA {
050:
051: public static final int REQUEST = 1;
052:
053: public static final int SATISFIED = 2;
054:
055: public static final int COMMIT = 3;
056:
057: public static final int ROLLBACK = 4;
058:
059: public static final int NO_TRANS = 5;
060:
061: public static final int REJECT = 6;
062:
063: /* -------------------------------------------------------------------------- */
064:
065: private Hashtable coordinators = new Hashtable();
066:
067: private POA poa;
068:
069: /* -------------------------------------------------------------------------- */
070:
071: public LockSetFactoryImpl(POA poa) {
072:
073: this .poa = poa;
074:
075: };
076:
077: /* -------------------------------------------------------------------------- */
078:
079: public LockSet create() {
080:
081: throw new org.omg.CORBA.NO_IMPLEMENT();
082:
083: };
084:
085: /* -------------------------------------------------------------------------- */
086:
087: public LockSet create_related(LockSet which) {
088:
089: throw new org.omg.CORBA.NO_IMPLEMENT();
090:
091: };
092:
093: /* -------------------------------------------------------------------------- */
094:
095: public TransactionalLockSet create_transactional() {
096:
097: TransactionalLockSetImpl ls = new TransactionalLockSetImpl(this );
098:
099: try {
100:
101: return TransactionalLockSetHelper.narrow(poa
102: .servant_to_reference(ls));
103:
104: } catch (Exception e) {
105:
106: e.printStackTrace(System.out);
107:
108: throw new org.omg.CORBA.INTERNAL();
109:
110: }
111:
112: };
113:
114: /* -------------------------------------------------------------------------- */
115:
116: public TransactionalLockSet create_transactional_related(
117: TransactionalLockSet which) {
118:
119: TransactionalLockSetImpl ls = new TransactionalLockSetImpl(this );
120:
121: ls.add_related(which);
122:
123: try {
124:
125: return TransactionalLockSetHelper.narrow(poa
126: .servant_to_reference(ls));
127:
128: } catch (Exception e) {
129:
130: e.printStackTrace(System.out);
131:
132: throw new org.omg.CORBA.INTERNAL();
133:
134: }
135:
136: };
137:
138: /* -------------------------------------------------------------------------- */
139:
140: synchronized TransactionCoordinator get_transaction_coordinator(
141: Coordinator current)
142:
143: {
144:
145: if (coordinators.containsKey(current.get_transaction_name()))
146:
147: {
148:
149: return (TransactionCoordinator) coordinators.get(current
150: .get_transaction_name());
151:
152: }
153:
154: TransactionCoordinator coordinator = new TransactionCoordinator(
155: this , current, poa);
156:
157: try
158:
159: {
160:
161: Resource res = ResourceHelper.narrow(poa
162: .servant_to_reference(coordinator));
163:
164: current.register_resource(res);
165:
166: }
167:
168: catch (Exception e)
169:
170: {
171:
172: e.printStackTrace(System.out);
173:
174: }
175:
176: coordinators.put(current.get_transaction_name(), coordinator);
177:
178: return coordinator;
179:
180: };
181:
182: /* -------------------------------------------------------------------------- */
183:
184: synchronized void remove_me(TransactionCoordinator i_am) {
185:
186: coordinators.remove(i_am.get_coordinator());
187:
188: try {
189:
190: byte[] ObjId = poa.servant_to_id(i_am);
191:
192: poa.deactivate_object(ObjId);
193:
194: } catch (Exception e) {
195:
196: e.printStackTrace(System.out);
197:
198: throw new org.omg.CORBA.INTERNAL();
199:
200: }
201:
202: }
203:
204: /* -------------------------------------------------------------------------- */
205:
206: synchronized void remove_me(TransactionalLockSetImpl i_am) {
207:
208: Enumeration enumeration = coordinators.elements();
209:
210: while (enumeration.hasMoreElements()) {
211:
212: TransactionCoordinator tc = (TransactionCoordinator) enumeration
213: .nextElement();
214:
215: tc.remove_coordinator(i_am);
216:
217: }
218:
219: try {
220:
221: byte[] ObjId = poa.servant_to_id(i_am);
222:
223: poa.deactivate_object(ObjId);
224:
225: } catch (Exception e) {
226:
227: e.printStackTrace(System.out);
228:
229: throw new org.omg.CORBA.INTERNAL();
230:
231: }
232:
233: };
234:
235: };
|