KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.omg.CORBA.INITIALIZE JavaDoc;
27 import org.omg.CORBA.CompletionStatus JavaDoc;
28 import org.omg.CORBA.TSIdentification;
29 import java.lang.reflect.Method JavaDoc;
30 import java.lang.reflect.InvocationTargetException JavaDoc;
31 import java.util.Properties JavaDoc;
32 import com.sun.corba.ee.impl.logging.POASystemException;
33 import com.sun.corba.ee.impl.txpoa.TSIdentificationImpl;
34 import com.sun.corba.ee.spi.costransactions.TransactionService;
35 import com.sun.corba.ee.spi.orb.ORB ;
36 import com.sun.corba.ee.spi.orb.ORBConfigurator;
37 import com.sun.corba.ee.spi.orb.ParserImplBase;
38 import com.sun.corba.ee.spi.orb.PropertyParser;
39 import com.sun.corba.ee.spi.orb.DataCollector;
40 import com.sun.corba.ee.spi.orb.OperationFactory;
41 import com.sun.corba.ee.spi.copyobject.ObjectCopierFactory ;
42 import com.sun.corba.ee.spi.copyobject.CopierManager;
43 import com.sun.corba.ee.spi.copyobject.CopyobjectDefaults;
44 import com.sun.corba.ee.impl.orbutil.ORBConstants;
45 import com.sun.corba.ee.impl.orbutil.closure.Constant;
46 import com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolManager;
47 import com.sun.enterprise.util.ORBManager;
48 import com.sun.enterprise.util.S1ASThreadPoolManager;
49
50 import com.sun.enterprise.Switch;
51 import com.sun.enterprise.admin.monitor.callflow.Agent;
52 import com.sun.enterprise.admin.monitor.callflow.ContainerTypeOrApplicationType;
53 import com.sun.corba.ee.spi.presentation.rmi.InvocationInterceptor;
54 import com.sun.corba.ee.impl.oa.poa.BadServerIdHandler ;
55 import com.sun.corba.ee.spi.ior.ObjectKey ;
56
57 // Internal JTS interceptor implementation
58
import com.sun.jts.pi.InterceptorImpl;
59
60 import java.util.logging.*;
61 import com.sun.logging.*;
62
63 public class PEORBConfigurator implements ORBConfigurator {
64
65     private static final java.util.logging.Logger JavaDoc logger =
66         java.util.logging.Logger.getLogger(LogDomains.CORBA_LOGGER);
67
68     private static final String JavaDoc OPT_COPIER_CLASS =
69     "com.sun.corba.ee.spi.copyobject.OptimizedCopyobjectDefaults";
70
71     private static com.sun.jts.pi.InterceptorImpl jtsInterceptor;
72     private static TSIdentification tsIdent;
73     private static ORB theORB;
74     private static ThreadPoolManager threadpoolMgr = null;
75
76     static {
77     tsIdent = new TSIdentificationImpl();
78     }
79
80     public void configure( DataCollector dc, ORB orb ) {
81         //begin temp fix for bug 6320008
82
// this is needed only because we are using transient Name Service
83
//this should be removed once we have the persistent Name Service in place
84
orb.setBadServerIdHandler(
85         new BadServerIdHandler() {
86         public void handle( ObjectKey objectkey ) {
87             // NO-OP
88
}
89         }
90     ) ;
91     //end temp fix for bug 6320008
92
if (threadpoolMgr != null) {
93         // This will be the case for the Server Side ORB created
94
// For client side threadpoolMgr will be null, so we will
95
// never come here
96
orb.setThreadPoolManager(threadpoolMgr);
97     }
98
99     configureCopiers(orb);
100         configureCallflowInvocationInterceptor(orb);
101     }
102
103     private static void configureCopiers(ORB orb) {
104     ObjectCopierFactory stream;
105     CopierManager cpm = orb.getCopierManager();
106
107     // Get the default copier factory
108
stream = CopyobjectDefaults.makeORBStreamObjectCopierFactory(orb);
109     cpm.registerObjectCopierFactory(stream,
110                 POARemoteReferenceFactory.PASS_BY_VALUE_ID);
111     cpm.setDefaultId(POARemoteReferenceFactory.PASS_BY_VALUE_ID);
112
113     // Detect if the optimized copier class exists in the classpath
114
// or not. For the RI, one should get a ClassNotFoundException
115
try {
116         Class JavaDoc cls = Class.forName(OPT_COPIER_CLASS);
117         configureOptCopier(orb, cls, stream);
118     } catch (ClassNotFoundException JavaDoc cnfe) {
119         // Don't do anything. This is true for RI and the default
120
// stream copier is fine for that
121
}
122     }
123
124     private static void configureOptCopier(ORB orb, Class JavaDoc cls,
125                     ObjectCopierFactory stream) {
126     CopierManager cpm = orb.getCopierManager();
127     
128     // Get the reference copier factory
129
ObjectCopierFactory reference = CopyobjectDefaults.
130                 getReferenceObjectCopierFactory();
131     
132     try {
133         Method JavaDoc m = cls.getMethod("makeReflectObjectCopierFactory",
134             new Class JavaDoc[] {com.sun.corba.ee.spi.orb.ORB.class});
135         ObjectCopierFactory reflect =
136         (ObjectCopierFactory)m.invoke(cls, new Object JavaDoc[] {orb});
137         ObjectCopierFactory fallback =
138         CopyobjectDefaults.makeFallbackObjectCopierFactory(reflect, stream);
139         cpm.registerObjectCopierFactory(fallback,
140             POARemoteReferenceFactory.PASS_BY_VALUE_ID);
141         cpm.registerObjectCopierFactory(reference,
142             POARemoteReferenceFactory.PASS_BY_REFERENCE_ID);
143         cpm.setDefaultId(POARemoteReferenceFactory.PASS_BY_VALUE_ID);
144     } catch (NoSuchMethodException JavaDoc e) {
145         logger.log(Level.FINE,"Caught NoSuchMethodException - " + e.getMessage());
146         logger.log(Level.FINE,"Proceeding with pass-by-value copier set to stream copier");
147     } catch (IllegalAccessException JavaDoc e) {
148         logger.log(Level.FINE,"Caught IllegalAccessException - " + e.getMessage());
149         logger.log(Level.FINE,"Proceeding with pass-by-value copier set to stream copier");
150     } catch (IllegalArgumentException JavaDoc e) {
151         logger.log(Level.FINE,"Caught IllegalArgumentException - " + e.getMessage());
152         logger.log(Level.FINE,"Proceeding with pass-by-value copier set to stream copier");
153     } catch (InvocationTargetException JavaDoc e) {
154         logger.log(Level.FINE,"Caught InvocationTargetException - " + e.getMessage());
155         logger.log(Level.FINE,"Proceeding with pass-by-value copier set to stream copier");
156     } catch (NullPointerException JavaDoc e) {
157         logger.log(Level.FINE,"Caught NullPointerException - " + e.getMessage());
158         logger.log(Level.FINE,"Proceeding with pass-by-value copier set to stream copier");
159     } catch (ExceptionInInitializerError JavaDoc e) {
160         logger.log(Level.FINE,"Caught ExceptionInInitializerError - " + e.getMessage());
161         logger.log(Level.FINE,"Proceeding with pass-by-value copier set to stream copier");
162     }
163     }
164
165     // Called from J2EEInitializer
166
static void setJTSInterceptor(InterceptorImpl intr, ORB orb)
167     {
168     theORB = orb;
169         jtsInterceptor = intr;
170
171         // Set ORB and TSIdentification: needed for app clients,
172
// standalone clients.
173
jtsInterceptor.setOrb(theORB);
174     }
175
176     // Called from ORBManager only when the ORB is running on server side
177
public static void setThreadPoolManager() {
178     threadpoolMgr = S1ASThreadPoolManager.getThreadPoolManager();
179     }
180
181     public static void initTransactionService(String JavaDoc jtsClassName, Properties JavaDoc
182     jtsProperties )
183     {
184     String JavaDoc clsName = (jtsClassName == null) ?
185         "com.sun.jts.CosTransactions.DefaultTransactionService" : jtsClassName;
186     try {
187         Class JavaDoc theJTSClass = Class.forName(clsName);
188
189         if (theJTSClass != null) {
190         try {
191             TransactionService jts = (TransactionService)theJTSClass.newInstance();
192             jts.identify_ORB(theORB, tsIdent, jtsProperties ) ;
193             jtsInterceptor.setTSIdentification(tsIdent);
194             // XXX should jts.get_current() be called everytime
195
// resolve_initial_references is called ??
196
org.omg.CosTransactions.Current transactionCurrent =
197             jts.get_current();
198
199             theORB.getLocalResolver().register(
200             ORBConstants.TRANSACTION_CURRENT_NAME,
201             new Constant(transactionCurrent));
202
203             // the JTS PI use this to call the proprietary hooks
204
theORB.getLocalResolver().register(
205             "TSIdentification", new Constant(tsIdent));
206
207         } catch (Exception JavaDoc ex) {
208             throw new org.omg.CORBA.INITIALIZE JavaDoc(
209             "JTS Exception: "+ex, POASystemException.JTS_INIT_ERROR ,
210             CompletionStatus.COMPLETED_MAYBE);
211         }
212         }
213     } catch (ClassNotFoundException JavaDoc cnfe) {
214         logger.log(Level.SEVERE,"iiop.inittransactionservice_exception",cnfe);
215     }
216
217     }
218     
219     private static void configureCallflowInvocationInterceptor(ORB orb) {
220         orb.setInvocationInterceptor(
221         new InvocationInterceptor() {
222         public void preInvoke() {
223             Agent agent = Switch.getSwitch().getCallFlowAgent();
224             if (agent != null) {
225                 agent.startTime(
226                     ContainerTypeOrApplicationType.ORB_CONTAINER);
227             }
228         }
229         public void postInvoke() {
230             Agent agent = Switch.getSwitch().getCallFlowAgent();
231             if (agent != null) {
232                 agent.endTime();
233             }
234         }
235         }
236     );
237     }
238 }
239
Popular Tags