1 package org.enhydra.shark.corba; 2 3 6 import java.util.Properties ; 7 8 import org.enhydra.shark.Shark; 9 import org.enhydra.shark.api.client.wfbase.BaseException; 10 import org.enhydra.shark.corba.WorkflowService.*; 11 import org.enhydra.shark.utilities.DeadlineChecker; 12 import org.enhydra.shark.utilities.LimitChecker; 13 import org.omg.CORBA.ORB ; 14 import org.omg.CosNaming.*; 15 import org.omg.CosNaming.NamingContextPackage.*; 16 import org.omg.WfBase.NameValueInfo; 17 import org.omg.WorkflowModel.WfCreateProcessEventAudit; 18 import org.omg.WorkflowModel.WfDataEventAudit; 19 import org.omg.WorkflowModel.WfStateEventAudit; 20 import org.omg.WorkflowModel._WfCreateProcessEventAuditStub; 21 import org.omg.WorkflowModel._WfDataEventAuditStub; 22 import org.omg.WorkflowModel._WfStateEventAuditStub; 23 24 33 public class SharkCORBAServer extends _SharkInterfaceImplBase { 34 35 private org.enhydra.shark.Shark shark; 36 37 private ORB orb; 38 39 private String engineName; 40 41 private String nsHost; 42 43 private String nsPort; 44 45 boolean trackObjects; 46 47 public SharkCORBAServer(String engineName, 48 String nsHost, 49 String nsPort, 50 Shark shark) { 51 if (engineName == null) throw new IllegalArgumentException ("Engine name cannot be null"); 53 if (nsHost == null) throw new IllegalArgumentException ("Name server host cannot be null"); 54 if (nsPort == null) throw new IllegalArgumentException ("Name server port cannot be null"); 55 if (shark == null) throw new IllegalArgumentException ("Shark instance cannot be null"); 56 57 this.engineName = engineName; 58 this.nsHost = nsHost; 59 this.nsPort = nsPort; 60 this.shark = shark; 61 this.trackObjects = Boolean.valueOf(shark.getProperties() 62 .getProperty("CORBAServer.TrackAndDisconnect", "false")).booleanValue(); 63 boolean ignoreProblematicRequester=new Boolean (shark.getProperties().getProperty("CORBAServer.ignoreProblematicRequester","true")).booleanValue(); 64 WfLinkingRequesterForCORBA.setIgnoreProblematicRequesterProcess(ignoreProblematicRequester); 65 66 67 Runtime.getRuntime().addShutdownHook(new Thread () { 69 public void run() { 70 shutdownORB(); 71 if (null != p) { 72 p.destroy(); 73 } 74 } 75 }); 76 } 77 78 public void startCORBAServer() throws BaseException { 79 String [] a1 = { 81 "-ORBInitialHost", nsHost, "-ORBInitialPort", nsPort 82 }; 83 String [] a2 = { 84 "-ORBInitRef", 85 "NameService=corbaloc::" 86 + nsHost + ":" + nsPort 87 + "/NameService" 88 }; 89 90 String vers = System.getProperty("java.version"); 92 if (vers.compareTo("1.4") < 0) { 93 orb = ORB.init(a1, null); 94 } else { 95 orb = ORB.init(a2, null); 96 } 97 org.omg.CORBA.Object objRef = null; 99 try { 100 objRef = orb.resolve_initial_references("NameService"); 101 } catch (Exception ex) { 102 for (int i = 0; i < 25; i++) { 107 108 try { 109 Thread.sleep(2500); 110 objRef = orb.resolve_initial_references("NameService"); 111 } catch (Exception ex2) {} 112 if (objRef != null) { 113 break; 114 } 115 } 116 } 117 118 if (objRef == null) { throw new BaseException("Unable to obtain initial reference from orb"); } 120 121 NamingContext ncRef = NamingContextHelper.narrow(objRef); 123 if (ncRef == null) { throw new BaseException("Null NamingContext"); } 124 125 NameComponent nc = new NameComponent(engineName, ""); 127 NameComponent path[] = { 128 nc 129 }; 130 try { 131 ncRef.rebind(path, this); 132 } catch (NotFound e) { 133 throw new BaseException(e); 134 } catch (CannotProceed e) { 135 throw new BaseException(e); 136 } catch (InvalidName e) { 137 throw new BaseException(e); 138 } 139 140 orb.run(); 144 } 145 146 public ORB getBoundORB() { 147 return orb; 148 } 149 150 public void shutdownORB() { 151 try { 152 orb.disconnect(this); 153 orb.shutdown(false); 154 } catch (Exception e) { 155 } 157 } 158 159 void shutdown() { 160 shutdownORB(); 161 System.exit(0); 162 } 163 164 public AdminMisc getAdminMisc() { 165 return new AdminMiscCORBA(this, shark.getAdminInterface() 166 .getAdminMisc()); 167 } 168 169 public ExecutionAdministration getExecutionAdministration() { 170 return new ExecutionAdminCORBA(this, shark.getAdminInterface() 171 .getExecutionAdministration()); 172 } 173 174 public MappingAdministration getMappingAdministration() { 175 return new MappingAdminCORBA(this, shark.getAdminInterface() 176 .getParticipantMappingAdministration(), shark.getAdminInterface() 177 .getApplicationMappingAdministration()); 178 } 179 180 public PackageAdministration getPackageAdministration() { 181 return new PackageAdminCORBA(this, shark.getAdminInterface() 182 .getPackageAdministration()); 183 } 184 185 public UserGroupAdministration getUserGroupAdministration() { 186 return new UserGroupAdminCORBA(this, shark.getAdminInterface() 187 .getUserGroupAdministration()); 188 } 189 190 public CacheAdministration getCacheAdministration() { 191 return new CacheAdminCORBA(this, shark.getAdminInterface() 192 .getCacheAdministration()); 193 } 194 195 public DeadlineAdministration getDeadlineAdministration() { 196 return new DeadlineAdminCORBA(this, shark.getAdminInterface() 197 .getDeadlineAdministration()); 198 } 199 200 public LimitAdministration getLimitAdministration() { 201 return new LimitAdminCORBA(this, shark.getAdminInterface() 202 .getLimitAdministration()); 203 } 204 205 public RepositoryMgr getRepositoryManager() { 206 return new RepositoryManagerCORBA(this, shark.getRepositoryManager()); 207 } 208 209 public SharkConnection getSharkConnection() { 210 return new SharkConnectionCORBA(this, shark.getSharkConnection()); 211 } 212 213 public ExpressionBuilderManager getExpressionBuilderManager() { 214 return new ExpressionBuilderMgrCORBA(this, shark.getExpressionBuilderManager()); 215 } 216 217 public NameValueInfo[] getProperties() { 218 return SharkCORBAUtilities.makeCORBANameValueInfoArray(shark.getProperties()); 219 } 220 221 boolean validateUser(String username, String pwd) { 222 try { 223 return shark.validateUser(username, pwd); 224 } catch (Exception ex) { 225 return true; 226 } 227 } 228 229 private static Process p; 230 231 private static long nameserverRestart_ms = 0; 232 233 public static void main(String args[]) { 236 try { 237 if (args != null && args.length > 0) { 238 Shark.configure(args[0]); 239 } else { 240 Shark.configure(); 241 } 242 243 org.enhydra.shark.Shark shark = Shark.getInstance(); 244 245 Properties properties = shark.getProperties(); 246 String nameserverhost = properties.getProperty("nameserverhost", 247 "localhost"); 248 final String nameserverport = properties.getProperty("nameserverport", 249 "10123"); 250 String enginename = properties.getProperty("enginename", "Shark"); 251 final String nameServerExecutable = properties.getProperty("nameserver.executable", 252 null); 253 String nameserverRestart = properties.getProperty("nameserver.restarting_period_minutes", 254 "0"); 255 256 double nsrmin = 0; 257 try { 258 nsrmin = Double.parseDouble(nameserverRestart); 259 nameserverRestart_ms = (long) (nsrmin * 60 * 1000); 260 } catch (Exception ex) {} 261 try { 263 org.enhydra.shark.api.client.wfservice.UserGroupAdministration uga = shark.getAdminInterface() 264 .getUserGroupAdministration(); 265 String adminGroup = properties.getProperty("DEFAULT_ADMINISTRATOR_GROUP_NAME", 266 "AdminGroup"); 267 String adminGroupDescripton = properties.getProperty("DEFAULT_ADMINISTRATOR_GROUP_DESCRIPTION", 268 "Default Admin Group"); 269 String adminUsername = properties.getProperty("DEFAULT_ADMINISTRATOR_USERNAME", 270 "admin"); 271 String adminPwd = properties.getProperty("DEFAULT_ADMINISTRATOR_PASSWORD", 272 "enhydra"); 273 String adminFirstName = properties.getProperty("DEFAULT_ADMINISTRATOR_FIRST_NAME", 274 "Administrator"); 275 String adminLastName = properties.getProperty("DEFAULT_ADMINISTRATOR_LAST_NAME", 276 "Admin"); 277 String adminEmail = properties.getProperty("DEFAULT_ADMINISTRATOR_EMAIL", 278 "admin@together.at"); 279 try { 280 if (!uga.doesGroupExist(adminGroup)) { 281 uga.createGroup(adminGroup, adminGroupDescripton); 282 } 283 } catch (Exception ex) {} 284 if (!uga.doesUserExist(adminUsername)) { 285 uga.createUser(adminGroup, 286 adminUsername, 287 adminPwd, 288 adminFirstName, 289 adminLastName, 290 adminEmail); 291 } 292 } catch (Exception ex) {} 293 294 String delay = null; 296 if (args != null && args.length > 1) { 297 delay = args[1]; 298 } else { 299 delay = properties.getProperty("Deadlines.pollingTime", "300000"); 300 } 301 if (properties.getProperty("Deadlines.SERVER_SIDE_CHECKING", "false") 302 .equals("true")) { 303 new DeadlineChecker(shark.getAdminInterface() 304 .getDeadlineAdministration(), Long.parseLong(delay)); 305 } 306 307 String ldelay = null; 309 String lacn = properties.getProperty("LimitAgentManagerClassName"); 310 if (lacn != null) { 311 if (args != null && args.length > 2) { 312 ldelay = args[2]; 313 } else { 314 ldelay = properties.getProperty("Limits.pollingTime", "60000"); 315 } 316 if (properties.getProperty("Limits.SERVER_SIDE_CHECKING", "false") 317 .equals("true")) { 318 new LimitChecker(shark.getAdminInterface() 319 .getLimitAdministration(), Long.parseLong(ldelay)); 320 } 321 } 322 323 final SharkCORBAServer ws = new SharkCORBAServer(enginename, 325 nameserverhost, 326 nameserverport, 327 shark); 328 if (null != nameServerExecutable) { 329 if (nameserverRestart_ms > 0) { 330 System.out.println("Nameserver will be restarted every " 331 + nameserverRestart + " minutes!"); 332 } 333 334 new Thread () { 335 public void run() { 336 while (true) { 337 try { 338 p = Runtime.getRuntime().exec(nameServerExecutable 339 + " -ORBInitialPort " 340 + nameserverport); 341 342 System.out.println("Nameserver is (re)started!"); 343 new Thread () { 346 public void run() { 347 try { 348 ws.startCORBAServer(); 349 } catch (Exception ex) { 350 ex.printStackTrace(System.out); 351 throw new Error (); 352 353 } 354 } 355 }.start(); 356 if (nameserverRestart_ms > 0) { 357 new Thread () { 358 public void run() { 359 try { 360 Thread.sleep(nameserverRestart_ms); 361 } catch (Exception ex) {} finally { 362 p.destroy(); 363 } 364 } 365 }.start(); 366 } 367 368 } catch (Throwable t) { 369 t.printStackTrace(); 370 System.out.println("Didn't start the nameserver"); 371 } 374 375 while (true) { 376 try { 377 p.waitFor(); 378 } catch (InterruptedException e) { 379 continue; 380 } 381 382 break; 384 } 385 } 386 } 387 }.start(); 388 } else { 389 ws.startCORBAServer(); 390 } 391 392 } catch (Throwable e) { 393 e.printStackTrace(System.out); 394 throw new Error (); 395 } 396 } 397 398 public void doneWith(org.omg.CORBA.Object toDisconnect) { 399 if (toDisconnect instanceof Collective) { 400 ((Collective)toDisconnect).__disband(orb); 401 } else { 402 try { 403 if (toDisconnect instanceof WfCreateProcessEventAudit) { 404 WfLinkingRequesterForCORBA.emptyCollective(((WfCreateProcessEventAudit)toDisconnect).process_key(),getBoundORB()); 405 } 406 if (toDisconnect instanceof WfDataEventAudit) { 407 WfLinkingRequesterForCORBA.emptyCollective(((WfDataEventAudit)toDisconnect).process_key(),getBoundORB()); 408 } 409 if (toDisconnect instanceof WfStateEventAudit) { 410 WfLinkingRequesterForCORBA.emptyCollective(((WfStateEventAudit)toDisconnect).process_key(),getBoundORB()); 411 } 412 orb.disconnect(toDisconnect); 413 } catch (Exception ex) { 414 } 415 } 416 } 417 } 418 419 | Popular Tags |