private void start(String[] arguments, CtrlCHandler signalHandler) { Args args = new Args(arguments); if (args.has("?") || args.has("h") || args.has("help") || args.has("usage")) { printUsage(); return; } String path = args.get(ARG_PATH, null); String host = args.get(ARG_HOST, null); String port = args.get(ARG_PORT, null); String name = args.get(ARG_NAME, null); String pid = args.get(ARG_PID, null); if ((path != null && (port != null || name != null || host != null || pid != null)) || (pid != null && host != null)) { System.err.println( "You have supplied both " + ARG_PATH + " as well as " + ARG_HOST + "/" + ARG_PORT + "/" + ARG_NAME + ". " + "You should either supply only " + ARG_PATH + " or " + ARG_HOST + "/" + ARG_PORT + "/" + ARG_NAME + " so that either a local or " + "remote shell client can be started"); } // Local else if (path != null) { try { checkNeo4jDependency(); } catch (ShellException e) { handleException(e, args); } startLocal(args, signalHandler); } // Remote else { String readonly = args.get(ARG_READONLY, null); if (readonly != null) { System.err.println( "Warning: -" + ARG_READONLY + " is ignored unless you connect with -" + ARG_PATH + "!"); } // Start server on the supplied process if (pid != null) { startServer(pid, args); } startRemote(args, signalHandler); } }
private void startServer(String pid, Args args) { String port = args.get("port", Integer.toString(SimpleAppServer.DEFAULT_PORT)); String name = args.get("name", SimpleAppServer.DEFAULT_NAME); try { String jarfile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()) .getAbsolutePath(); Object vm = attachMethod.invoke(null, pid); loadMethod.invoke(vm, jarfile, new ShellBootstrap(Integer.parseInt(port), name).serialize()); } catch (Exception e) { handleException(e, args); } }
private void startRemote(Args args, CtrlCHandler signalHandler) { try { String host = args.get(ARG_HOST, "localhost"); int port = args.getNumber(ARG_PORT, SimpleAppServer.DEFAULT_PORT).intValue(); String name = args.get(ARG_NAME, SimpleAppServer.DEFAULT_NAME); ShellClient client = ShellLobby.newClient( RmiLocation.location(host, port, name), getSessionVariablesFromArgs(args), signalHandler); if (!isCommandLine(args)) { System.out.println( "NOTE: Remote Neo4j graph database service '" + name + "' at port " + port); } grabPromptOrJustExecuteCommand(client, args); } catch (Exception e) { handleException(e, args); } }
private void startLocal(Args args, CtrlCHandler signalHandler) { String dbPath = args.get(ARG_PATH, null); if (dbPath == null) { System.err.println( "ERROR: To start a local Neo4j service and a " + "shell client on top of that you need to supply a path to a " + "Neo4j store or just a new path where a new store will " + "be created if it doesn't exist. -" + ARG_PATH + " /my/path/here"); return; } try { boolean readOnly = args.getBoolean(ARG_READONLY, false, true); tryStartLocalServerAndClient(dbPath, readOnly, args, signalHandler); } catch (Exception e) { handleException(e, args); } System.exit(0); }