KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > pi > InterceptorImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 package com.sun.jts.pi;
30
31 import java.lang.Object JavaDoc;
32 // IASRI 4698847 START
33
// import java.util.Stack;
34
import com.sun.enterprise.util.collection.ArrayListStack;
35 // IASRI 4698847 END
36

37 import org.omg.IOP.Codec JavaDoc;
38 import org.omg.IOP.ServiceContext JavaDoc;
39 import org.omg.IOP.TaggedComponent JavaDoc;
40 import org.omg.IOP.CodecPackage.*;
41
42 import com.sun.corba.ee.spi.presentation.rmi.StubAdapter;
43 import org.omg.CORBA.portable.InputStream JavaDoc;
44 import org.omg.PortableInterceptor.Current JavaDoc;
45
46 import org.omg.CORBA.*;
47 import org.omg.CosTransactions.*;
48 import org.omg.PortableInterceptor.*;
49
50 import org.omg.CosTSPortability.Sender;
51 import org.omg.CosTSPortability.Receiver;
52
53 import org.omg.CosTSInteroperation.TAG_OTS_POLICY;
54
55 import com.sun.jts.CosTransactions.CurrentTransaction;
56 import com.sun.corba.ee.impl.corba.EnvironmentImpl;
57 import com.sun.corba.ee.impl.txpoa.TSIdentificationImpl;
58  
59 import java.util.logging.Logger JavaDoc;
60 import java.util.logging.Level JavaDoc;
61 import com.sun.logging.LogDomains;
62
63 /**
64  * This is the implementation of the JTS PI-based client/server interceptor.
65  * This will be called during request/reply invocation path.
66  *
67  * @author Ram Jeyaraman 11/11/2000, $Author: sheetalv $
68  * @version 1.0, $Revision: 1.2.4.2 $ on $Date: 2006/03/31 21:20:36 $
69  */

