1 package org.enhydra.shark.corba.poa; 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.corba.poa.*; 12 import org.omg.WorkflowModel.*; 13 import org.enhydra.shark.utilities.DeadlineChecker; 14 import org.enhydra.shark.utilities.LimitChecker; 15 import org.omg.CORBA.ORB ; 16 import org.omg.CORBA.Policy ; 17 import org.omg.CosNaming.*; 19 import org.omg.CosNaming.NamingContextPackage.*; 20 import org.omg.WfBase.NameValueInfo; 22 import org.omg.PortableServer.POAPackage.*; 23 import org.omg.PortableServer.POAManagerPackage.AdapterInactive ; 24 import org.omg.PortableServer.*; 25 26 27 37 public class SharkCORBAServer extends SharkInterfacePOA { 38 39 private org.enhydra.shark.Shark shark; 40 41 private ORB orb; 42 43 private String engineName; 44 45 private String nsHost; 46 47 private String nsPort; 48 49 boolean trackObjects; 50 51 private POA rootPOA; 52 private AdminMisc adminMisc = null; 53 private ExecutionAdministration executionAdmin = null; 54 private MappingAdministration mappingAdmin = null; 55 private PackageAdministration packageAdmin = null; 56 private UserGroupAdministration userGroupAdmin = null; 57 private CacheAdministration cacheAdmin = null; 58 private DeadlineAdministration deadlineAdmin = null; 59 private LimitAdministration limitAdmin = null; 60 private RepositoryMgr repositoryMgr = null; 61 private SharkConnection connect = null; 62 private ExpressionBuilderManager express = null; 63 64 public SharkCORBAServer(String engineName, 65 String nsHost, 66 String nsPort, 67 Shark shark) { 68 if (engineName == null) throw new IllegalArgumentException ("Engine name cannot be null"); 70 if (nsHost == null) throw new IllegalArgumentException ("Name server host cannot be null"); 71 if (nsPort == null) throw new IllegalArgumentException ("Name server port cannot be null"); 72 if (shark == null) throw new IllegalArgumentException ("Shark instance cannot be null"); 73 74 this.engineName = engineName; 75 this.nsHost = nsHost; 76 this.nsPort = nsPort; 77 this.shark = shark; 78 this.trackObjects = Boolean.valueOf(shark.getProperties() 79 .getProperty("CORBAServer.TrackAndDisconnect", "false")).booleanValue(); 80 boolean ignoreProblematicRequester = new Boolean (shark.getProperties().getProperty("CORBAServer.ignoreProblematicRequester", "true")).booleanValue(); 81 WfLinkingRequesterForCORBA.setIgnoreProblematicRequesterProcess(ignoreProblematicRequester); 82 83 84 Runtime.getRuntime().addShutdownHook(new Thread () { 86 public void run() { 87 shutdownORB(); 88 if (null != p) { 89 p.destroy(); 90 } 91 } 92 }); 93 } 94 95 public void startCORBAServer() throws BaseException { 96 String [] a1 = { 98 "-ORBInitialHost", nsHost, "-ORBInitialPort", nsPort 99 }; 100 String [] a2 = { 101 "-ORBInitRef", 102 "NameService=corbaloc::" 103 + nsHost + ":" + nsPort 104 + "/NameService" 105 }; 106 107 String vers = System.getProperty("java.version"); 109 System.out.println("java.version " + vers); 110 if (vers.compareTo("1.4") < 0) { 111 orb = ORB.init(a1, null); 112 } else { 113 orb = ORB.init(a2, null); 114 } 115 try { 117 rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 118 125 } catch (org.omg.CORBA.ORBPackage.InvalidName invalidName) { 127 invalidName.printStackTrace(); } 137 org.omg.CORBA.Object objRef = null; 141 try { 142 objRef = orb.resolve_initial_references("NameService"); 143 } catch (Exception ex) { 144 System.err.println("startCORBAServer: " + ex); 145 for (int i = 0; i < 2; i++) { 150 151 try { 152 Thread.sleep(2500); 153 objRef = orb.resolve_initial_references("NameService"); 154 } catch (Exception ex2) { 155 System.err.println("NameService failed " + ex2); 156 } 157 if (objRef != null) { 158 break; 159 } 160 } 161 } 162 163 if (objRef == null) { 165 throw new BaseException("Unable to obtain initial reference from orb"); 166 } 167 168 NamingContext ncRef = NamingContextHelper.narrow(objRef); 170 if (ncRef == null) { 171 throw new BaseException("Null NamingContext"); 172 } else System.out.println("NameService contacted"); 173 NameComponent nc = new NameComponent(engineName, ""); 175 NameComponent path[] = { 176 nc 177 }; 178 try { 179 rootPOA.the_POAManager().activate(); 180 rootPOA.activate_object(this); 181 SharkCORBAUtilities.setPOA(rootPOA); 182 SharkCORBAUtilities.setORB(orb); 183 ncRef.rebind(path, this._this_object()); 184 185 System.out.println("CORBA Server registered and activated"); 186 } catch (NotFound e) { 187 throw new BaseException(e); 188 } catch (CannotProceed e) { 189 throw new BaseException(e); 190 } catch (InvalidName e) { 191 throw new BaseException(e); 192 } catch (AdapterInactive adapterInactive) { 193 adapterInactive.printStackTrace(); 194 } catch (ServantAlreadyActive es) { 195 es.printStackTrace(); 196 } catch (WrongPolicy wp) { 197 wp.printStackTrace(); 198 } 199 orb.run(); 203 } 204 205 public ORB getBoundORB() { 206 return orb; 207 } 208 209 public void shutdownORB() { 210 try { 211 orb.disconnect(this._this_object()); 212 orb.shutdown(false); 213 } catch (Exception e) { 214 } 216 } 217 218 void shutdown() { 219 shutdownORB(); 220 System.exit(0); 221 } 222 223 public AdminMisc getAdminMisc() { 224 AdminMiscCORBA adminMiscImpl = new AdminMiscCORBA(this, shark.getAdminInterface() 226 .getAdminMisc()); 227 228 229 230 try { 231 byte[] o = rootPOA.activate_object(adminMiscImpl); 232 adminMisc = AdminMiscHelper.narrow(rootPOA.id_to_reference(o)); 233 234 } catch (ServantAlreadyActive servantAlreadyActive) { 235 servantAlreadyActive.printStackTrace(); 236 } catch (WrongPolicy wrongPolicy) { 237 wrongPolicy.printStackTrace(); 238 } catch (ObjectNotActive objectNotActive) { 239 objectNotActive.printStackTrace(); 240 } 241 242 return adminMisc; 243 } 244 245 public ExecutionAdministration getExecutionAdministration() { 246 247 ExecutionAdminCORBA executionAdminImpl = new ExecutionAdminCORBA(this, shark.getAdminInterface() 249 .getExecutionAdministration()); 250 251 try { 252 rootPOA.activate_object(executionAdminImpl); 253 executionAdmin = ExecutionAdministrationHelper.narrow(rootPOA.servant_to_reference(executionAdminImpl)); 254 255 } catch (ServantAlreadyActive servantAlreadyActive) { 256 servantAlreadyActive.printStackTrace(); 257 } catch (WrongPolicy wrongPolicy) { 258 wrongPolicy.printStackTrace(); 259 } catch (ServantNotActive servantNotActive) { 260 servantNotActive.printStackTrace(); 261 } 262 263 return executionAdmin; 264 } 265 266 public MappingAdministration getMappingAdministration() { 267 268 MappingAdminCORBA mappingAdminImpl = new MappingAdminCORBA(this, shark.getAdminInterface() 270 .getParticipantMappingAdministration(), shark.getAdminInterface() 271 .getApplicationMappingAdministration()); 272 273 try { 274 rootPOA.activate_object(mappingAdminImpl); 275 mappingAdmin = MappingAdministrationHelper.narrow(rootPOA.servant_to_reference(mappingAdminImpl)); 276 277 } catch (ServantAlreadyActive servantAlreadyActive) { 278 servantAlreadyActive.printStackTrace(); 279 } catch (WrongPolicy wrongPolicy) { 280 wrongPolicy.printStackTrace(); 281 } catch (ServantNotActive servantNotActive) { 282 servantNotActive.printStackTrace(); 283 } 284 285 return mappingAdmin; 286 287 } 288 289 public PackageAdministration getPackageAdministration() { 290 PackageAdminCORBA packageAdminImpl = new PackageAdminCORBA(this, shark.getAdminInterface() 292 .getPackageAdministration()); 293 294 try { 295 rootPOA.activate_object(packageAdminImpl); 296 packageAdmin = PackageAdministrationHelper.narrow(rootPOA.servant_to_reference(packageAdminImpl)); 297 298 } catch (ServantAlreadyActive servantAlreadyActive) { 299 servantAlreadyActive.printStackTrace(); 300 } catch (WrongPolicy wrongPolicy) { 301 wrongPolicy.printStackTrace(); 302 } catch (ServantNotActive servantNotActive) { 303 servantNotActive.printStackTrace(); 304 } 305 306 return packageAdmin; 307 308 } 309 310 public UserGroupAdministration getUserGroupAdministration() { 311 UserGroupAdminCORBA userGroupAdminImpl = new UserGroupAdminCORBA(this, shark.getAdminInterface() 313 .getUserGroupAdministration()); 314 315 try { 316 rootPOA.activate_object(userGroupAdminImpl); 317 userGroupAdmin = UserGroupAdministrationHelper.narrow(rootPOA.servant_to_reference(userGroupAdminImpl)); 318 319 } catch (ServantAlreadyActive servantAlreadyActive) { 320 servantAlreadyActive.printStackTrace(); 321 } catch (WrongPolicy wrongPolicy) { 322 wrongPolicy.printStackTrace(); 323 } catch (ServantNotActive servantNotActive) { 324 servantNotActive.printStackTrace(); 325 } 326 327 return userGroupAdmin; 328 } 329 330 public CacheAdministration getCacheAdministration() { 331 332 CacheAdminCORBA cacheAdminImpl = new CacheAdminCORBA(this, shark.getAdminInterface() 334 .getCacheAdministration()); 335 336 try { 337 rootPOA.activate_object(cacheAdminImpl); 338 cacheAdmin = CacheAdministrationHelper.narrow(rootPOA.servant_to_reference(cacheAdminImpl)); 339 340 } catch (ServantAlreadyActive servantAlreadyActive) { 341 servantAlreadyActive.printStackTrace(); 342 } catch (WrongPolicy wrongPolicy) { 343 wrongPolicy.printStackTrace(); 344 } catch (ServantNotActive servantNotActive) { 345 servantNotActive.printStackTrace(); 346 } 347 348 return cacheAdmin; 349 } 350 351 public DeadlineAdministration getDeadlineAdministration() { 352 353 DeadlineAdminCORBA deadlineAdminImpl = new DeadlineAdminCORBA(this, shark.getAdminInterface() 355 .getDeadlineAdministration()); 356 357 try { 358 rootPOA.activate_object(deadlineAdminImpl); 359 deadlineAdmin = DeadlineAdministrationHelper.narrow(rootPOA.servant_to_reference(deadlineAdminImpl)); 360 361 } catch (ServantAlreadyActive servantAlreadyActive) { 362 servantAlreadyActive.printStackTrace(); 363 } catch (WrongPolicy wrongPolicy) { 364 wrongPolicy.printStackTrace(); 365 } catch (ServantNotActive servantNotActive) { 366 servantNotActive.printStackTrace(); 367 } 368 369 return deadlineAdmin; 370 } 371 372 public LimitAdministration getLimitAdministration() { 373 LimitAdminCORBA limitAdminImpl = new LimitAdminCORBA(this, shark.getAdminInterface() 375 .getLimitAdministration()); 376 377 try { 378 rootPOA.activate_object(limitAdminImpl); 379 limitAdmin = LimitAdministrationHelper.narrow(rootPOA.servant_to_reference(limitAdminImpl)); 380 381 } catch (ServantAlreadyActive servantAlreadyActive) { 382 servantAlreadyActive.printStackTrace(); 383 } catch (WrongPolicy wrongPolicy) { 384 wrongPolicy.printStackTrace(); 385 } catch (ServantNotActive servantNotActive) { 386 servantNotActive.printStackTrace(); 387 } 388 389 return limitAdmin; 390 } 391 392 public RepositoryMgr getRepositoryManager() { 393 394 RepositoryManagerCORBA repositoryManagerImpl = new RepositoryManagerCORBA(this, shark.getRepositoryManager()); 396 397 try { 398 rootPOA.activate_object(repositoryManagerImpl); 399 repositoryMgr = RepositoryMgrHelper.narrow(rootPOA.servant_to_reference(repositoryManagerImpl)); 400 401 } catch (ServantAlreadyActive servantAlreadyActive) { 402 servantAlreadyActive.printStackTrace(); 403 } catch (WrongPolicy wrongPolicy) { 404 wrongPolicy.printStackTrace(); 405 } catch (ServantNotActive servantNotActive) { 406 servantNotActive.printStackTrace(); 407 } 408 409 return repositoryMgr; 410 } 411 412 public SharkConnection getSharkConnection() { 413 414 SharkConnectionCORBA connectImpl = new SharkConnectionCORBA(this, shark.getSharkConnection()); 416 try { 417 rootPOA.activate_object(connectImpl); 418 connect = SharkConnectionHelper.narrow(rootPOA.servant_to_reference(connectImpl)); 419 420 } catch (ServantAlreadyActive servantAlreadyActive) { 421 servantAlreadyActive.printStackTrace(); 422 } catch (WrongPolicy wrongPolicy) { 423 wrongPolicy.printStackTrace(); 424 } catch (ServantNotActive servantNotActive) { 425 servantNotActive.printStackTrace(); 426 } 427 428 return connect; 429 } 431 432 public ExpressionBuilderManager getExpressionBuilderManager() { 433 434 ExpressionBuilderMgrCORBA expressionBuilderMgrImpl = new ExpressionBuilderMgrCORBA(this, shark.getExpressionBuilderManager()); 436 437 try { 438 rootPOA.activate_object(expressionBuilderMgrImpl); 439 express = ExpressionBuilderManagerHelper.narrow(rootPOA.servant_to_reference(expressionBuilderMgrImpl)); 440 if (express == null) System.err.println("getExpressBuilderManager: " + express); 441 } catch (ServantAlreadyActive servantAlreadyActive) { 442 servantAlreadyActive.printStackTrace(); 443 } catch (WrongPolicy wrongPolicy) { 444 wrongPolicy.printStackTrace(); 445 } catch (ServantNotActive servantNotActive) { 446 servantNotActive.printStackTrace(); 447 } 448 449 return express; 450 } 451 452 public NameValueInfo[] getProperties() { 453 return SharkCORBAUtilities.makeCORBANameValueInfoArray(shark.getProperties()); 454 } 455 456 boolean validateUser(String username, String pwd) { 457 try { 458 return shark.validateUser(username, pwd); 459 } catch (Exception ex) { 460 return true; 461 } 462 } 463 464 private static Process p; 465 466 private static long nameserverRestart_ms = 0; 467 468 public static void main(String args[]) { 471 try { 472 if (args != null && args.length > 0) { 473 Shark.configure(args[0]); 474 } else { 475 Shark.configure(); 476 } 477 478 org.enhydra.shark.Shark shark = Shark.getInstance(); 479 480 Properties properties = shark.getProperties(); 481 String nameserverhost = properties.getProperty("nameserverhost", 482 "localhost"); 483 final String nameserverport = properties.getProperty("nameserverport", 484 "10123"); 485 String enginename = properties.getProperty("enginename", "Shark"); 486 final String nameServerExecutable = properties.getProperty("nameserver.executable", 487 null); 488 String nameserverRestart = properties.getProperty("nameserver.restarting_period_minutes", 489 "0"); 490 491 double nsrmin = 0; 492 try { 493 nsrmin = Double.parseDouble(nameserverRestart); 494 nameserverRestart_ms = (long) (nsrmin * 60 * 1000); 495 } catch (Exception ex) { 496 } 497 try { 499 org.enhydra.shark.api.client.wfservice.UserGroupAdministration uga = shark.getAdminInterface() 500 .getUserGroupAdministration(); 501 String adminGroup = properties.getProperty("DEFAULT_ADMINISTRATOR_GROUP_NAME", 502 "AdminGroup"); 503 String adminGroupDescripton = properties.getProperty("DEFAULT_ADMINISTRATOR_GROUP_DESCRIPTION", 504 "Default Admin Group"); 505 String adminUsername = properties.getProperty("DEFAULT_ADMINISTRATOR_USERNAME", 506 "admin"); 507 String adminPwd = properties.getProperty("DEFAULT_ADMINISTRATOR_PASSWORD", 508 "enhydra"); 509 String adminFirstName = properties.getProperty("DEFAULT_ADMINISTRATOR_FIRST_NAME", 510 "Administrator"); 511 String adminLastName = properties.getProperty("DEFAULT_ADMINISTRATOR_LAST_NAME", 512 "Admin"); 513 String adminEmail = properties.getProperty("DEFAULT_ADMINISTRATOR_EMAIL", 514 "admin@together.at"); 515 try { 516 if (!uga.doesGroupExist(adminGroup)) { 517 uga.createGroup(adminGroup, adminGroupDescripton); 518 } 519 } catch (Exception ex) { 520 } 521 if (!uga.doesUserExist(adminUsername)) { 522 uga.createUser(adminGroup, 523 adminUsername, 524 adminPwd, 525 adminFirstName, 526 adminLastName, 527 adminEmail); 528 } 529 } catch (Exception ex) { 530 } 531 532 String delay = null; 534 if (args != null && args.length > 1) { 535 delay = args[1]; 536 } else { 537 delay = properties.getProperty("Deadlines.pollingTime", "300000"); 538 } 539 if (properties.getProperty("Deadlines.SERVER_SIDE_CHECKING", "false") 540 .equals("true")) { 541 new DeadlineChecker(shark.getAdminInterface() 542 .getDeadlineAdministration(), Long.parseLong(delay)); 543 } 544 545 String ldelay = null; 547 String lacn = properties.getProperty("LimitAgentManagerClassName"); 548 if (lacn != null) { 549 if (args != null && args.length > 2) { 550 ldelay = args[2]; 551 } else { 552 ldelay = properties.getProperty("Limits.pollingTime", "60000"); 553 } 554 if (properties.getProperty("Limits.SERVER_SIDE_CHECKING", "false") 555 .equals("true")) { 556 new LimitChecker(shark.getAdminInterface() 557 .getLimitAdministration(), Long.parseLong(ldelay)); 558 } 559 } 560 561 final SharkCORBAServer ws = new SharkCORBAServer(enginename, 563 nameserverhost, 564 nameserverport, 565 shark); 566 if (null != nameServerExecutable) { 567 if (nameserverRestart_ms > 0) { 568 System.out.println("Nameserver will be restarted every " 569 + nameserverRestart + " minutes!"); 570 } 571 572 new Thread () { 573 public void run() { 574 while (true) { 575 try { 576 p = Runtime.getRuntime().exec(nameServerExecutable 577 + " -ORBInitialPort " 578 + nameserverport); 579 580 System.out.println("Nameserver is (re)started!"); 581 new Thread () { 584 public void run() { 585 try { 586 ws.startCORBAServer(); 587 } catch (Exception ex) { 588 ex.printStackTrace(System.out); 589 throw new Error (); 590 591 } 592 } 593 }.start(); 594 if (nameserverRestart_ms > 0) { 595 new Thread () { 596 public void run() { 597 try { 598 Thread.sleep(nameserverRestart_ms); 599 } catch (Exception ex) { 600 } finally { 601 p.destroy(); 602 } 603 } 604 }.start(); 605 } 606 607 } catch (Throwable t) { 608 t.printStackTrace(); 609 System.out.println("Didn't start the nameserver"); 610 } 613 614 while (true) { 615 try { 616 p.waitFor(); 617 } catch (InterruptedException e) { 618 continue; 619 } 620 621 break; 623 } 624 } 625 } 626 }.start(); 627 } else { 628 ws.startCORBAServer(); 629 } 630 631 } catch (Throwable e) { 632 e.printStackTrace(System.out); 633 throw new Error (); 634 } 635 } 636 637 public void doneWith(org.omg.CORBA.Object toDisconnect) { 638 Servant s = null; 640 try { 641 s = rootPOA.reference_to_servant(toDisconnect); 642 } catch (ObjectNotActive objectNotActive) { 643 objectNotActive.printStackTrace(); 644 } catch (WrongPolicy wrongPolicy) { 645 wrongPolicy.printStackTrace(); 646 } catch (WrongAdapter wrongAdapter) { 647 wrongAdapter.printStackTrace(); 648 } 649 650 if (s instanceof Collective) { 651 ((Collective) s).__disband(orb); 652 } else { 653 try { 654 if (toDisconnect instanceof WfCreateProcessEventAudit) { 655 WfLinkingRequesterForCORBA.emptyCollective(((WfCreateProcessEventAudit) toDisconnect).process_key(), getBoundORB()); 656 } 657 if (toDisconnect instanceof WfDataEventAudit) { 658 WfLinkingRequesterForCORBA.emptyCollective(((WfDataEventAudit) toDisconnect).process_key(), getBoundORB()); 659 } 660 if (toDisconnect instanceof WfStateEventAudit) { 661 WfLinkingRequesterForCORBA.emptyCollective(((WfStateEventAudit) toDisconnect).process_key(), getBoundORB()); 662 } 663 toDisconnect._release();; 664 } catch (Exception ex) { 666 System.err.println("exception in doneWith" +ex); 667 } 668 } 669 } 670 } 671 672 | Popular Tags |