KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > rmi > jrmp > interceptor > JInterceptorStore


1 /**
2  * Copyright (C) 2002,2004 - INRIA (www.inria.fr)
3  *
4  * CAROL: Common Architecture for RMI ObjectWeb Layer
5  *
6  * This library is developed inside the ObjectWeb Consortium,
7  * http://www.objectweb.org
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  *
24  * --------------------------------------------------------------------------
25  * $Id: JInterceptorStore.java,v 1.9 2005/04/28 18:21:51 el-vadimo Exp $
26  * --------------------------------------------------------------------------
27  */

28 package org.objectweb.carol.rmi.jrmp.interceptor;
29
30 import java.rmi.server.UID JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Arrays JavaDoc;
33 import java.util.Enumeration JavaDoc;
34 import java.util.Properties JavaDoc;
35
36 import org.objectweb.carol.util.configuration.TraceCarol;
37
38 /**
39  * Class <code>JInterceptorStore</code> is the CAROL JRMP Client and Server
40  * Interceptors Storage System
41  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
42  * @version 1.0, 10/03/2003
43  */

44 public class JInterceptorStore {
45
46     /**
47      * Initilazer class prefix
48      */

49     public static final String JavaDoc INTIALIZER_PREFIX = "org.objectweb.PortableInterceptor.JRMPInitializerClass";
50
51     /**
52      * private Interceptor for Context propagation
53      */

54     private static JServerRequestInterceptor[] sis = null;
55
56     /**
57      * private Interceptor for Context propagation
58      */

59     private static JClientRequestInterceptor[] cis = null;
60
61     /**
62      * private remote Interceptor cache for Context propagation
63      */

64     private static JClientRequestInterceptor[] rcis = null;
65
66     /**
67      * private remote UID for cache
68      */

69     private static UID JavaDoc uid = null;
70
71     /**
72      * private remote addr for cache
73      */

74     private static byte[] address = null;
75
76     /**
77      * private Interceptors Initializers for Context propagation
78      */

79     private static String JavaDoc[] initializers = null;
80
81     /**
82      * JRMPINfo Impl
83      */

84     private static JRMPInitInfoImpl jrmpInfo = new JRMPInitInfoImpl();
85
86     /**
87      * Intialize interceptors for a carol server
88      */

89     static {
90         // Load the Interceptors
91
try {
92             JInitInfo jrmpInfo = new JRMPInitInfoImpl();
93             String JavaDoc[] ins = getJRMPInitializers();
94             for (int i = 0; i < ins.length; i++) {
95                 JInitializer jinit = (JInitializer) Thread.currentThread().getContextClassLoader()
96                     .loadClass(ins[i]).newInstance();
97                 jinit.pre_init(jrmpInfo);
98                 jinit.post_init(jrmpInfo);
99             }
100             sis = jrmpInfo.getServerRequestInterceptors();
101             cis = jrmpInfo.getClientRequestInterceptors();
102             // fisrt remote reference = local reference
103
rcis = cis;
104             uid = JInterceptorHelper.getSpaceID();
105             address = JInterceptorHelper.getInetAddress();
106         } catch (Exception JavaDoc e) {
107             //we did not found the interceptor do nothing but a trace ?
108
TraceCarol.error("JrmpPRODelegate(), No interceptors found", e);
109         }
110     }
111
112     /**
113      * get the local server interceptor
114      */

115     public static JServerRequestInterceptor[] getLocalServerInterceptors() {
116         return sis;
117     }
118
119     /**
120      * get the local client interceptor
121      */

122     public static JClientRequestInterceptor[] getLocalClientInterceptors() {
123         return cis;
124     }
125
126     /**
127      * Get Intializers method
128      * @return JRMP Initializers enuumeration
129      */

130     public synchronized static String JavaDoc[] getJRMPInitializers() {
131         // if exists, return it
132
if (initializers != null) {
133             return initializers;
134         }
135         // else, compute it.
136
ArrayList JavaDoc ins = new ArrayList JavaDoc();
137         Properties JavaDoc sys = System.getProperties();
138         for (Enumeration JavaDoc e = System.getProperties().propertyNames(); e.hasMoreElements();) {
139             String JavaDoc pkey = (String JavaDoc) e.nextElement();
140             if (pkey.startsWith(INTIALIZER_PREFIX)) {
141                 ins.add(pkey.substring(INTIALIZER_PREFIX.length() + 1));
142             }
143         }
144         int sz = ins.size();
145         initializers = new String JavaDoc[sz];
146         for (int i = 0; i < sz; i++) {
147             initializers[i] = (String JavaDoc) ins.get(i);
148         }
149         return initializers;
150     }
151
152     /**
153      * Get interceptor if exist
154      * @param raddr The remote adress (later)
155      * @param ruid The remote uid (later)
156      * @param ia iterceptors initializers
157      * @return JClientRequestInterceptors [] , the interceptors
158      */

159     public synchronized static JClientRequestInterceptor[] setRemoteInterceptors(byte[] raddr, UID JavaDoc ruid, String JavaDoc[] ia) {
160         if ((Arrays.equals(raddr, address)) && (ruid.equals(uid))) {
161             return rcis;
162         } else {
163             jrmpInfo.clear();
164             for (int i = 0; i < ia.length; i++) {
165                 JInitializer jinit = null;
166                 try {
167                     jinit = (JInitializer) Class.forName(ia[i]).newInstance();
168                     jinit.pre_init(jrmpInfo);
169                     jinit.post_init(jrmpInfo);
170                 } catch (Exception JavaDoc e) {
171                     TraceCarol.error("can not load interceptors", e);
172                 }
173             }
174             ruid = uid;
175             address = raddr;
176             rcis = jrmpInfo.getClientRequestInterceptors();
177             return rcis;
178         }
179     }
180 }
181
182
Popular Tags