KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > transaction > ServerContextTransferInterceptor


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.transaction;
22
23 import org.apache.avalon.framework.logger.Logger;
24
25 import org.omg.PortableInterceptor.*;
26 import org.omg.CosTransactions.*;
27 import org.omg.IOP.ServiceContext JavaDoc;
28 import org.omg.IOP.TransactionService JavaDoc;
29 import org.omg.IOP.Codec JavaDoc;
30
31 /**
32  * This interceptor transfers the propagation context
33  * from the corresponding service context to a slot
34  * in the PICurrent.
35  *
36  * @author Nicolas Noffke
37  * @author Vladimir Mencl
38  * @version $Id: ServerContextTransferInterceptor.java,v 1.10 2004/04/28 12:37:29 brose Exp $
39  *
40  * Changes made by Vladimir Mencl <vladimir.mencl@mff.cuni.cz> (2002/05/01)
41  *
42  * * set transaction context in receive_request into internal structures of
43  * Current (TransactionCurrentImpl) using resume()
44  *
45  * * reset transaction context when a request terminates (either through
46  * send_reply, send_exception or send_other) using suspend()
47  *
48  * * accesses Current only through CosTransactions::Current interface
49  * (without typecasting to TransactionCurrentImpl)
50  */

51
52 public class ServerContextTransferInterceptor
53     extends org.omg.CORBA.LocalObject JavaDoc
54     implements ServerRequestInterceptor
55 {
56     private Codec JavaDoc codec = null;
57     private int slot_id = -1;
58     private org.omg.CosTransactions.Current ts_current;
59     private org.omg.CORBA.ORB JavaDoc orb;
60     private Logger logger;
61
62     public ServerContextTransferInterceptor(Codec JavaDoc codec,
63                                             int slot_id,
64                                             org.omg.CosTransactions.Current ts_current,
65                                             org.omg.CORBA.ORB JavaDoc orb)
66     {
67         this.codec = codec;
68         this.slot_id = slot_id;
69         this.ts_current = ts_current;
70         this.orb = orb;
71         this.logger =
72             ((org.jacorb.orb.ORB)orb).getConfiguration().getNamedLogger("jacorb.tx_service.interceptor");
73     }
74
75     // implementation of org.omg.PortableInterceptor.InterceptorOperations interface
76
public String JavaDoc name()
77     {
78         return "ServerContextTransferInterceptor";
79     }
80
81     public void destroy()
82     {
83     }
84
85     /**
86      * Put the propagation context from the service context
87      * into the PICurrent.
88      */

89     public void receive_request_service_contexts(ServerRequestInfo ri)
90         throws ForwardRequest
91     {
92         try
93         {
94             ServiceContext JavaDoc ctx = ri.get_request_service_context(TransactionService.value);
95             ri.set_slot(slot_id, codec.decode(ctx.context_data));
96         }
97         catch (Exception JavaDoc e)
98         {
99             if (logger.isDebugEnabled())
100                 logger.debug("Exception", e);
101         }
102     }
103
104     public void receive_request(ServerRequestInfo ri)
105         throws ForwardRequest
106     {
107         try
108         {
109             org.omg.PortableInterceptor.Current JavaDoc pi_current =
110                 (org.omg.PortableInterceptor.Current JavaDoc)
111         orb.resolve_initial_references("PICurrent");
112
113             PropagationContext context = PropagationContextHelper.extract
114                 (pi_current.get_slot(slot_id));
115
116             Control control = ControlHelper.extract(context.implementation_specific_data);
117             ts_current.resume(control);
118         }
119         catch(Exception JavaDoc e)
120         {
121             if (logger.isDebugEnabled())
122                 logger.debug("Exception", e);
123         }
124     }
125
126     public void send_reply(ServerRequestInfo ri)
127     {
128         ts_current.suspend();
129     }
130
131     public void send_exception(ServerRequestInfo ri)
132         throws ForwardRequest
133     {
134         ts_current.suspend();
135     }
136
137     public void send_other(ServerRequestInfo ri)
138         throws ForwardRequest
139     {
140         ts_current.suspend();
141     }
142 } // ServerContextTransferInterceptor
143

144
145
Popular Tags