70 public class InterceptorImpl extends org.omg.CORBA.LocalObject JavaDoc
71         implements ClientRequestInterceptor, ServerRequestInterceptor {
72
73     // class attributes
74

75     private static final String JavaDoc name = "com.sun.jts.pi.Interceptor";
76     private static final int TransactionServiceId = 0;
77     private static final SystemException SYS_EXC =
78         new SystemException("", 0, CompletionStatus.COMPLETED_MAYBE) {};
79
80     public static final int NO_REPLY_SLOT = 0;
81     public static final int NULL_CTX_SLOT = 1;
82
83     public static final Integer JavaDoc PROPER_CTX = new Integer JavaDoc(0);
84     public static final Integer JavaDoc NULL_CTX = new Integer JavaDoc(1);
85
86     public static final Integer JavaDoc REPLY = new Integer JavaDoc(0);
87     public static final Integer JavaDoc NO_REPLY = new Integer JavaDoc(1);
88
89     public static final String JavaDoc CLIENT_POLICY_CHECKING =
90         "com.sun.jts.pi.CLIENT_POLICY_CHECKING";
91     public static final String JavaDoc INTEROP_MODE = "com.sun.jts.pi.INTEROP_MODE";
92     
93     /*
94         Logger to log transaction messages
95     */

96      static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
97
98     public static ThreadLocal JavaDoc otsThreadLocal =
99         new ThreadLocal JavaDoc() {
100             protected java.lang.Object JavaDoc initialValue() {
101                 Object JavaDoc[] threadLocalState = new Object JavaDoc[2];
102                 // IASRI 4698847 START
103
//threadLocalState[NO_REPLY_SLOT] = new Stack();
104
//threadLocalState[NULL_CTX_SLOT] = new Stack();
105
threadLocalState[NO_REPLY_SLOT] = new ArrayListStack();
106                 threadLocalState[NULL_CTX_SLOT] = new ArrayListStack();
107                 // IASRI 4698847 END
108
return threadLocalState;
109             }
110         };
111
112     private static PropagationContext nullContext, dummyContext = null;
113
114     // static initializer block
115

116     static {
117         Any any = ORB.init().create_any();
118         any.insert_boolean(false);
119         nullContext = new PropagationContext(
120             0,
121             new TransIdentity(null, null, new otid_t(0, 0, new byte[0])),
122             new TransIdentity[0],
123             any);
124
125         any.insert_boolean(true);
126         dummyContext = new PropagationContext(
127             -1,
128             new TransIdentity(null, null, new otid_t(-1, 0, new byte[0])),
129             new TransIdentity[0],
130             any);
131     }
132
133     public static ORB txOrb = null;
134
135     // instance attributes
136

137     Current JavaDoc pic = null;
138     Codec JavaDoc codec = null;
139     int[] slotIds = null;
140     TSIdentification tsi = null;
141     TSIdentificationImpl tsiImpl = null;
142     Sender sender = null;
143     Receiver receiver = null;
144     private boolean checkPolicy = true;
145     private boolean interopMode = true;
146
147     // constructor
148

149     public InterceptorImpl(Current JavaDoc pic, Codec JavaDoc codec, int[] slotIds,
150             TSIdentification tsi) {
151         this.pic = pic;
152         this.codec = codec;
153         this.slotIds = slotIds;
154         this.tsi = tsi;
155         this.tsiImpl = (TSIdentificationImpl) tsi;
156         if (this.tsiImpl != null) {
157             this.sender = this.tsiImpl.getSender();
158             this.receiver = this.tsiImpl.getReceiver();
159         }
160
161         // check if client side checking is disabled. This allows client side
162
// policy checking to be disabled (for testing purposes).
163
String JavaDoc prop = System.getProperty(CLIENT_POLICY_CHECKING, "true");
164         this.checkPolicy = prop.equals("true");
165
166         // get the transaction interoperability mode.
167
prop = System.getProperty(INTEROP_MODE, "true");
168         this.interopMode = prop.equals("true");
169
170         if (_logger.isLoggable(Level.FINE))
171             _logger.log(Level.FINE, "Transaction INTEROP Mode: " + this.interopMode);
172
173     }
174
175     // proprietary hook for the J2EE RI. This is currently required since the
176
// RI does JTS initialization after the ORB.init() call.
177

178     public void setTSIdentification(TSIdentification tsi) {
179
180         if (tsi == null) {
181             return;
182         }
183
184         this.tsi = tsi;
185         this.tsiImpl = (TSIdentificationImpl) tsi;
186         this.sender = this.tsiImpl.getSender();
187         this.receiver = this.tsiImpl.getReceiver();
188     }
189
190     // implementation of the Interceptor interface.
191

192     public String JavaDoc name() {
193     return InterceptorImpl.name;
194     }
195
196     public void destroy() {}
197
198     // implementation of the ClientInterceptor interface.
199

200    public void send_request(ClientRequestInfo ri) throws ForwardRequest {
201
202         // do IOR policy checking.
203

204         TaggedComponent JavaDoc otsComp = null;
205         try {
206             otsComp = ri.get_effective_component(TAG_OTS_POLICY.value);
207         } catch (BAD_PARAM e) {
208             // ignore
209
}
210
211         short otsPolicyValue = -1;
212
213         if (otsComp == null) {
214             // in the case of J2EE RI, all published IORs must have an
215
// associated OTS policy component. The only exception being the
216
// location forwarded IORs returned by ORBD. Until a time, the ORBD
217
// is capable of transcribing the target POA policies into the
218
// location forwarded IOR, treat the absence of an OTS policy
219
// component as being equivalent to ADAPTS. Once the ORBD is
220
// able to support OTS policy components, the absence of an OTS
221
// policy component must be treated as FORBIDS.
222
otsPolicyValue = OTSPolicyImpl._ADAPTS.value();
223         } else {
224             TypeCode typeCode = ORB.init().get_primitive_tc(TCKind.tk_short);
225             Any any = null;
226             try {
227                 any = this.codec.decode_value(otsComp.component_data, typeCode);
228             } catch (TypeMismatch e) {
229                 throw new INTERNAL();
230             } catch (FormatMismatch e) {
231                 throw new INTERNAL();
232             }
233             otsPolicyValue = OTSPolicyValueHelper.extract(any);
234         }
235
236         // TransactionService is not available.
237

238         if (this.tsiImpl == null || this.sender == null) {
239             if (otsPolicyValue == REQUIRES.value && this.checkPolicy) {
240                 throw new TRANSACTION_UNAVAILABLE();
241             }
242             return;
243         }
244
245         // TransactionService is available.
246

247         /*
248         // Call JTS proprietary interceptor to see if there is a current tx.
249         PropagationContextHolder hctx = new PropagationContextHolder();
250         sender.sending_request(ri.request_id(), hctx);
251
252         if (hctx.value == null) { // no tx context
253             if (otsPolicyValue == REQUIRES.value && this.checkPolicy) {
254                 throw new TRANSACTION_REQUIRED();
255             }
256             return;
257         }
258         */

259
260         // Check to see if there is a current transaction.
261
boolean isTxAssociated = CurrentTransaction.isTxAssociated();
262         if (!isTxAssociated) { // no tx context
263
if (otsPolicyValue == REQUIRES.value && this.checkPolicy) {
264                 throw new TRANSACTION_REQUIRED();
265             }
266             return;
267         }
268
269         if (_logger.isLoggable(Level.FINE)) {
270             _logger.log(Level.FINE," sending_request["+ ri.request_id() +
271                     "] : " + ri.operation() + ", ThreadName : " +
272                 Thread.currentThread().toString());
273         }
274
275         // a current tx is available. Create service context.
276

277         if (otsPolicyValue == FORBIDS.value && this.checkPolicy) {
278             throw new INVALID_TRANSACTION();
279         }
280
281         PropagationContextHolder hctx = new PropagationContextHolder();
282
283         // if target object is co-located, no need to send tx context.
284
// This optimization uses a dummy context to flag the local case, so
285
// that the server receive point shall ignore the context (after doing
286
// appropriate policy checking). The net gain is that the activation of
287
// coordinator object is avoided.
288
// Note, this currently has issues with respect to checked behavior.
289
// Currently, checked behaviour is disabled and shall be reinstated
290
// once OTS RTF redrafts the OTS spec based on PI. An issue needs to be
291
// filed.
292
Object JavaDoc target = ri.effective_target();
293         if ( StubAdapter.isStub(target) && StubAdapter.isLocal(target) ) {
294             // target is local
295
// load a dummy context and discard the current tx context.
296
hctx.value = dummyContext;
297         } else if (this.interopMode == false) { // target is remote
298
// load a null context and discard the current tx context.
299
hctx.value = nullContext;
300         } else {
301             // Call JTS proprietary interceptor to get current tx.
302
sender.sending_request(ri.request_id(), hctx);
303         }
304
305         // add service context.
306

307         //Any any = ORB.init().create_any();
308
Any any = txOrb.create_any();
309         PropagationContextHelper.insert(any, hctx.value);
310         byte[] ctxData = null;
311         try {
312             ctxData = this.codec.encode_value(any);
313         } catch (InvalidTypeForEncoding e) {
314             throw new INTERNAL();
315         }
316
317         ServiceContext JavaDoc svc = new ServiceContext JavaDoc(TransactionServiceId, ctxData);
318         ri.add_request_service_context(svc, false);
319     }
320
321     public void send_poll(ClientRequestInfo ri) {
322         // do nothing.
323
}
324
325     public void receive_reply(ClientRequestInfo ri) {
326
327         // check if a tx svc context was received.
328

329         ServiceContext JavaDoc svc = null;
330         try {
331             svc = ri.get_reply_service_context(TransactionServiceId);
332         } catch (BAD_PARAM e) {
333             return; // do nothing (no tx service context in reply).
334
// REVISIT If a valid tx context was sent, and none was received
335
// back, then the checked transaction behaviour will cause the
336
// transaction to fail.
337
}
338
339         // a tx svc context is available.
340

341         // check if TransactionService is available.
342
if (this.tsiImpl == null || this.sender == null) {
343             throw new TRANSACTION_ROLLEDBACK(0, CompletionStatus.COMPLETED_YES);
344         }
345
346         if (_logger.isLoggable(Level.FINE)) {
347             _logger.log(Level.FINE," received_reply[" + ri.request_id() + "] : " +
348                     ri.operation() + ", ThreadName : " +
349                     Thread.currentThread().toString());
350         }
351
352         // read the propagation context
353

354         Any any = null;
355         try {
356             TypeCode typeCode = PropagationContextHelper.type();
357             any = this.codec.decode_value(svc.context_data, typeCode);
358         } catch (TypeMismatch e) {
359             throw new INTERNAL(0, CompletionStatus.COMPLETED_YES);
360         } catch (FormatMismatch e) {
361             throw new INTERNAL(0, CompletionStatus.COMPLETED_YES);
362         }
363         PropagationContext ctx = PropagationContextHelper.extract(any);
364
365         // Set up the Environment instance with exception information.
366
// The exception can be a SystemException or an UnknownUserException.
367

368     Environment env = new EnvironmentImpl();
369     env.exception(null);
370
371         // call the OTS proprietary hook.
372

373         try {
374         sender.received_reply(ri.request_id(), ctx, env);
375     } catch (org.omg.CORBA.WrongTransaction JavaDoc ex) {
376             throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_YES);
377     }
378     }
379
380     public void receive_exception(ClientRequestInfo ri) throws ForwardRequest {
381
382         // check if a tx svc context was received.
383

384         ServiceContext JavaDoc svc = null;
385         try {
386             svc = ri.get_reply_service_context(TransactionServiceId);
387         } catch (BAD_PARAM e) {
388             return; // do nothing (no tx service context in reply).
389
// REVISIT Exception replies may not carry a tx context back,
390
// as a result checked transaction behaviour will cause the
391
// transaction to fail.
392
}
393     catch(Exception JavaDoc e){
394         return;
395     }
396
397         // a tx svc context is available.
398

399         // Set up the Environment instance with exception information.
400
// The exception can be a SystemException or an UnknownUserException.
401
Environment env = new com.sun.corba.ee.impl.corba.EnvironmentImpl();
402         SystemException exception = null;
403         Any any = ri.received_exception();
404         InputStream JavaDoc strm = any.create_input_stream();
405         String JavaDoc repId = ri.received_exception_id();
406         strm.read_string(); // read repId
407
int minorCode = strm.read_long(); // read minorCode
408
CompletionStatus completionStatus = // read completionStatus
409
CompletionStatus.from_int(strm.read_long());
410         if (repId.indexOf("UNKNOWN") != -1) { // user exception ?
411
if (minorCode == 1) { // read minorCode
412
// user exception
413
} else { // system exception
414
exception = SYS_EXC;
415         }
416         } else { // system exception
417
exception = SYS_EXC;
418         }
419     env.exception(exception);
420
421         // check if TransactionService is available.
422
if (this.tsiImpl == null || this.sender == null) {
423             throw new TRANSACTION_ROLLEDBACK(0, completionStatus);
424         }
425
426         // read the propagation context
427

428         try {
429             TypeCode typeCode = PropagationContextHelper.type();
430             any = this.codec.decode_value(svc.context_data, typeCode);
431         } catch (TypeMismatch e) {
432             throw new INTERNAL(0, completionStatus);
433         } catch (FormatMismatch e) {
434             throw new INTERNAL(0, completionStatus);
435         }
436         PropagationContext ctx = PropagationContextHelper.extract(any);
437
438         // call the OTS proprietary hook.
439

440         try {
441         sender.received_reply(ri.request_id(), ctx, env);
442     } catch (org.omg.CORBA.WrongTransaction JavaDoc ex) {
443             throw new INVALID_TRANSACTION(0, completionStatus);
444     }
445     }
446
447     public void receive_other(ClientRequestInfo ri) throws ForwardRequest {
448
449         // check if a tx svc context was received.
450

451         ServiceContext JavaDoc svc = null;
452         try {
453             svc = ri.get_reply_service_context(TransactionServiceId);
454         } catch (BAD_PARAM e) {
455             return; // do nothing (no tx service context in reply).
456
// REVISIT If a valid tx context was sent, and none was received
457
// back, then the checked transaction behaviour will cause the
458
// transaction to fail.
459
}
460
461         // a tx svc context is available.
462

463         // check if TransactionService is available.
464
if (this.tsiImpl == null || this.sender == null) {
465             throw new TRANSACTION_ROLLEDBACK(0, CompletionStatus.COMPLETED_NO);
466         }
467
468         // read the propagation context
469

470         Any any = null;
471         try {
472             TypeCode typeCode = PropagationContextHelper.type();
473             any = this.codec.decode_value(svc.context_data, typeCode);
474         } catch (TypeMismatch e) {
475             throw new INTERNAL(0, CompletionStatus.COMPLETED_NO);
476         } catch (FormatMismatch e) {
477             throw new INTERNAL(0, CompletionStatus.COMPLETED_NO);
478         }
479         PropagationContext ctx = PropagationContextHelper.extract(any);
480
481         // Set up the Environment instance with exception information.
482
// The exception can be a SystemException or an UnknownUserException.
483

484     Environment env = new EnvironmentImpl();
485     env.exception(null);
486
487         // call the OTS proprietary hook.
488

489         try {
490         sender.received_reply(ri.request_id(), ctx, env);
491     } catch (org.omg.CORBA.WrongTransaction JavaDoc ex) {
492             throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_NO);
493     }
494     }
495
496     // implementation of the ServerInterceptor interface.
497

