/** * Create a new shell server with specific options. * * @param vertx the vertx * @return the created shell server */ static ShellServer create(Vertx vertx) { return new ShellServerImpl(vertx, new ShellServerOptions()); }
@Override public ShellServiceOptions setReaperInterval(long reaperInterval) { return (ShellServiceOptions) super.setReaperInterval(reaperInterval); }
@Override public ShellServiceOptions setSessionTimeout(long timeoutMillis) { return (ShellServiceOptions) super.setSessionTimeout(timeoutMillis); }
public static void toJson(ShellServerOptions obj, java.util.Map<String, Object> json) { json.put("reaperInterval", obj.getReaperInterval()); json.put("sessionTimeout", obj.getSessionTimeout()); if (obj.getWelcomeMessage() != null) { json.put("welcomeMessage", obj.getWelcomeMessage()); } } }
@Test public void testPrompt(TestContext context) { commands = new TestCommands(vertx); ShellServer server = ShellServer.create(vertx, new ShellServerOptions() .setWelcomeMessage("") .setSessionTimeout(100) .setReaperInterval(100)); server.shellHandler(shell -> shell.setPrompt(s -> "FOOPROMPT")); TestTermServer termServer = new TestTermServer(vertx); server.registerTermServer(termServer); server. registerCommandResolver(CommandResolver.baseCommands(vertx)). registerCommandResolver(commands). listen(context.asyncAssertSuccess()); TestTtyConnection conn = termServer.openConnection(); Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { context.assertEquals(null, conn.checkWritten("FOOPROMPTfoo\n")); process.stdinHandler(cp -> { context.fail(); }); process.endHandler(v -> { async.complete(); } ); process.end(); })); conn.read("foo\r"); async.awaitSuccess(5000); }
private void startShellServer(TestContext context, long sessionTimeout, long reaperInterval) { if (shellServer != null) { throw new IllegalStateException("Already started"); } Async latch = context.async(); shellServer = ShellServer.create(vertx, new ShellServerOptions().setSessionTimeout(sessionTimeout).setReaperInterval(reaperInterval)). registerTermServer(termServer). registerCommandResolver(registry). listen(context.asyncAssertSuccess(v -> latch.complete())); latch.awaitSuccess(20000); }
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ShellServerOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "reaperInterval": if (member.getValue() instanceof Number) { obj.setReaperInterval(((Number)member.getValue()).longValue()); } break; case "sessionTimeout": if (member.getValue() instanceof Number) { obj.setSessionTimeout(((Number)member.getValue()).longValue()); } break; case "welcomeMessage": if (member.getValue() instanceof String) { obj.setWelcomeMessage((String)member.getValue()); } break; } } }
@Override public ShellServiceOptions setWelcomeMessage(String welcomeMessage) { return (ShellServiceOptions) super.setWelcomeMessage(welcomeMessage); }
public ShellServerImpl(Vertx vertx, ShellServerOptions options) { this.vertx = vertx; this.welcomeMessage = options.getWelcomeMessage(); this.termServers = new ArrayList<>(); this.timeoutMillis = options.getSessionTimeout(); this.sessions = new ConcurrentHashMap<>(); this.reaperInterval = options.getReaperInterval(); this.resolvers = new CopyOnWriteArrayList<>(); this.commandManager = new InternalCommandManager(resolvers); // Register builtin commands so they are listed in help resolvers.add(() -> Arrays.asList( CommandBuilder.command("exit").processHandler(process -> {}).build(vertx), CommandBuilder.command("logout").processHandler(process -> {}).build(vertx), CommandBuilder.command("jobs").processHandler(process -> {}).build(vertx), CommandBuilder.command("fg").processHandler(process -> {}).build(vertx), CommandBuilder.command("bg").processHandler(process -> {}).build(vertx) )); }
public ShellServiceImpl(Vertx vertx, ShellServiceOptions options) { this.vertx = vertx; this.options = options; this.server = ShellServer.create(vertx, new ShellServerOptions(options)); this.registry = CommandRegistry.getShared(vertx); }
public static io.vertx.ext.shell.ShellServer create(io.vertx.ext.shell.ShellServer j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.ext.shell.ShellServer.create(vertx, options != null ? new io.vertx.ext.shell.ShellServerOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } }