1 27 package ch.ethz.prose; 28 29 import java.lang.reflect.Constructor ; 31 import java.security.AccessControlException ; 32 import java.security.AccessController ; 33 import java.security.PrivilegedActionException ; 34 import java.security.PrivilegedExceptionAction ; 35 import java.util.StringTokenizer ; 36 37 import ch.ethz.jvmai.JVMAspectInterface; 38 import ch.ethz.inf.util.Logger; 39 40 79 public class ProseSystem implements Component { 80 81 static private AspectManager currentExtM = null; 82 static private AspectManager testExtM = null; 83 static private JVMAspectInterface aspectInterface = null; 84 static boolean systemUp = false; 85 static ProsePermission permission = new ProsePermission("startupExtensionSystem"); 86 87 static ch.ethz.jvmai.Provider provider = null; 89 static String [] packagePrefixes = null; 90 static boolean openWorldAssumption; 91 92 93 109 public synchronized static void startup() throws SystemStartupException 110 { 111 if (systemUp) 112 return; 113 114 if (!System.getProperty("prose.port","UNKNOWN").equals("UNKNOWN")) 117 ch.ethz.prose.tools.RemoteProseComponent.startup(); 118 try { Thread.currentThread().sleep(500); } catch (InterruptedException e) {} 119 120 try { 121 124 AccessController.doPrivileged(new PrivilegedExceptionAction () { 126 public Object run() throws SystemStartupException { 127 doStartup(); 128 return null; 129 } 130 }); 131 132 } catch (AccessControlException e) { 133 doStartup(); 135 136 } catch (PrivilegedActionException e) { 137 e.printStackTrace(); 138 throw new SystemStartupException(e.toString()); 139 } 140 141 146 147 systemUp=true; 148 } 149 150 153 private synchronized static void doStartup() throws SystemStartupException 154 { 155 156 try 157 { 158 159 String providerClassName = System.getProperty("ch.ethz.prose.JVMAIProvider"); 161 if(providerClassName==null) 162 providerClassName = "ch.ethz.inf.iks.jvmai.jvmdi.DebuggerProvider"; 163 164 Class providerClass = Class.forName(providerClassName); 165 provider = (ch.ethz.jvmai.Provider)providerClass.newInstance(); 166 167 packagePrefixes = new String [0]; 168 openWorldAssumption = true; 169 170 String packageList = System.getProperty("ch.ethz.prose.JVMAIPackagePrefixes"); 171 String openWorldParam = System.getProperty("ch.ethz.prose.JVMAIOpenWorldAssumption"); 172 173 if(packageList==null && openWorldParam==null) 174 { 175 packagePrefixes = new String [] {"ch.ethz.prose."}; 176 openWorldAssumption = true; 177 } 178 else 179 { 180 if(packageList==null) 181 { 182 packagePrefixes = new String [0]; 183 } 184 else 185 { 186 StringTokenizer tokenizer = new StringTokenizer (packageList,","); 187 packagePrefixes = new String [tokenizer.countTokens()]; 188 for(int p=0; p<packagePrefixes.length; p++) { 189 packagePrefixes[p] = tokenizer.nextToken(); 190 } 191 } 192 if(openWorldParam==null) 193 { 194 openWorldAssumption = true; 195 } 196 else 197 { 198 openWorldAssumption = openWorldParam.toUpperCase().equals("TRUE"); 199 } 200 201 } 202 aspectInterface = provider.getAspectInterface(); 204 205 aspectInterface.startup(packagePrefixes,openWorldAssumption); 207 208 aspectInterface.suspendNotification(Thread.currentThread()); 209 210 String extMName = System.getProperty("ch.ethz.prose.EXManager"); 212 if (extMName != null) 213 { 214 Class [] paramTypes = new Class [] {boolean.class, JVMAspectInterface.class}; 215 Object [] params = new Object [] {Boolean.TRUE, aspectInterface}; 216 Class extMClass = Class.forName(extMName); 217 Constructor extMConstructor = extMClass.getConstructor(paramTypes); 218 currentExtM = (AspectManager)extMConstructor.newInstance(params); 219 params[0] = Boolean.FALSE; 220 testExtM = (AspectManager)extMConstructor.newInstance(params); 221 } 222 else 223 { 224 currentExtM = new LocalAspectManager(true, aspectInterface); 225 testExtM = new LocalAspectManager(false, aspectInterface); 226 } 227 currentExtM.startup(); 228 testExtM.startup(); 229 230 systemUp = true; 231 } 232 catch(Throwable e) 233 { 234 e.printStackTrace(); 235 if (currentExtM != null) 236 { 237 currentExtM.teardown(); 238 currentExtM = null; 239 } 240 241 if (testExtM != null) 242 { 243 currentExtM.teardown(); 244 testExtM = null; 245 } 246 if (aspectInterface != null) 247 aspectInterface.teardown(); 248 aspectInterface = null; 249 250 if (e instanceof SystemStartupException) 251 throw (SystemStartupException)e; 252 253 throw new SystemStartupException(e.toString()); 254 } 255 finally 256 { 257 if (aspectInterface != null) 259 aspectInterface.resumeNotification(Thread.currentThread()); 260 } 261 Logger.message("ProseComponent.startup: succeeded! "); 262 } 263 264 265 274 public static void teardown() throws SystemTeardownException 275 { 276 if (!systemUp) 277 return; 278 if (getAspectManager() != null) 279 { 280 currentExtM.teardown(); 281 currentExtM = null; 282 } 283 284 if (getTestAspectManager() != null) 285 { 286 testExtM.teardown(); 287 testExtM = null; 288 } 289 290 if (aspectInterface != null) 291 aspectInterface.teardown(); 292 293 aspectInterface = null; 294 295 systemUp = false; 296 } 297 298 299 303 public static boolean isActive() 304 { 305 306 return systemUp; 307 } 308 309 310 313 public static AspectManager getAspectManager() 314 { 315 try { startup(); } catch (Exception e) {} 316 return currentExtM; 317 } 318 319 323 public static AspectManager getTestAspectManager() 324 { 325 try { startup(); } catch (Exception e) {} 326 return testExtM; 327 } 328 } 329 330 331 332 333
| Popular Tags
|