public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { int serverId = illegalServerId; try { // determine the server id if (cmdArgs.length == 2) if (cmdArgs[0].equals("-serverid")) serverId = (Integer.valueOf(cmdArgs[1])).intValue(); else if (cmdArgs[0].equals("-applicationName")) serverId = ServerTool.getServerIdForAlias(orb, cmdArgs[1]); if (serverId == illegalServerId) return parseError; // startup the server Activator activator = ActivatorHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_ACTIVATOR_NAME)); activator.activate(serverId); out.println(CorbaResourceUtil.getText("servertool.startserver2")); } catch (ServerNotRegistered ex) { out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); } catch (ServerAlreadyActive ex) { out.println(CorbaResourceUtil.getText("servertool.serverup")); } catch (ServerHeldDown ex) { out.println(CorbaResourceUtil.getText("servertool.helddown")); } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { int serverId = illegalServerId; try { if (cmdArgs.length == 2) { if (cmdArgs[0].equals("-serverid")) serverId = (Integer.valueOf(cmdArgs[1])).intValue(); else if (cmdArgs[0].equals("-applicationName")) serverId = ServerTool.getServerIdForAlias(orb, cmdArgs[1]); } // the server id has to be specified if (serverId == illegalServerId) return parseError; // activate the server Activator activator = ActivatorHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_ACTIVATOR_NAME)); String[] orbList = activator.getORBNames(serverId); out.println(CorbaResourceUtil.getText("servertool.orbidmap2")); for (int i = 0; i < orbList.length; i++) { out.println("\t " + orbList[i]); } } catch (ServerNotRegistered ex) { out.println("\tno such server found."); } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { if ((cmdArgs.length == 2) && cmdArgs[0].equals("-applicationName")) { String str = (String) cmdArgs[1]; try { Repository repository = RepositoryHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_REPOSITORY_NAME)); try { int result = repository.getServerID(str); out.println(); out.println( CorbaResourceUtil.getText("servertool.getserverid2", str, Integer.toString(result))); out.println(); } catch (ServerNotRegistered e) { out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); } } catch (Exception ex) { ex.printStackTrace(); } return commandDone; } else return parseError; }
String[] readCommand(BufferedReader in) { System.out.print(toolName + " > "); try { int i = 0; String cmd[] = null; String cmdLine = in.readLine(); if (cmdLine != null) { StringTokenizer st = new StringTokenizer(cmdLine); if (st.countTokens() != 0) { cmd = new String[st.countTokens()]; while (st.hasMoreTokens()) cmd[i++] = st.nextToken(); } } return cmd; } catch (Exception ex) { System.out.println(CorbaResourceUtil.getText("servertool.usage", "servertool")); System.out.println(); ex.printStackTrace(); } return null; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { int serverId = illegalServerId; boolean listOneServer = false; ServerDef serverDef; // determine if list single server or all servers listOneServer = (cmdArgs.length != 0); if ((cmdArgs.length == 2) && cmdArgs[0].equals("-serverid")) serverId = (Integer.valueOf(cmdArgs[1])).intValue(); if ((serverId == illegalServerId) && listOneServer) return parseError; // process the list server command try { Repository repository = RepositoryHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_REPOSITORY_NAME)); if (listOneServer) { try { serverDef = repository.getServer(serverId); out.println(); printServerDef(serverDef, serverId, out); out.println(); } catch (ServerNotRegistered e) { out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); } } else { int[] servers = repository.listRegisteredServers(); out.println(CorbaResourceUtil.getText("servertool.list2")); sortServers(servers); for (int i = 0; i < servers.length; i++) { try { serverDef = repository.getServer(servers[i]); out.println( "\t " + servers[i] + "\t\t" + serverDef.serverName + "\t\t" + serverDef.applicationName); } catch (ServerNotRegistered e) { } } } } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { int serverId = illegalServerId; String orbId = ""; try { // parse command String arg; int i = 0; while (i < cmdArgs.length) { arg = cmdArgs[i++]; if (arg.equals("-serverid")) { if (i < cmdArgs.length) serverId = (Integer.valueOf(cmdArgs[i++])).intValue(); else return parseError; } else if (arg.equals("-applicationName")) { if (i < cmdArgs.length) serverId = ServerTool.getServerIdForAlias(orb, cmdArgs[i++]); else return parseError; } else if (arg.equals("-orbid")) { if (i < cmdArgs.length) orbId = cmdArgs[i++]; } } // the server id has to be specified if (serverId == illegalServerId) return parseError; // locate the server // deactivate the server Locator locator = LocatorHelper.narrow(orb.resolve_initial_references(ORBConstants.SERVER_LOCATOR_NAME)); ServerLocationPerORB location = locator.locateServerForORB(serverId, orbId); // print success message out.println(CorbaResourceUtil.getText("servertool.locateorb2", location.hostname)); int numEntries = location.ports.length; for (i = 0; i < numEntries; i++) { EndPointInfo Port = location.ports[i]; out.println("\t\t" + Port.port + "\t\t" + Port.endpointType + "\t\t" + orbId); } } catch (InvalidORBid ex) { out.println(CorbaResourceUtil.getText("servertool.nosuchorb")); } catch (ServerHeldDown ex) { out.println(CorbaResourceUtil.getText("servertool.helddown")); } catch (ServerNotRegistered ex) { out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { try { Repository repository = RepositoryHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_REPOSITORY_NAME)); String[] applicationNames = repository.getApplicationNames(); out.println(CorbaResourceUtil.getText("servertool.listappnames2")); out.println(); for (int i = 0; i < applicationNames.length; i++) out.println("\t" + applicationNames[i]); } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
void run(String[] args) { String[] cmd = null; // if command specified in the args, get it for (int i = 0; i < args.length; i++) { if (args[i].equals(commandArg)) { // get the command int cmdLen = args.length - i - 1; cmd = new String[cmdLen]; for (int j = 0; j < cmdLen; j++) cmd[j] = args[++i]; break; } } try { // create the POA ORB Properties props = System.getProperties(); props.put("org.omg.CORBA.ORBClass", "com.sun.corba.se.impl.orb.ORBImpl"); orb = (ORB) ORB.init(args, props); // if command specified in the args, process it if (cmd != null) executeCommand(cmd); else { // process commands interactively // create a buffered reader to read commands from standard in BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // print tool banner System.out.println(CorbaResourceUtil.getText("servertool.banner")); // process commands until user quits while (true) { cmd = readCommand(in); if (cmd != null) executeCommand(cmd); else printAvailableCommands(); } } } catch (Exception ex) { System.out.println(CorbaResourceUtil.getText("servertool.usage", "servertool")); System.out.println(); ex.printStackTrace(); } }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { int serverId = illegalServerId; try { if (cmdArgs.length == 2) { if (cmdArgs[0].equals("-serverid")) serverId = (Integer.valueOf(cmdArgs[1])).intValue(); else if (cmdArgs[0].equals("-applicationName")) serverId = ServerTool.getServerIdForAlias(orb, cmdArgs[1]); } // the server id has to be specified if (serverId == illegalServerId) return parseError; // deactivate server, hold it down and and unregister it // deactivate the server try { Activator activator = ActivatorHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_ACTIVATOR_NAME)); activator.uninstall(serverId); } catch (ServerHeldDown ex) { } // unregister the server from the repository Repository repository = RepositoryHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_REPOSITORY_NAME)); repository.unregisterServer(serverId); // print success message out.println(CorbaResourceUtil.getText("servertool.unregister2")); } catch (ServerNotRegistered ex) { out.println(CorbaResourceUtil.getText("servertool.nosuchserver")); } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { ServerDef serverDef; // process the list active servers command try { Repository repository = RepositoryHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_REPOSITORY_NAME)); Activator activator = ActivatorHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_ACTIVATOR_NAME)); int[] servers = activator.getActiveServers(); out.println(CorbaResourceUtil.getText("servertool.list2")); ListServers.sortServers(servers); for (int i = 0; i < servers.length; i++) { try { serverDef = repository.getServer(servers[i]); out.println( "\t " + servers[i] + "\t\t" + serverDef.serverName + "\t\t" + serverDef.applicationName); } catch (ServerNotRegistered e) { } } } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }
public boolean processCommand(String[] cmdArgs, ORB orb, PrintStream out) { int i = 0; String applicationName = ""; String name = ""; String classpath = ""; String args = ""; String vmargs = ""; int serverId = 0; // parse register server command String arg; while (i < cmdArgs.length) { arg = cmdArgs[i++]; if (arg.equals("-server")) { if (i < cmdArgs.length) name = cmdArgs[i++]; else return parseError; } else if (arg.equals("-applicationName")) { if (i < cmdArgs.length) applicationName = cmdArgs[i++]; else return parseError; } else if (arg.equals("-classpath")) { if (i < cmdArgs.length) classpath = cmdArgs[i++]; else return parseError; } else if (arg.equals("-args")) { while ((i < cmdArgs.length) && !cmdArgs[i].equals("-vmargs")) { args = args.equals("") ? cmdArgs[i] : args + " " + cmdArgs[i]; i++; } if (args.equals("")) return parseError; } else if (arg.equals("-vmargs")) { while ((i < cmdArgs.length) && !cmdArgs[i].equals("-args")) { vmargs = vmargs.equals("") ? cmdArgs[i] : vmargs + " " + cmdArgs[i]; i++; } if (vmargs.equals("")) return parseError; } else return parseError; } // minimally the server class name has to be specified if (name.equals("")) return parseError; // register server and activate it try { // register the server with the repository Repository repository = RepositoryHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_REPOSITORY_NAME)); ServerDef server = new ServerDef(applicationName, name, classpath, args, vmargs); serverId = repository.registerServer(server); // activate the server Activator activator = ActivatorHelper.narrow( orb.resolve_initial_references(ORBConstants.SERVER_ACTIVATOR_NAME)); activator.activate(serverId); activator.install(serverId); // print success message out.println(CorbaResourceUtil.getText("servertool.register2", serverId)); } catch (ServerNotRegistered ex) { } catch (ServerAlreadyActive ex) { } catch (ServerHeldDown ex) { out.println(CorbaResourceUtil.getText("servertool.register3", serverId)); } catch (ServerAlreadyRegistered ex) { out.println(CorbaResourceUtil.getText("servertool.register4", serverId)); } catch (BadServerDefinition ex) { out.println(CorbaResourceUtil.getText("servertool.baddef", ex.reason)); } catch (Exception ex) { ex.printStackTrace(); } return commandDone; }