ServerTool.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.corba.se.impl.activation; 27 28import java.io.BufferedReader; 29import java.io.InputStreamReader; 30import java.io.PrintStream; 31import java.util.Vector; 32import java.util.Properties; 33import java.util.StringTokenizer; 34 35import org.omg.CORBA.ORB; 36import org.omg.CORBA.INITIALIZE; 37import org.omg.CORBA.CompletionStatus; 38import com.sun.corba.se.impl.orbutil.ORBConstants; 39import com.sun.corba.se.impl.orbutil.CorbaResourceUtil; 40import com.sun.corba.se.spi.activation.*; 41import com.sun.corba.se.spi.activation.ServerHeldDown; 42import com.sun.corba.se.spi.activation.RepositoryPackage.ServerDef; 43import com.sun.corba.se.spi.activation.LocatorPackage.ServerLocation; 44import com.sun.corba.se.spi.activation.LocatorPackage.ServerLocationPerORB; 45 46/** 47 * 48 * @author Anita Jindal 49 * @since JDK1.3 50 */ 51public class ServerTool 52{ 53 final static String helpCommand = "help"; 54 final static String toolName = "servertool"; 55 final static String commandArg = "-cmd"; 56 57 static int getServerIdForAlias( ORB orb, String applicationName ) throws ServerNotRegistered 58 { 59 try { 60 Repository rep = RepositoryHelper.narrow( 61 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME ) ) ; 62 int serverid = rep.getServerID(applicationName); 63 64 return rep.getServerID( applicationName ) ; 65 } catch (Exception ex) { 66 throw (new ServerNotRegistered()); 67 } 68 } 69 70 void run(String[] args) 71 { 72 String[] cmd = null; 73 74 // if command specified in the args, get it 75 for (int i=0; i < args.length; i++) { 76 77 if (args[i].equals(commandArg)) { 78 // get the command 79 int cmdLen = args.length - i - 1; 80 cmd = new String[cmdLen]; 81 for (int j=0; j < cmdLen; j++) cmd[j] = args[++i]; 82 83 break; 84 } 85 } 86 87 try { 88 // create the POA ORB 89 Properties props = System.getProperties() ; 90 props.put("org.omg.CORBA.ORBClass", 91 "com.sun.corba.se.impl.orb.ORBImpl" ); 92 orb = (ORB) ORB.init(args, props); 93 94 // if command specified in the args, process it 95 if (cmd != null) executeCommand(cmd); 96 else { // process commands interactively 97 98 // create a buffered reader to read commands from standard in 99 BufferedReader in = new 100 BufferedReader(new InputStreamReader(System.in)); 101 102 // print tool banner 103 System.out.println(CorbaResourceUtil.getText("servertool.banner")); 104 105 // process commands until user quits 106 while (true) { 107 cmd = readCommand(in); 108 if (cmd != null) executeCommand(cmd); 109 else printAvailableCommands(); 110 } 111 } 112 } catch (Exception ex) { 113 System.out.println(CorbaResourceUtil.getText("servertool.usage", "servertool")); 114 System.out.println(); 115 ex.printStackTrace(); 116 } 117 } 118 119 public static void main(String[] args) 120 { 121 ServerTool tool = new ServerTool(); 122 tool.run(args); 123 } 124 125 String[] readCommand(BufferedReader in) 126 { 127 System.out.print(toolName + " > "); 128 129 try { 130 int i = 0; 131 String cmd[] = null; 132 133 String cmdLine = in.readLine(); 134 135 if (cmdLine != null) { 136 StringTokenizer st = new StringTokenizer(cmdLine); 137 if (st.countTokens() != 0) { 138 cmd = new String[st.countTokens()]; 139 while (st.hasMoreTokens()) cmd[i++] = st.nextToken(); 140 } 141 } 142 143 return cmd; 144 } catch (Exception ex) { 145 System.out.println(CorbaResourceUtil.getText("servertool.usage", "servertool")); 146 System.out.println(); 147 ex.printStackTrace(); 148 } 149 150 return null; 151 } 152 153 void printAvailableCommands() 154 { 155 CommandHandler handler; 156 157 // print short help 158 System.out.println(CorbaResourceUtil.getText("servertool.shorthelp")); 159 160 for (int i=0; i < handlers.size(); i++) { 161 handler = (CommandHandler) handlers.elementAt(i); 162 System.out.print("\t" + handler.getCommandName()); 163 for (int j=handler.getCommandName().length(); 164 j < maxNameLen; j++) System.out.print(" "); 165 System.out.print(" - "); 166 handler.printCommandHelp(System.out, 167 CommandHandler.shortHelp); 168 } 169 170 System.out.println(); 171 } 172 173 void executeCommand(String[] cmd) 174 { 175 boolean result; 176 CommandHandler handler; 177 178 // handle the help command 179 if (cmd[0].equals(helpCommand)) { 180 if (cmd.length == 1) printAvailableCommands(); 181 else { 182 // print long help for a specific command 183 for (int i=0; i < handlers.size(); i++) { 184 handler = (CommandHandler) handlers.elementAt(i); 185 if (handler.getCommandName().equals(cmd[1])) { 186 handler.printCommandHelp(System.out, 187 CommandHandler.longHelp); 188 } 189 } 190 } 191 192 return; 193 } 194 195 // determine the subcommand and execute it 196 for (int i=0; i < handlers.size(); i++) { 197 handler = (CommandHandler) handlers.elementAt(i); 198 if (handler.getCommandName().equals(cmd[0])) { 199 String[] cmdArgs = new String[cmd.length - 1]; 200 201 // construct args to the command 202 for (int j=0; j < cmdArgs.length; j++) 203 cmdArgs[j] = cmd[j+1]; 204 205 // execute the command 206 try { 207 System.out.println(); 208 209 result = handler.processCommand(cmdArgs, orb, System.out); 210 211 if (result == CommandHandler.parseError) { 212 handler.printCommandHelp(System.out, 213 CommandHandler.longHelp); 214 } 215 216 System.out.println(); 217 218 } catch (Exception ex) {} 219 220 return; 221 } 222 } 223 224 // unknown command - print available commands 225 printAvailableCommands(); 226 } 227 228 final private static boolean debug = false; 229 230 ORB orb = null; 231 232 static Vector handlers; 233 static int maxNameLen; 234 235 static { 236 handlers = new Vector(); 237 handlers.addElement(new RegisterServer()); 238 handlers.addElement(new UnRegisterServer()); 239 handlers.addElement(new GetServerID()); 240 handlers.addElement(new ListServers()); 241 handlers.addElement(new ListAliases()); 242 handlers.addElement(new ListActiveServers()); 243 handlers.addElement(new LocateServer()); 244 handlers.addElement(new LocateServerForORB()); 245 handlers.addElement(new ListORBs()); 246 handlers.addElement(new ShutdownServer()); 247 handlers.addElement(new StartServer()); 248 handlers.addElement(new Help()); 249 handlers.addElement(new Quit()); 250 251 // determine longest command name 252 maxNameLen = 0; 253 int cmdNameLen; 254 for (int i=0; i < handlers.size(); i++) { 255 CommandHandler handler = (CommandHandler) handlers.elementAt(i); 256 cmdNameLen = handler.getCommandName().length(); 257 if (cmdNameLen > maxNameLen) maxNameLen = cmdNameLen; 258 } 259 } 260} 261 262class RegisterServer implements CommandHandler 263{ 264 public String getCommandName() {return "register";} 265 266 public void printCommandHelp(PrintStream out, boolean helpType) 267 { 268 if (helpType == longHelp) { 269 out.println(CorbaResourceUtil.getText("servertool.register")); 270 } else { 271 out.println(CorbaResourceUtil.getText("servertool.register1")); 272 } 273 } 274 275 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 276 { 277 int i=0; 278 String applicationName = ""; 279 String name = ""; 280 String classpath = ""; 281 String args = ""; 282 String vmargs = ""; 283 int serverId = 0; 284 285 // parse register server command 286 String arg; 287 while (i < cmdArgs.length) { 288 289 arg = cmdArgs[i++]; 290 291 if (arg.equals("-server")) { 292 if (i < cmdArgs.length) name = cmdArgs[i++]; 293 else return parseError; 294 } else if (arg.equals("-applicationName")) { 295 if (i < cmdArgs.length) applicationName = cmdArgs[i++]; 296 else return parseError; 297 } else if (arg.equals("-classpath")) { 298 if (i < cmdArgs.length) classpath = cmdArgs[i++]; 299 else return parseError; 300 } else if (arg.equals("-args")) { 301 while ((i < cmdArgs.length) && !cmdArgs[i].equals("-vmargs")){ 302 args = args.equals("") ? cmdArgs[i] : 303 args + " " + cmdArgs[i]; 304 i++; 305 } 306 if (args.equals("")) return parseError; 307 } else if (arg.equals("-vmargs")) { 308 while ((i < cmdArgs.length) && !cmdArgs[i].equals("-args")){ 309 vmargs = vmargs.equals("") ? cmdArgs[i] : 310 vmargs + " " + cmdArgs[i]; 311 i++; 312 } 313 if (vmargs.equals("")) return parseError; 314 } else return parseError; 315 } 316 317 // minimally the server class name has to be specified 318 if (name.equals("")) return parseError; 319 320 // register server and activate it 321 try { 322 // register the server with the repository 323 Repository repository = RepositoryHelper.narrow( 324 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME )); 325 326 ServerDef server = new ServerDef(applicationName, name, classpath, args, vmargs); 327 serverId = repository.registerServer(server); 328 329 // activate the server 330 Activator activator = ActivatorHelper.narrow( 331 orb.resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )); 332 activator.activate(serverId); 333 activator.install(serverId); 334 335 // print success message 336 out.println(CorbaResourceUtil.getText("servertool.register2", serverId)); 337 } catch (ServerNotRegistered ex) { 338 } catch (ServerAlreadyActive ex) { 339 } catch (ServerHeldDown ex) { 340 out.println(CorbaResourceUtil.getText("servertool.register3", serverId)); 341 } catch (ServerAlreadyRegistered ex) { 342 out.println(CorbaResourceUtil.getText("servertool.register4", serverId)); 343 } catch (BadServerDefinition ex) { 344 out.println(CorbaResourceUtil.getText("servertool.baddef", ex.reason)); 345 } catch (Exception ex) { 346 ex.printStackTrace(); 347 } 348 349 return commandDone; 350 } 351} 352 353class UnRegisterServer implements CommandHandler 354{ 355 public String getCommandName() {return "unregister";} 356 357 public void printCommandHelp(PrintStream out, boolean helpType) 358 { 359 if (helpType == longHelp) { 360 out.println(CorbaResourceUtil.getText("servertool.unregister")); 361 } else { 362 out.println(CorbaResourceUtil.getText("servertool.unregister1")); 363 } 364} 365 366 final static int illegalServerId = -1; 367 368 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 369 { 370 int serverId = illegalServerId; 371 372 try { 373 if (cmdArgs.length == 2) { 374 if (cmdArgs[0].equals("-serverid")) 375 serverId = (Integer.valueOf(cmdArgs[1])).intValue(); 376 else if (cmdArgs[0].equals("-applicationName")) 377 serverId = ServerTool.getServerIdForAlias( orb, cmdArgs[1] ) ; 378 } 379 380 // the server id has to be specified 381 if (serverId == illegalServerId) 382 return parseError; 383 384 // deactivate server, hold it down and and unregister it 385 // deactivate the server 386 try { 387 Activator activator = ActivatorHelper.narrow( 388 orb.resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )); 389 activator.uninstall(serverId); 390 } catch (ServerHeldDown ex) {} 391 392 // unregister the server from the repository 393 Repository repository = RepositoryHelper.narrow( 394 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME )); 395 repository.unregisterServer(serverId); 396 397 // print success message 398 out.println(CorbaResourceUtil.getText("servertool.unregister2")); 399 } catch (ServerNotRegistered ex) { 400 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 401 } catch (Exception ex) { 402 ex.printStackTrace(); 403 } 404 405 return commandDone; 406 } 407} 408 409class LocateServer implements CommandHandler 410{ 411 public String getCommandName() {return "locate";} 412 413 public void printCommandHelp(PrintStream out, boolean helpType) 414 { 415 if (helpType == longHelp) { 416 out.println(CorbaResourceUtil.getText("servertool.locate")); 417 } else { 418 out.println(CorbaResourceUtil.getText("servertool.locate1")); 419 } 420 } 421 422 final static int illegalServerId = -1; 423 424 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 425 { 426 int serverId = illegalServerId; 427 428 String endPointType = IIOP_CLEAR_TEXT.value; 429 try { 430 431 // parse command 432 String arg; 433 int i = 0; 434 while (i < cmdArgs.length) { 435 436 arg = cmdArgs[i++]; 437 438 if (arg.equals("-serverid")) { 439 if (i < cmdArgs.length) 440 serverId = (Integer.valueOf(cmdArgs[i++])).intValue(); 441 else 442 return parseError; 443 } else if (arg.equals("-applicationName")) { 444 if (i < cmdArgs.length) 445 serverId = ServerTool.getServerIdForAlias( orb, cmdArgs[i++] ) ; 446 else 447 return parseError; 448 } else if (arg.equals("-endpointType")) { 449 if (i < cmdArgs.length) 450 endPointType = cmdArgs[i++]; 451 } 452 } 453 454 // the server id has to be specified 455 if (serverId == illegalServerId) 456 return parseError; 457 458 // locate the server 459 // deactivate the server 460 Locator locator = LocatorHelper.narrow( 461 orb.resolve_initial_references( ORBConstants.SERVER_LOCATOR_NAME )); 462 463 ServerLocation location = locator.locateServer(serverId, endPointType); 464 465 // print success message 466 out.println(CorbaResourceUtil.getText("servertool.locate2", location.hostname)); 467 int numEntries = location.ports.length; 468 for (i = 0; i < numEntries; i++) { 469 ORBPortInfo orbPort = location.ports[i]; 470 out.println("\t\t"+ orbPort.port + "\t\t" + endPointType + "\t\t" + orbPort.orbId ); 471 } 472 } catch (NoSuchEndPoint ex) { 473 } catch (ServerHeldDown ex) { 474 out.println(CorbaResourceUtil.getText("servertool.helddown")); 475 } catch (ServerNotRegistered ex) { 476 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 477 } catch (Exception ex) { 478 ex.printStackTrace(); 479 } 480 481 return commandDone; 482 } 483} 484 485class LocateServerForORB implements CommandHandler 486{ 487 public String getCommandName() {return "locateperorb";} 488 489 public void printCommandHelp(PrintStream out, boolean helpType) 490 { 491 if (helpType == longHelp) { 492 out.println(CorbaResourceUtil.getText("servertool.locateorb")); 493 } else { 494 out.println(CorbaResourceUtil.getText("servertool.locateorb1")); 495 } 496 } 497 498 final static int illegalServerId = -1; 499 500 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 501 { 502 int serverId = illegalServerId; 503 504 String orbId = ""; 505 try { 506 507 // parse command 508 String arg; 509 int i = 0; 510 while (i < cmdArgs.length) { 511 512 arg = cmdArgs[i++]; 513 514 if (arg.equals("-serverid")) { 515 if (i < cmdArgs.length) 516 serverId = (Integer.valueOf(cmdArgs[i++])).intValue(); 517 else 518 return parseError; 519 } else if (arg.equals("-applicationName")) { 520 if (i < cmdArgs.length) 521 serverId = ServerTool.getServerIdForAlias( orb, cmdArgs[i++] ) ; 522 else 523 return parseError; 524 } else if (arg.equals("-orbid")) { 525 if (i < cmdArgs.length) 526 orbId = cmdArgs[i++]; 527 } 528 } 529 530 // the server id has to be specified 531 if (serverId == illegalServerId) 532 return parseError; 533 534 // locate the server 535 // deactivate the server 536 Locator locator = LocatorHelper.narrow( 537 orb.resolve_initial_references( ORBConstants.SERVER_LOCATOR_NAME )); 538 539 ServerLocationPerORB location = locator.locateServerForORB(serverId, 540 orbId); 541 542 // print success message 543 out.println(CorbaResourceUtil.getText("servertool.locateorb2", location.hostname)); 544 int numEntries = location.ports.length; 545 for (i = 0; i < numEntries; i++) { 546 EndPointInfo Port = location.ports[i]; 547 out.println("\t\t"+ Port.port + "\t\t" + Port.endpointType + "\t\t" + orbId ); 548 } 549 } catch (InvalidORBid ex) { 550 out.println(CorbaResourceUtil.getText("servertool.nosuchorb")); 551 } catch (ServerHeldDown ex) { 552 out.println(CorbaResourceUtil.getText("servertool.helddown")); 553 } catch (ServerNotRegistered ex) { 554 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 555 } catch (Exception ex) { 556 ex.printStackTrace(); 557 } 558 559 return commandDone; 560 } 561} 562 563class GetServerID implements CommandHandler 564{ 565 public String getCommandName() {return "getserverid" ; } 566 567 public void printCommandHelp( PrintStream out, boolean helpType ) 568 { 569 if (helpType == longHelp) { 570 out.println(CorbaResourceUtil.getText("servertool.getserverid")); 571 } else { 572 out.println(CorbaResourceUtil.getText("servertool.getserverid1")); 573 } 574 } 575 576 public boolean processCommand( String[] cmdArgs, ORB orb, PrintStream out ) 577 { 578 if ((cmdArgs.length == 2) && cmdArgs[0].equals( "-applicationName" )) { 579 String str = (String)cmdArgs[1] ; 580 581 try { 582 Repository repository = RepositoryHelper.narrow( 583 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME )); 584 585 try { 586 int result = repository.getServerID( str ) ; 587 out.println() ; 588 out.println(CorbaResourceUtil.getText("servertool.getserverid2", str, Integer.toString(result))); 589 out.println() ; 590 } catch (ServerNotRegistered e) { 591 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 592 } 593 } catch (Exception ex) { 594 ex.printStackTrace() ; 595 } 596 597 return commandDone ; 598 } else 599 return parseError ; 600 } 601} 602 603class ListServers implements CommandHandler 604{ 605 public String getCommandName() {return "list";} 606 607 public void printCommandHelp(PrintStream out, boolean helpType) 608 { 609 if (helpType == longHelp) { 610 out.println(CorbaResourceUtil.getText("servertool.list")); 611 } else { 612 out.println(CorbaResourceUtil.getText("servertool.list1")); 613 } 614 } 615 616 final static int illegalServerId = -1; 617 618 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 619 { 620 int serverId = illegalServerId; 621 boolean listOneServer = false; 622 ServerDef serverDef; 623 624 // determine if list single server or all servers 625 listOneServer = (cmdArgs.length!=0) ; 626 if ((cmdArgs.length == 2) && cmdArgs[0].equals("-serverid")) 627 serverId = (Integer.valueOf(cmdArgs[1])).intValue(); 628 629 if ((serverId == illegalServerId) && listOneServer) 630 return parseError; 631 632 // process the list server command 633 try { 634 Repository repository = RepositoryHelper.narrow( 635 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME )); 636 637 if (listOneServer) { 638 639 try { 640 serverDef = repository.getServer(serverId); 641 out.println(); 642 printServerDef(serverDef, serverId, out); 643 out.println(); 644 } catch (ServerNotRegistered e) { 645 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 646 } 647 648 } else { 649 int[] servers = repository.listRegisteredServers(); 650 out.println(CorbaResourceUtil.getText("servertool.list2")); 651 652 sortServers(servers); 653 for (int i=0; i < servers.length; i++) { 654 try { 655 serverDef = repository.getServer(servers[i]); 656 out.println("\t " + servers[i] + "\t\t" + 657 serverDef.serverName + "\t\t" 658 + serverDef.applicationName); 659 } catch (ServerNotRegistered e) {} 660 } 661 662 } 663 } catch (Exception ex) { 664 ex.printStackTrace(); 665 } 666 667 return commandDone; 668 } 669 670static void printServerDef(ServerDef serverDef, int serverId, 671 PrintStream out) 672{ 673 out.println(CorbaResourceUtil.getText("servertool.appname", serverDef.applicationName)); 674 out.println(CorbaResourceUtil.getText("servertool.name", serverDef.serverName)); 675 out.println(CorbaResourceUtil.getText("servertool.classpath", serverDef.serverClassPath)); 676 out.println(CorbaResourceUtil.getText("servertool.args", serverDef.serverArgs)); 677 out.println(CorbaResourceUtil.getText("servertool.vmargs", serverDef.serverVmArgs)); 678 out.println(CorbaResourceUtil.getText("servertool.serverid", serverId)); 679} 680 681/** 682 * Do a simple bubble sort to sort the server ids in ascending 683 * order. 684 */ 685static void sortServers(int[] serverIds) 686{ 687 int size = serverIds.length; 688 int lowest; 689 690 for (int i=0; i < size; i++) { 691 692 lowest = i; 693 694 for (int j=i+1; j < size; j++) { 695 if (serverIds[j] < serverIds[lowest]) lowest = j; 696 } 697 698 if (lowest != i) { 699 int temp = serverIds[i]; 700 serverIds[i] = serverIds[lowest]; 701 serverIds[lowest] = temp; 702 } 703 } 704} 705} 706 707class ListActiveServers implements CommandHandler 708{ 709 public String getCommandName() {return "listactive";} 710 711 public void printCommandHelp(PrintStream out, boolean helpType) 712 { 713 if (helpType == longHelp) { 714 out.println(CorbaResourceUtil.getText("servertool.listactive")); 715 } else { 716 out.println(CorbaResourceUtil.getText("servertool.listactive1")); 717 } 718 } 719 720 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 721 { 722 ServerDef serverDef; 723 724 // process the list active servers command 725 try { 726 Repository repository = RepositoryHelper.narrow( 727 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME )); 728 729 Activator activator = ActivatorHelper.narrow( 730 orb.resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )); 731 732 int[] servers = activator.getActiveServers(); 733 734 out.println(CorbaResourceUtil.getText("servertool.list2")); 735 736 ListServers.sortServers(servers); 737 for (int i=0; i < servers.length; i++) { 738 try { 739 serverDef = repository.getServer(servers[i]); 740 out.println("\t " + servers[i] + "\t\t" + 741 serverDef.serverName + "\t\t" + 742 serverDef.applicationName); 743 } catch (ServerNotRegistered e) {} 744 } 745 } catch (Exception ex) { 746 ex.printStackTrace(); 747 } 748 749 return commandDone; 750 } 751} 752 753class ListAliases implements CommandHandler 754{ 755 public String getCommandName() {return "listappnames";} 756 757 public void printCommandHelp(PrintStream out, boolean helpType) 758 { 759 if (helpType == longHelp) { 760 out.println(CorbaResourceUtil.getText("servertool.listappnames")); 761 } else { 762 out.println(CorbaResourceUtil.getText("servertool.listappnames1")); 763 } 764 } 765 766 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 767 { 768 try { 769 Repository repository = RepositoryHelper.narrow( 770 orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME )); 771 772 String[] applicationNames = repository.getApplicationNames(); 773 774 out.println(CorbaResourceUtil.getText("servertool.listappnames2")); 775 out.println(); 776 for (int i=0; i < applicationNames.length; i++) 777 out.println( "\t" + applicationNames[i] ) ; 778 } catch (Exception ex) { 779 ex.printStackTrace(); 780 } 781 782 return commandDone; 783 } 784} 785 786class ShutdownServer implements CommandHandler 787{ 788 public String getCommandName() {return "shutdown";} 789 790 public void printCommandHelp(PrintStream out, boolean helpType) 791 { 792 if (helpType == longHelp) { 793 out.println(CorbaResourceUtil.getText("servertool.shutdown")); 794 } else { 795 out.println(CorbaResourceUtil.getText("servertool.shutdown1")); 796 } 797 } 798 799 final static int illegalServerId = -1; 800 801 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 802 { 803 int serverId = illegalServerId; 804 805 try { 806 // determine the server id 807 if (cmdArgs.length == 2) 808 if (cmdArgs[0].equals("-serverid")) 809 serverId = (Integer.valueOf(cmdArgs[1])).intValue(); 810 else if (cmdArgs[0].equals("-applicationName")) 811 serverId = ServerTool.getServerIdForAlias( orb, cmdArgs[1] ) ; 812 813 if (serverId == illegalServerId) 814 return parseError; 815 816 // shutdown the server 817 Activator activator = ActivatorHelper.narrow( 818 orb.resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )); 819 activator.shutdown(serverId); 820 821 out.println(CorbaResourceUtil.getText("servertool.shutdown2")); 822 } catch (ServerNotActive ex) { 823 out.println(CorbaResourceUtil.getText("servertool.servernotrunning")); 824 } catch (ServerNotRegistered ex) { 825 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 826 } catch (Exception ex) { 827 ex.printStackTrace(); 828 } 829 830 return commandDone; 831 } 832} 833 834class StartServer implements CommandHandler 835{ 836 public String getCommandName() {return "startup";} 837 838 public void printCommandHelp(PrintStream out, boolean helpType) 839 { 840 if (helpType == longHelp) { 841 out.println(CorbaResourceUtil.getText("servertool.startserver")); 842 } else { 843 out.println(CorbaResourceUtil.getText("servertool.startserver1")); 844 } 845 } 846 847 final static int illegalServerId = -1; 848 849 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 850 { 851 int serverId = illegalServerId; 852 853 try { 854 // determine the server id 855 if (cmdArgs.length == 2) 856 if (cmdArgs[0].equals("-serverid")) 857 serverId = (Integer.valueOf(cmdArgs[1])).intValue(); 858 else if (cmdArgs[0].equals("-applicationName")) 859 serverId = ServerTool.getServerIdForAlias( orb, cmdArgs[1] ) ; 860 861 if (serverId == illegalServerId) 862 return parseError; 863 864 // startup the server 865 Activator activator = ActivatorHelper.narrow( 866 orb.resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )); 867 activator.activate(serverId); 868 869 out.println(CorbaResourceUtil.getText("servertool.startserver2")); 870 } catch (ServerNotRegistered ex) { 871 out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); 872 } catch (ServerAlreadyActive ex) { 873 out.println(CorbaResourceUtil.getText("servertool.serverup")); 874 } catch (ServerHeldDown ex) { 875 out.println(CorbaResourceUtil.getText("servertool.helddown")); 876 } catch (Exception ex) { 877 ex.printStackTrace(); 878 } 879 return commandDone; 880 } 881} 882 883class Quit implements CommandHandler 884{ 885 public String getCommandName() {return "quit";} 886 887 public void printCommandHelp(PrintStream out, boolean helpType) 888 { 889 if (helpType == longHelp) { 890 out.println(CorbaResourceUtil.getText("servertool.quit")); 891 } else { 892 out.println(CorbaResourceUtil.getText("servertool.quit1")); 893 } 894 } 895 896 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 897 { 898 System.exit(0); 899 900 return commandDone; 901 } 902} 903 904class Help implements CommandHandler 905{ 906 public String getCommandName() {return "help";} 907 908 public void printCommandHelp(PrintStream out, boolean helpType) 909 { 910 if (helpType == longHelp) { 911 out.println(CorbaResourceUtil.getText("servertool.help")); 912 } else { 913 out.println(CorbaResourceUtil.getText("servertool.help1")); 914 } 915 } 916 917 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 918 { 919 return commandDone; 920 } 921} 922 923class ListORBs implements CommandHandler 924{ 925 public String getCommandName() {return "orblist";} 926 927 public void printCommandHelp(PrintStream out, boolean helpType) 928 { 929 if (helpType == longHelp) { 930 out.println(CorbaResourceUtil.getText("servertool.orbidmap")); 931 } else { 932 out.println(CorbaResourceUtil.getText("servertool.orbidmap1")); 933 } 934 } 935 936 final static int illegalServerId = -1; 937 938 public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) 939 { 940 941 int serverId = illegalServerId; 942 943 try { 944 if (cmdArgs.length == 2) { 945 if (cmdArgs[0].equals("-serverid")) 946 serverId = (Integer.valueOf(cmdArgs[1])).intValue(); 947 else if (cmdArgs[0].equals("-applicationName")) 948 serverId = ServerTool.getServerIdForAlias( orb, cmdArgs[1] ) ; 949 } 950 951 // the server id has to be specified 952 if (serverId == illegalServerId) 953 return parseError; 954 // activate the server 955 Activator activator = ActivatorHelper.narrow( 956 orb.resolve_initial_references( ORBConstants.SERVER_ACTIVATOR_NAME )); 957 958 String[] orbList = activator.getORBNames(serverId); 959 960 out.println(CorbaResourceUtil.getText("servertool.orbidmap2")); 961 962 for (int i = 0; i < orbList.length ; i++) { 963 out.println("\t "+ orbList[i]); 964 } 965 } catch (ServerNotRegistered ex) { 966 out.println("\tno such server found."); 967 } catch (Exception ex) { 968 ex.printStackTrace(); 969 } 970 971 return commandDone; 972 } 973} 974