List of usage examples for java.net ServerSocket toString
public String toString()
From source file:at.alladin.rmbt.qos.testserver.util.TestServerConsole.java
public TestServerConsole() { super(System.out, true); keyListener = new Thread(new Runnable() { @Override//from ww w. j a va 2 s . c o m public void run() { if (System.console() != null) { while (true) { try { String command = System.console().readLine(); if (!isCommandLine) { isCommandLine = true; printLine(); printCommand( "\n\nEntered command mode!\n\nTo switch to debug output type 'exit' and press enter." + "\nType 'help' for some information on command mode."); } else { String[] commands = command.split("[ ]"); switch (commands[0]) { case COMMAND_EXIT_COMMAND_PROMPT: printlnCommand("\nStopped command mode.\n\n"); isCommandLine = false; break; case COMMAND_SHOW: if (commands.length > 1) { switch (commands[1]) { case SUBCOMMAND_SHOW_CLIENTS: printLine(); printlnCommand("\n"); printlnCommand("\nActive clients: " + TestServer.clientHandlerSet.size() + "\n"); for (ClientHandler client : TestServer.clientHandlerSet) { printlnCommand(" - " + client.getName()); printlnCommand("\t UdpIncomingResults: "); for (Entry<Integer, UdpTestCandidate> udpIn : client .getClientUdpInDataMap().entrySet()) { printlnCommand("\t\t " + udpIn.toString()); } printlnCommand("\t UdpOutgoingResults: "); for (Entry<Integer, UdpTestCandidate> udpOut : client .getClientUdpOutDataMap().entrySet()) { printlnCommand("\t\t " + udpOut.toString()); } } printLine(); break; case SUBCOMMAND_SHOW_INFO: printLine(); printlnCommand("\n" + TestServer.TEST_SERVER_VERSION_NAME); printlnCommand("\nCurrent server settings: " + TestServer.serverPreferences.toString()); printlnCommand( "\nQoSTestServer is listening on the following addresses:"); for (ServerSocket ss : TestServer.serverSocketList) { printlnCommand("\t- " + ss.toString()); } printLine(); break; case SUBCOMMAND_SHOW_OPENED_TCP_PORTS: boolean showTcp = true; if (TestServer.tcpServerMap.size() > 500) { showTcp = (commands.length > 2 && commands[2].equals(SUBCOMMAND_FORCE)); } printlnCommand("\nFound " + TestServer.tcpServerMap.values().size() + " active TCP sockets."); if (showTcp) { printlnCommand("\n\nList of all TCP sockets:\n"); for (Entry<Integer, List<TcpMultiClientServer>> e : TestServer.tcpServerMap .entrySet()) { for (TcpMultiClientServer i : e.getValue()) { printlnCommand( "Port " + e.getKey() + " -> " + i.toString()); } } } else { printlnCommand( "\n\nAre you sure you want to display them all? To ignore this warning type: 'show tcp force'."); } break; case SUBCOMMAND_SHOW_OPENED_UDP_PORTS: printlnCommand("Available udp sub options: " + "\nshow udp [#####] \t- where ##### is a port number between 0 and 65535" + "\nshow udp data \t\t- shows UDP servers with active ClientData awaiting incoming packets" + "\nshow udp nodata \t- shows UDP servers without active ClientData\n\n"); if (commands.length > 2) { if ("data".equals(commands[2])) { printlnCommand( "\nMultiClient UDP Server containing ClientData:"); for (List<AbstractUdpServer<?>> udpServerList : TestServer.udpServerMap .values()) { for (AbstractUdpServer<?> udpServer : udpServerList) { if (!udpServer.getIncomingMap().isEmpty()) { printlnCommand("\nUDP Server Info: " + udpServer.toString()); } } } } else if ("nodata".equals(commands[2])) { printlnCommand("\nMultiClient UDP Server wihtout ClientData:"); for (List<AbstractUdpServer<?>> udpServerList : TestServer.udpServerMap .values()) { for (AbstractUdpServer<?> udpServer : udpServerList) { if (udpServer.getIncomingMap().isEmpty()) { printlnCommand("\nUDP Server Info: " + udpServer.toString()); } } } } else { try { List<AbstractUdpServer<?>> udpServerList = TestServer.udpServerMap .get(Integer.valueOf(commands[2])); for (AbstractUdpServer<?> udpServer : udpServerList) { printlnCommand("\nMultiClient UDP Server Info:\n" + udpServer.toString()); } } catch (Exception e) { e.printStackTrace(); } } } else { printlnCommand("\nActive UDP ports: " + TestServer.serverPreferences.getUdpPortSet()); } break; default: printlnCommand("\n" + HINT_SHOW); break; } } else { printlnCommand("\n" + HINT_SHOW); } break; case COMMAND_SETTINGS: if (commands.length > 1) { switch (commands[1]) { case SUBCOMMAND_SETTINGS_SET_VERBOSE: if (commands.length > 2) { int verboseLevel = Integer.parseInt(commands[2]); verboseLevel = verboseLevel < 0 ? 0 : (verboseLevel > 2 ? 2 : verboseLevel); printlnCommand("\nSetting verbose level to: " + verboseLevel); TestServer.serverPreferences.setVerboseLevel(verboseLevel); } else { printlnCommand("\nVerbose level missing!"); } break; default: printCommand("\nSET what? Available options: [verbose]."); } } printlnCommand("\nCurrent server settings: " + TestServer.serverPreferences.toString()); break; case COMMAND_SHUTDOWN: isCommandLine = false; printLine(); TestServer.shutdown(); System.exit(0); break; case COMMAND_HELP: printHelp(); break; case DEBUG_COMMAND_LIST_SERVICES: synchronized (TestServer.serviceManager.getServiceMap()) { Iterator<Entry<String, FutureService>> entries = TestServer.serviceManager .getServiceMap().entrySet().iterator(); printlnCommand("\n" + TestServer.serviceManager.getServiceMap().size() + " services found:\n"); int i = 0; while (entries.hasNext()) { Entry<String, FutureService> e = entries.next(); printlnCommand("\t" + (++i) + ") " + e.getKey() + ":\n\t\t" + e.getValue().getService().toString()); } } break; default: printCommand("\nUnknown command. Enter 'help' for more information."); printHelp(); } } if (isCommandLine) { printCommand(PROMPT); } } catch (Exception e) { e.printStackTrace(); break; //exit loop } } } } }); }