KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > iiop > ServerConnectionInterceptor


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 package com.sun.enterprise.iiop;
25
26 import java.net.Socket JavaDoc;
27 import org.omg.PortableInterceptor.ServerRequestInfo JavaDoc;
28 import com.sun.corba.ee.spi.legacy.interceptor.RequestInfoExt;
29 import com.sun.corba.ee.spi.legacy.connection.Connection;
30 import com.sun.enterprise.iiop.security.SecurityMechanismSelector;
31 import com.sun.enterprise.iiop.security.ServerConnectionContext;
32
33 import com.sun.enterprise.J2EETransactionManager;
34 import com.sun.enterprise.Switch;
35 import com.sun.enterprise.distributedtx.J2EETransactionManagerOpt;
36
37 import com.sun.enterprise.admin.monitor.callflow.Agent;
38 import com.sun.enterprise.admin.monitor.callflow.RequestType;
39 import com.sun.enterprise.admin.monitor.callflow.RequestInfo;
40 import com.sun.enterprise.admin.monitor.callflow.ContainerTypeOrApplicationType;
41 import com.sun.enterprise.util.ORBManager;
42 import java.util.logging.*;
43 import com.sun.logging.*;
44
45
46 public class ServerConnectionInterceptor extends org.omg.CORBA.LocalObject JavaDoc
47     implements org.omg.PortableInterceptor.ServerRequestInterceptor JavaDoc, Comparable JavaDoc
48 {
49     private static Logger _logger=null;
50     static{
51        _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER);
52         }
53     public static final String JavaDoc baseMsg = "ServerConnectionInterceptor";
54     public int order;
55
56     /**
57      * Construct the interceptor.
58      * @param the order in which the interceptor should run.
59      */