498     public void receive_request_service_contexts(ServerRequestInfo ri)
499             throws ForwardRequest {
500
501         // since this could be called on a seperate thread, we need to
502
// transfer the svc context to the request PICurrent slots.
503
// But for now, since we know that this is called by the same thread
504
// as the target, we do not do it. But we should at some point.
505
// do policy checking.
506

507         OTSPolicy otsPolicy = null;
508         try {
509             otsPolicy = (OTSPolicy) ri.get_server_policy(OTS_POLICY_TYPE.value);
510         } catch (INV_POLICY e) {
511             // ignore. This will be treated as FORBIDS.
512
}
513
514         short otsPolicyValue = -1;
515
516         if (otsPolicy == null) {
517             // Once J2EE RI moves to POA based policy mechanism, default of
518
// FORBIDS shall be used. Until then, we will use ADAPTS.
519
//otsPolicyValue = OTSPolicyImpl._FORBIDS.value();
520
otsPolicyValue = OTSPolicyImpl._ADAPTS.value();
521         } else {
522             otsPolicyValue = otsPolicy.value();
523         }
524
525         // get the tx contxt, if one was received.
526

527         ServiceContext JavaDoc svc = null;
528         try {
529             svc = ri.get_request_service_context(TransactionServiceId);
530         } catch (BAD_PARAM e) {
531             // ignore, svc == null will be handled later.
532
}
533
534         // set threadLocal slot to indicate whether tx svc ctxt
535
// was received or not. (svc == null) ==> NO_REPLY is true.
536

537         if (svc == null) {
538             setThreadLocalData(NO_REPLY_SLOT, NO_REPLY);
539         } else {
540             setThreadLocalData(NO_REPLY_SLOT, REPLY);
541         }
542
543         // initially set the thread local slot to indicate proper ctxt.
544
// if the null ctx is received, then it will be set later in the method.
545
setThreadLocalData(NULL_CTX_SLOT, PROPER_CTX);
546
547         try {
548
549             // TransactionService is not available.
550

551             if (this.tsiImpl == null || this.receiver == null) {
552                 if (svc != null || otsPolicyValue == REQUIRES.value) {
553                     throw new TRANSACTION_UNAVAILABLE();
554                 }
555                 return;
556             }
557
558             // TransactionService is available.
559

560             // no tx context was received.
561
if (svc == null) {
562                 if (otsPolicyValue == REQUIRES.value) {
563                     throw new TRANSACTION_REQUIRED();
564                 }
565                 return;
566             }
567
568             // a tx ctx was received.
569

570             // check policy
571
if (otsPolicyValue == FORBIDS.value) {
572                 throw new INVALID_TRANSACTION();
573             }
574
575             if (_logger.isLoggable(Level.FINE)) {
576                 _logger.log(Level.FINE," received_request[" +
577                     ri.request_id() + "] : " + ri.operation() +
578                     ", ThreadName : " + Thread.currentThread().toString());
579             }
580
581             // Create service context.
582

583             // sanity check.
584
if (svc.context_id != TransactionServiceId) {
585                 throw new INVALID_TRANSACTION();
586             }
587
588             Any any = null;
589             try {
590                 TypeCode typeCode = PropagationContextHelper.type();
591                 any = this.codec.decode_value(svc.context_data, typeCode);
592             } catch (TypeMismatch e) {
593                 throw new INTERNAL();
594             } catch (FormatMismatch e) {
595                 throw new INTERNAL();
596             }
597             PropagationContext ctx = PropagationContextHelper.extract(any);
598
599             // check if a 'dummyContext' is present (local optimization).
600
// If so, return.
601

602             if (isDummyContext(ctx)) {
603                 // do nothing, since it is the same client thread which already
604
// has the tx context association.
605
// NOTE There is a chance that the 'nullContext' could be mistaken
606
// to be a 'dummyContext', which may cause a valid 'nullContext'
607
// to be ignored (!). But let's hope there won't be a collision :)
608

609                 // no need to send a reply ctx
610
getThreadLocalData(NO_REPLY_SLOT); // pop item
611
setThreadLocalData(NO_REPLY_SLOT, NO_REPLY); // push item
612
return;
613             }
614
615             // check if a 'nullContext' was received,
616
// and set the threadlocal data appropriately.
617

618             if (isNullContext(ctx)) {
619                 // indicate a null context
620
getThreadLocalData(NULL_CTX_SLOT); // pop item
621
setThreadLocalData(NULL_CTX_SLOT, NULL_CTX); // push item
622
// no need to send a reply ctx
623
getThreadLocalData(NO_REPLY_SLOT); // pop item
624
setThreadLocalData(NO_REPLY_SLOT, NO_REPLY); // push item
625
return;
626             } else if (this.interopMode == false) {
627                 getThreadLocalData(NULL_CTX_SLOT); // pop item
628
setThreadLocalData(NULL_CTX_SLOT, NULL_CTX); // push item
629
}
630
631             // call the proprietary hook
632
receiver.received_request(ri.request_id(), ctx);
633
634         } catch (RuntimeException JavaDoc r) {
635             // The server send point will not be called if the server receive
636
// point raises an exception. So, do the cleanup.
637
// ie., restore thread local data
638
getThreadLocalData(NO_REPLY_SLOT);
639             getThreadLocalData(NULL_CTX_SLOT);
640             throw r;
641         }
642     }
643
644     public void receive_request(ServerRequestInfo ri)
645             throws ForwardRequest {
646         // do nothing.
647
}
648
649     private void processServerSendPoint(
650             ServerRequestInfo ri, CompletionStatus completionStatus) {
651
652         // clear the null ctx indicator
653
getThreadLocalData(NULL_CTX_SLOT);
654
655         // see if a reply ctx needs to be sent.
656

657         Integer JavaDoc no_reply = getThreadLocalData(NO_REPLY_SLOT);
658
659         if (no_reply == NO_REPLY) {
660             return;
661         }
662
663         // TransactionService is not available.
664

665         if (this.tsiImpl == null || this.receiver == null) {
666             if (no_reply == REPLY) {
667                 // would the TransactionService go down during request
668
// processing ? Maybe.
669
throw new TRANSACTION_ROLLEDBACK(0, completionStatus);
670             }
671             return;
672         }
673
674         if (_logger.isLoggable(Level.FINE)) {
675             _logger.log(Level.FINE," sending_reply["+ ri.request_id() + "] : " +
676                 ri.operation() + ", ThreadName : " +
677                 Thread.currentThread().toString());
678         }
679
680         // call the proprietary OTS interceptor.
681

682         PropagationContextHolder ctxh = new PropagationContextHolder();
683         receiver.sending_reply(ri.request_id(), ctxh);
684
685         if (ctxh.value == null) {
686             // no tx context available. This should not happen since a tx ctx
687
// was received.
688
throw new TRANSACTION_ROLLEDBACK(0, completionStatus);
689         }
690
691         // create the service context and set it in the reply.
692

693         //Any any = ORB.init().create_any();
694
Any any = txOrb.create_any();
695         PropagationContextHelper.insert(any, ctxh.value);
696         byte[] ctxData = null;
697         try {
698             ctxData = this.codec.encode_value(any);
699         } catch (InvalidTypeForEncoding e) {
700             throw new INTERNAL(0, completionStatus);
701         }
702         ServiceContext JavaDoc svc = new ServiceContext JavaDoc(TransactionServiceId, ctxData);
703         ri.add_reply_service_context(svc, false);
704     }
705
706     public void send_reply(ServerRequestInfo ri) {
707         processServerSendPoint(ri, CompletionStatus.COMPLETED_YES);
708     }
709
710     public void send_exception(ServerRequestInfo ri) throws ForwardRequest {
711         Any any = ri.sending_exception();
712         InputStream JavaDoc strm = any.create_input_stream();
713         strm.read_string(); // repId
714
strm.read_long(); // minorCode
715
CompletionStatus completionStatus =
716             CompletionStatus.from_int(strm.read_long());
717
718         processServerSendPoint(ri, completionStatus);
719     }
720
721     public void send_other(ServerRequestInfo ri) throws ForwardRequest {
722         processServerSendPoint(ri, CompletionStatus.COMPLETED_NO);
723     }
724
725     // helper static methods.
726

