1 28 package org.objectweb.carol.rmi.jrmp.interceptor; 29 30 import java.rmi.server.UID ; 31 import java.util.ArrayList ; 32 import java.util.Arrays ; 33 import java.util.Enumeration ; 34 import java.util.Properties ; 35 36 import org.objectweb.carol.util.configuration.TraceCarol; 37 38 44 public class JInterceptorStore { 45 46 49 public static final String INTIALIZER_PREFIX = "org.objectweb.PortableInterceptor.JRMPInitializerClass"; 50 51 54 private static JServerRequestInterceptor[] sis = null; 55 56 59 private static JClientRequestInterceptor[] cis = null; 60 61 64 private static JClientRequestInterceptor[] rcis = null; 65 66 69 private static UID uid = null; 70 71 74 private static byte[] address = null; 75 76 79 private static String [] initializers = null; 80 81 84 private static JRMPInitInfoImpl jrmpInfo = new JRMPInitInfoImpl(); 85 86 89 static { 90 try { 92 JInitInfo jrmpInfo = new JRMPInitInfoImpl(); 93 String [] 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 rcis = cis; 104 uid = JInterceptorHelper.getSpaceID(); 105 address = JInterceptorHelper.getInetAddress(); 106 } catch (Exception e) { 107 TraceCarol.error("JrmpPRODelegate(), No interceptors found", e); 109 } 110 } 111 112 115 public static JServerRequestInterceptor[] getLocalServerInterceptors() { 116 return sis; 117 } 118 119 122 public static JClientRequestInterceptor[] getLocalClientInterceptors() { 123 return cis; 124 } 125 126 130 public synchronized static String [] getJRMPInitializers() { 131 if (initializers != null) { 133 return initializers; 134 } 135 ArrayList ins = new ArrayList (); 137 Properties sys = System.getProperties(); 138 for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { 139 String pkey = (String ) 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 [sz]; 146 for (int i = 0; i < sz; i++) { 147 initializers[i] = (String ) ins.get(i); 148 } 149 return initializers; 150 } 151 152 159 public synchronized static JClientRequestInterceptor[] setRemoteInterceptors(byte[] raddr, UID ruid, String [] 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 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 |