new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) {
@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(); } }); } }
@Override public void start() throws Exception { Command starwars = CommandBuilder.command("echokeyboard"). processHandler(process -> { // Echo process.stdinHandler(keys -> { process.write(keys.replace('\r', '\n')); }); // Terminate when user hits Ctrl-C process.interruptHandler(v -> { process.end(); }); }).build(vertx); ShellService service = ShellService.create(vertx, new ShellServiceOptions().setTelnetOptions( new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) { ar.cause().printStackTrace(); } }); } }
new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(starwars); service.start(ar -> { if (!ar.succeeded()) {
new TelnetTermOptions().setHost("localhost").setPort(3000) )); CommandRegistry.getShared(vertx).registerCommand(helloWorld); service.start(ar -> { if (!ar.succeeded()) {
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); }
/** * 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; }
/** * 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; }
@Before public void before() throws Exception { vertx = Vertx.vertx(); registry = CommandRegistry.getShared(vertx); }
@Before public void before() throws Exception { File target = new File(System.getProperty("vertx.test.dir", "target")); root = Files.createTempDirectory(target.toPath(), "fs").toFile(); System.setProperty("vertx.cwd", root.getAbsolutePath()); vertx = Vertx.vertx(); registry = CommandRegistry.getShared(vertx); helper = new FsHelper(); }
@Test public void testCloseRegistryOnVertxClose(TestContext context) { Vertx vertx = Vertx.vertx(); CommandRegistryImpl registry = (CommandRegistryImpl) CommandRegistry.getShared(vertx); context.assertFalse(registry.isClosed()); vertx.close(context.asyncAssertSuccess(v -> { context.assertTrue(registry.isClosed()); })); }
@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 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()); })); })); }
@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")); })); })); }
@Override public void testExec(TestContext context) throws Exception { AtomicReference<Vertx> execCommand = new AtomicReference<>(); CommandRegistry registry = CommandRegistry.getShared(vertx); registry.registerCommand(CommandBuilder.command("the-command").processHandler(process -> { context.assertNotNull(Vertx.currentContext()); context.assertNotNull(process.session()); execCommand.set(process.vertx()); context.assertEquals(-1, process.width()); context.assertEquals(-1, process.height()); context.assertEquals(Arrays.asList("arg1", "arg2"), process.args()); context.assertTrue(process.isForeground()); StringBuilder input = new StringBuilder(); process.stdinHandler(data -> { input.append(data); if (input.toString().equals("the_input")) { process.end(2); } }); process.write("the_output"); }).build(vertx)); super.testExec(context); assertEquals(execCommand.get(), vertx); } }
@Before public void before(TestContext context) { registry = CommandRegistry.getShared(rule.vertx()); registry.registerCommand(CommandBuilder.command("foo").processHandler(proc -> { }).completionHandler( completion -> { completion.complete("completed_by_foo", false); } ).build(rule.vertx()), context.asyncAssertSuccess(v1 -> { registry.registerCommand(CommandBuilder.command("bar").processHandler(proc -> { }).build(rule.vertx()), context.asyncAssertSuccess(v2 -> { registry.registerCommand(CommandBuilder.command("baz").processHandler(proc -> { }).build(rule.vertx()), context.asyncAssertSuccess(v3 -> { registry.registerCommand(CommandBuilder.command("err").processHandler(proc -> { }).completionHandler(completion -> { throw new RuntimeException("expected"); }).build(rule.vertx()), context.asyncAssertSuccess()); })); })); })); mgr = new InternalCommandManager(registry); }
CommandRegistry mgr = CommandRegistry.getShared(vertx);