727     public static boolean isTxCtxtNull() {
728         Object JavaDoc[] threadLocalState = (Object JavaDoc[]) otsThreadLocal.get();
729         // IASRI 4698847 START
730
//Stack stack = (Stack) threadLocalState[NULL_CTX_SLOT];
731
/*
732         if (stack.empty()) {
733             return true;
734         }
735         */

736         // return ((Integer) stack.peek() == NULL_CTX);
737
ArrayListStack stack = (ArrayListStack) threadLocalState[NULL_CTX_SLOT];
738         return ((Integer JavaDoc) stack.peek() == NULL_CTX);
739         // IASRI 4698847 END
740
}
741
742     public static boolean isNullContext(PropagationContext ctx) {
743         return (ctx.current.coord == null && ctx.current.term == null);
744     }
745
746     public static boolean isDummyContext(PropagationContext ctx) {
747         boolean proceed = false;
748         try {
749             proceed =
750                 (ctx.implementation_specific_data.extract_boolean() == true);
751         } catch (BAD_OPERATION e) {
752             return false;
753         }
754         return (proceed && isNullContext(ctx) && ctx.timeout == -1);
755     }
756
757     public static void setThreadLocalData(int slot, Integer JavaDoc data) {
758         Object JavaDoc[] threadLocalState = (Object JavaDoc[]) otsThreadLocal.get();
759         // IASRI 4698847 START
760
//((Stack) threadLocalState[slot]).push(data);
761
((ArrayListStack) threadLocalState[slot]).push(data);
762         // IASRI 4698847 END
763
}
764
765     public static Integer JavaDoc getThreadLocalData(int slot) {
766         Object JavaDoc[] threadLocalState = (Object JavaDoc[]) otsThreadLocal.get();
767         // IASRI 4698847 START
768
//return (Integer) ((Stack) threadLocalState[slot]).pop();
769
return (Integer JavaDoc) ((ArrayListStack) threadLocalState[slot]).pop();
770         // IASRI 4698847 END
771
}
772
773     public static void setOrb(ORB orb) {
774         txOrb = orb;
775     }
776 }
777
Popular Tags