60     public ServerConnectionInterceptor(int order) {
61     this.order = order;
62     }
63
64     public String JavaDoc name() { return baseMsg; }
65
66     public void receive_request_service_contexts(ServerRequestInfo JavaDoc sri)
67     {
68         Socket JavaDoc s = null;
69         Connection c = ((RequestInfoExt)sri).connection();
70         SecurityMechanismSelector sms = new SecurityMechanismSelector();
71         ServerConnectionContext scc = null;
72         if (c != null) {
73             s = c.getSocket();
74             if(_logger.isLoggable(Level.FINE)) {
75                 _logger.log(Level.FINE,"RECEIVED request on connection: " + c);
76                 _logger.log(Level.FINE,"Socket =" + s);
77             }
78             scc = new ServerConnectionContext(s);
79         } else {
80             scc = new ServerConnectionContext();
81         }
82         sms.setServerConnectionContext(scc);
83     }
84
85     public int compareTo(Object JavaDoc o)
86     {
87     int otherOrder = -1;
88     if( o instanceof ServerConnectionInterceptor) {
89             otherOrder = ((ServerConnectionInterceptor)o).order;
90     }
91         if (order < otherOrder) {
92             return -1;
93         } else if (order == otherOrder) {
94             return 0;
95         }
96         return 1;
97     }
98
99     public void destroy() {}
100
101     public void receive_request(ServerRequestInfo JavaDoc sri)
102     {
103         Socket JavaDoc s = null;
104         Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
105         // callFlowAgent should never be null.
106
// If the else block is executed, its a bug.
107
// more investigation needed
108
if (callFlowAgent != null) {
109         boolean callFlowEnabled = callFlowAgent.isEnabled();
110         if (callFlowEnabled){
111             // Only do callflow RequestStart,
112
// If it is a ejb call and not a is_a call. For everything else
113
// do a startTime for OTHER Container
114
if (isEjbCall(sri)){
115             try {
116                 try{
117                 Connection c = ((RequestInfoExt)sri).connection();
118                 if (c != null) {
119                     s = c.getSocket();
120                 }
121             } finally {
122                 String JavaDoc callerIPAddress = null;
123                 if (s != null) {
124                                 callerIPAddress = s.getInetAddress().getHostAddress();
125                 }
126                 callFlowAgent.requestStart(RequestType.REMOTE_EJB);
127                 callFlowAgent.addRequestInfo(
128                              RequestInfo.CALLER_IP_ADDRESS, callerIPAddress);
129             }
130             } catch (Exception JavaDoc ex){
131                 _logger.log( Level.WARNING,
132                      "Callflow Agent's requestStart exception" + ex);
133             }
134         } else {
135             try {
136                 callFlowAgent.startTime(ContainerTypeOrApplicationType.ORB_CONTAINER);
137             } catch (Exception JavaDoc ex){
138                 _logger.log( Level.WARNING,
139                      "Callflow Agent's starttime exception" + ex);
140             }
141         }
142         }
143     } else {
144          _logger.log( Level.FINE, "CallFlow Agent not initialized. ");
145     }
146     }
147     public void send_reply(ServerRequestInfo JavaDoc sri)
148     {
149         try {
150             checkTransaction(sri);
151         } finally {
152             if (isEjbCall(sri)) {
153                 Switch.getSwitch().getTransactionManager().cleanTxnTimeout();
154             }
155             Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
156         // callFlowAgent should never be null.
157
// If the else block is executed, its a bug.
158
// more investigation needed
159
if (callFlowAgent != null) {
160             boolean callFlowEnabled = callFlowAgent.isEnabled();
161         if(callFlowEnabled){
162             if (isEjbCall(sri)){
163                 try {
164                 callFlowAgent.requestEnd();
165             } catch (Exception JavaDoc ex) {
166                 _logger.log(
167                       Level.WARNING,
168                       "Callflow Agent's requestEnd method exception" + ex);
169             }
170             } else {
171                 try {
172                 callFlowAgent.endTime();
173             } catch (Exception JavaDoc ex) {
174                 _logger.log(
175                     Level.WARNING,
176                     "Callflow Agent's endtime method exception" + ex);
177             }
178             }
179         }
180         } else {
181             _logger.log( Level.FINE, "CallFlow Agent not initialized. ");
182         }
183     }
184     }
185
186     public void send_exception(ServerRequestInfo JavaDoc sri)
187     {
188         try {
189             checkTransaction(sri);
190         } finally {
191             if (isEjbCall(sri)) {
192                 Switch.getSwitch().getTransactionManager().cleanTxnTimeout();
193             }
194             Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
195         // callFlowAgent should never be null.
196
// If the else block is executed, its a bug.
197
// more investigation needed
198
if (callFlowAgent != null) {
199              boolean callFlowEnabled = callFlowAgent.isEnabled();
200          if(callFlowEnabled){
201              if (isEjbCall(sri)){
202                  try {
203                  callFlowAgent.requestEnd();
204              } catch (Exception JavaDoc ex) {
205                  _logger.log(
206                        Level.WARNING,
207                        "Callflow Agent's requestEnd method exception" + ex);
208              }
209              } else {
210                  try {
211                  callFlowAgent.endTime();
212              } catch (Exception JavaDoc ex) {
213                  _logger.log(
214                      Level.WARNING,
215                      "Callflow Agent's endtime method exception" + ex);
216              }
217              }
218          }
219          } else {
220              _logger.log( Level.FINE, "CallFlow Agent not initialized. ");
221          }
222     }
223     }
224
225     public void send_other(ServerRequestInfo JavaDoc sri)
226     {
227         try {
228             checkTransaction(sri);
229         } finally {
230             if (isEjbCall(sri)) {
231                 Switch.getSwitch().getTransactionManager().cleanTxnTimeout();
232             }
233             Agent callFlowAgent = Switch.getSwitch().getCallFlowAgent();
234         // callFlowAgent should never be null.
235
// If the else block is executed, its a bug.
236
// more investigation needed
237
if (callFlowAgent != null) {
238             boolean callFlowEnabled = callFlowAgent.isEnabled();
239         if(callFlowEnabled){
240             if (isEjbCall(sri)) {
241                 try {
242                 callFlowAgent.requestEnd();
243             } catch (Exception JavaDoc ex) {
244                 _logger.log(
245                     Level.WARNING,
246                     "Callflow Agent's requestEnd method exception" + ex);
247             }
248             } else {
249                 try {
250                 callFlowAgent.endTime();
251             } catch (Exception JavaDoc ex) {
252                 _logger.log(
253                     Level.WARNING,
254                     "Callflow Agent's endtime method exception" + ex);
255             }
256             }
257         }
258             } else {
259             _logger.log( Level.FINE, "CallFlow Agent not initialized. ");
260         }
261         }
262     }
263
264     private void checkTransaction(ServerRequestInfo JavaDoc sri) {
265     /**
266     ObjectImpl target = (ObjectImpl)sri.effective_target();
267         if ( !target._is_local() ) {
268         J2EETransactionManager tm =
269                     Switch.getSwitch().getTransactionManager();
270         if ( tm != null )
271         tm.checkTransactionExport();
272     }
273     **/

274     J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
275     if ( tm != null )
276         tm.checkTransactionImport();
277     }
278     /**
279      * Returns true, if the incoming call is a EJB method call.
280      * This checks for is_a calls and ignores those calls. In callflow analysis
281      * when a component looks up another component, this lookup should be
282      * considered part of the same call coming in.
283      * Since a lookup triggers the iiop codebase, it will fire a new request start.
284      * With this check, we consider the calls that are only new incoming ejb
285      * method calls as new request starts.
286      */

287     private boolean isEjbCall (ServerRequestInfo JavaDoc sri) {
288         if (ORBManager.isEjbAdapterName(sri.adapter_name()) &&
289                 (!ORBManager.isIsACall(sri.operation()))) {
290             return true;
291         } else
292             return false;
293     }
294 }
295
Popular Tags