new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) {
@Test public void testDuplicateRegistration(TestContext context) { CommandRegistry registry = CommandRegistry.getShared(vertx); Command a = CommandBuilder.command("a").build(vertx); Command b = CommandBuilder.command("b").build(vertx); registry.registerCommand(a, context.asyncAssertSuccess(reg -> { registry.registerCommands(Arrays.asList(a, b), context.asyncAssertFailure(err -> { context.assertEquals(1, registry.commands().size()); context.assertNotNull(registry.getCommand("a")); })); })); }
@Test public void testRegister(TestContext context) { CommandRegistry registry = CommandRegistry.getShared(vertx); CommandBuilder command = CommandBuilder.command("hello"); registry.registerCommand(command.build(vertx), context.asyncAssertSuccess(reg -> { registry.unregisterCommand("hello", context.asyncAssertSuccess(done -> { context.assertEquals(Collections.emptyList(), registry.commands()); })); })); }
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); }
/** * Like {@link io.vertx.rxjava.ext.shell.command.CommandRegistry#registerCommand}, without a completion handler. * @param command * @return */ public io.vertx.rxjava.ext.shell.command.CommandRegistry registerCommand(io.vertx.rxjava.ext.shell.command.Command command) { delegate.registerCommand(command.getDelegate()); return this; }
@Test public void testUndeployInVerticleContext(TestContext context) { CommandRegistry registry = CommandRegistry.getShared(vertx); Async async = context.async(); AtomicReference<String> ref = new AtomicReference<>(); vertx.deployVerticle(new AbstractVerticle() { @Override public void start(Future<Void> startFuture) throws Exception { CommandBuilder command = CommandBuilder.command("hello"); command.processHandler(process -> { }); registry.registerCommand(command.build(vertx), ar -> { if (ar.succeeded()) { startFuture.complete(); } else { startFuture.fail(ar.cause()); } }); } }, context.asyncAssertSuccess(id -> { ref.set(id); async.complete(); })); async.awaitSuccess(5000); vertx.undeploy(ref.get(), context.asyncAssertSuccess(v -> { context.assertEquals(Collections.emptyList(), registry.commands()); })); }
@Test public void testUndeployCommands(TestContext context) throws Exception { Async async = context.async(); registry.registerCommands( Arrays.asList(CommandBuilder.command("a").build(vertx), CommandBuilder.command("b").build(vertx)), context.asyncAssertSuccess(list -> async.complete())); async.awaitSuccess(2000); Set<String> afterIds = new HashSet<>(vertx.deploymentIDs()); System.out.println(afterIds); context.assertEquals(1, afterIds.size()); String deploymentId = afterIds.iterator().next(); Async async2 = context.async(); registry.unregisterCommand("a", context.asyncAssertSuccess(v -> async2.complete())); async2.awaitSuccess(2000); context.assertTrue(vertx.deploymentIDs().contains(deploymentId)); Async async3 = context.async(); registry.unregisterCommand("b", context.asyncAssertSuccess(v -> async3.complete())); async3.awaitSuccess(2000); context.assertFalse(vertx.deploymentIDs().contains(deploymentId)); } }
/** * Like {@link io.vertx.rxjava.ext.shell.command.CommandRegistry#unregisterCommand}, without a completion handler. * @param commandName * @return */ public io.vertx.rxjava.ext.shell.command.CommandRegistry unregisterCommand(String commandName) { delegate.unregisterCommand(commandName); return this; }
/** * Like {@link io.vertx.rxjava.ext.shell.command.CommandRegistry#registerCommands}, without a completion handler. * @param commands * @return */ public io.vertx.rxjava.ext.shell.command.CommandRegistry registerCommands(List<io.vertx.rxjava.ext.shell.command.Command> commands) { delegate.registerCommands(commands.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList())); return this; }
/** * Create a new registry. * @param vertx the vertx instance * @return the created registry */ public static io.vertx.rxjava.ext.shell.command.CommandRegistry create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.shell.command.CommandRegistry ret = io.vertx.rxjava.ext.shell.command.CommandRegistry.newInstance(io.vertx.ext.shell.command.CommandRegistry.create(vertx.getDelegate())); return ret; }
/** * Get the shared registry for the Vert.x instance. * @param vertx the vertx instance * @return the shared registry */ public static io.vertx.rxjava.ext.shell.command.CommandRegistry getShared(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.shell.command.CommandRegistry ret = io.vertx.rxjava.ext.shell.command.CommandRegistry.newInstance(io.vertx.ext.shell.command.CommandRegistry.getShared(vertx.getDelegate())); return ret; }
/** * Like {@link io.vertx.rxjava.ext.shell.command.CommandRegistry#registerCommand}, without a completion handler. * @param command * @return */ public io.vertx.rxjava.ext.shell.command.CommandRegistry registerCommand(io.vertx.rxjava.ext.shell.command.Command command) { delegate.registerCommand(command.getDelegate()); return this; }
/** * Unregister a command. * @param commandName the command name * @param completionHandler notified when the command is unregistered * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandRegistry unregisterCommand(String commandName, Handler<AsyncResult<Void>> completionHandler) { delegate.unregisterCommand(commandName, completionHandler); return this; }
/** * Like {@link io.vertx.rxjava.ext.shell.command.CommandRegistry#registerCommands}, without a completion handler. * @param commands * @return */ public io.vertx.rxjava.ext.shell.command.CommandRegistry registerCommands(List<io.vertx.rxjava.ext.shell.command.Command> commands) { delegate.registerCommands(commands.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList())); return this; }
/** * Create a new registry. * @param vertx the vertx instance * @return the created registry */ public static io.vertx.rxjava.ext.shell.command.CommandRegistry create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.shell.command.CommandRegistry ret = io.vertx.rxjava.ext.shell.command.CommandRegistry.newInstance(io.vertx.ext.shell.command.CommandRegistry.create(vertx.getDelegate())); return ret; }
@Override public void start() throws Exception { Command helloWorld = CommandBuilder.command("hello-world"). processHandler(process -> { process.write("hello world\n"); process.end(); }).build(vertx); ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(helloWorld); service.start(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace(); } }); } }
/** * Get the shared registry for the Vert.x instance. * @param vertx the vertx instance * @return the shared registry */ public static io.vertx.rxjava.ext.shell.command.CommandRegistry getShared(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.shell.command.CommandRegistry ret = io.vertx.rxjava.ext.shell.command.CommandRegistry.newInstance(io.vertx.ext.shell.command.CommandRegistry.getShared(vertx.getDelegate())); return ret; }
/** * Register a command * @param command the command to register * @param completionHandler notified when the command is registered * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandRegistry registerCommand(io.vertx.rxjava.ext.shell.command.Command command, Handler<AsyncResult<io.vertx.rxjava.ext.shell.command.Command>> completionHandler) { delegate.registerCommand(command.getDelegate(), new Handler<AsyncResult<io.vertx.ext.shell.command.Command>>() { public void handle(AsyncResult<io.vertx.ext.shell.command.Command> ar) { if (ar.succeeded()) { completionHandler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.shell.command.Command.newInstance(ar.result()))); } else { completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }
/** * Unregister a command. * @param commandName the command name * @param completionHandler notified when the command is unregistered * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandRegistry unregisterCommand(String commandName, Handler<AsyncResult<Void>> completionHandler) { delegate.unregisterCommand(commandName, completionHandler); return this; }
/** * Register a list of commands. * @param commands the commands to register * @param completionHandler notified when the command is registered * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.command.CommandRegistry registerCommands(List<io.vertx.rxjava.ext.shell.command.Command> commands, Handler<AsyncResult<List<io.vertx.rxjava.ext.shell.command.Command>>> completionHandler) { delegate.registerCommands(commands.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList()), new Handler<AsyncResult<java.util.List<io.vertx.ext.shell.command.Command>>>() { public void handle(AsyncResult<java.util.List<io.vertx.ext.shell.command.Command>> ar) { if (ar.succeeded()) { completionHandler.handle(io.vertx.core.Future.succeededFuture(ar.result().stream().map(elt -> io.vertx.rxjava.ext.shell.command.Command.newInstance(elt)).collect(java.util.stream.Collectors.toList()))); } else { completionHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } }); return this; }