private void startShell(BundleContext context, CommandProcessor processor) { Dictionary<String, Object> dict = new Hashtable<>(); dict.put(CommandProcessor.COMMAND_SCOPE, "gogo"); Set<ServiceRegistration<?>> currentRegs = new HashSet<>(); // register converters currentRegs.add(context.registerService(Converter.class.getName(), new Converters(context.getBundle(0).getBundleContext()), null)); // register commands dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions); currentRegs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions); currentRegs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions); currentRegs.add(context.registerService(Posix.class.getName(), new Posix(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions); currentRegs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict)); Shell shell = new Shell(context, processor); dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions); currentRegs.add(context.registerService(Shell.class.getName(), shell, dict)); synchronized (regs) { regs.addAll(currentRegs); currentRegs.clear(); } // start shell on a separate thread... executor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "Gogo shell")); shellJob = new StartShellJob(context, processor); executor.submit(shellJob); }
private void stopShell() { if (executor != null && !(executor.isShutdown() || executor.isTerminated())) { if (shellJob != null) { shellJob.terminate(); } executor.shutdown(); try { if (!executor.awaitTermination(5, TimeUnit.SECONDS)) { System.err.println("!!! FAILED TO STOP EXECUTOR !!!"); Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet()) { Thread t = entry.getKey(); System.err.printf("Thread: %s (%s): %s\n", t.getName(), t.getState(), Arrays.toString(entry.getValue())); } } } catch (InterruptedException e) { // Restore administration... Thread.currentThread().interrupt(); } executor = null; } }
private void startShell(BundleContext context, CommandProcessor processor) { Dictionary<String, Object> dict = new Hashtable<>(); dict.put(CommandProcessor.COMMAND_SCOPE, "gogo"); Set<ServiceRegistration<?>> currentRegs = new HashSet<>(); // register converters currentRegs.add(context.registerService(Converter.class.getName(), new Converters(context.getBundle(0).getBundleContext()), null)); // register commands dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions); currentRegs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions); currentRegs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions); currentRegs.add(context.registerService(Posix.class.getName(), new Posix(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions); currentRegs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict)); Shell shell = new Shell(context, processor); dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions); currentRegs.add(context.registerService(Shell.class.getName(), shell, dict)); synchronized (regs) { regs.addAll(currentRegs); currentRegs.clear(); } // start shell on a separate thread... executor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "Gogo shell")); shellJob = new StartShellJob(context, processor); executor.submit(shellJob); }
private void stopShell() { if (executor != null && !(executor.isShutdown() || executor.isTerminated())) { if (shellJob != null) { shellJob.terminate(); } executor.shutdown(); try { if (!executor.awaitTermination(5, TimeUnit.SECONDS)) { System.err.println("!!! FAILED TO STOP EXECUTOR !!!"); Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet()) { Thread t = entry.getKey(); System.err.printf("Thread: %s (%s): %s\n", t.getName(), t.getState(), Arrays.toString(entry.getValue())); } } } catch (InterruptedException e) { // Restore administration... Thread.currentThread().interrupt(); } executor = null; } }