/** * Get some data from the session * @param key the key of the data * @return the data */ public <T> T get(String key) { T ret = (T) delegate.get(key); return ret; }
/** * Put some data in a session * @param key the key for the data * @param obj the data * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.session.Session put(String key, Object obj) { delegate.put(key, obj); return this; }
/** * Remove some data from the session * @param key the key of the data * @return the data that was there or null if none there */ public <T> T remove(String key) { T ret = (T) delegate.remove(key); return ret; }
@Override public void process(CommandProcess process) { if (process.args().size() > 0) { String cwd = process.session().get("cwd"); new FsHelper().cd(process.vertx().fileSystem(), cwd, dir, ar -> { if (ar.succeeded()) { process.session().put("cwd", ar.result()); process.end(); } else { process.write("cd: No such file or directory\n"); process.end(); } }); } else { process.session().remove("cwd"); process.end(); } }
@Test public void testSessionPut(TestContext context) throws Exception { Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { Session session = process.session(); context.assertNotNull(session); context.assertNull(session.get("the_key")); session.put("the_key", "the_value"); process.end(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create(); Session session = new SessionImpl(); job.setSession(session).setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { context.assertEquals(0, job.process().exitCode()); context.assertEquals("the_value", session.get("the_key")); async.complete(); })).run(); }
/** * Create a new empty session. * @return the created session */ public static io.vertx.rxjava.ext.shell.session.Session create() { io.vertx.rxjava.ext.shell.session.Session ret = io.vertx.rxjava.ext.shell.session.Session.newInstance(io.vertx.ext.shell.session.Session.create()); return ret; }
@Test public void testSessionRemove(TestContext context) throws Exception { Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { Session session = process.session(); context.assertNotNull(session); context.assertEquals("the_value", session.remove("the_key")); process.end(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create(); Session session = new SessionImpl(); session.put("the_key", "the_value"); job.setSession(session).setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { context.assertEquals(0, job.process().exitCode()); context.assertNull(session.get("the_key")); async.complete(); })).run(); }
@Test public void testSessionGet(TestContext context) throws Exception { Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { Session session = process.session(); context.assertNotNull(session); context.assertEquals("the_value", session.get("the_key")); process.end(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Session session = new SessionImpl(); session.put("the_key", "the_value"); Pty pty = Pty.create(); job.setSession(session).setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { context.assertEquals(0, job.process().exitCode()); async.complete(); })).run(); }
/** * Create a new empty session. * @return the created session */ public static io.vertx.rxjava.ext.shell.session.Session create() { io.vertx.rxjava.ext.shell.session.Session ret = io.vertx.rxjava.ext.shell.session.Session.newInstance(io.vertx.ext.shell.session.Session.create()); return ret; }
/** * Get some data from the session * @param key the key of the data * @return the data */ public <T> T get(String key) { T ret = (T) delegate.get(key); return ret; }
/** * Put some data in a session * @param key the key for the data * @param obj the data * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.shell.session.Session put(String key, Object obj) { delegate.put(key, obj); return this; }
private Process createProcessInContext(Context context, Command command) throws Exception { CompletableFuture<Process> fut = new CompletableFuture<>(); context.runOnContext(v -> { Process process = command.createProcess().setSession(Session.create()).setTty(Pty.create().slave()); fut.complete(process); }); return fut.get(2000, TimeUnit.MILLISECONDS); }
/** * Remove some data from the session * @param key the key of the data * @return the data that was there or null if none there */ public <T> T remove(String key) { T ret = (T) delegate.remove(key); return ret; }
public static <T>java.lang.Object get(io.vertx.ext.shell.session.Session j_receiver, java.lang.String key) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.get(key)); } public static <T>java.lang.Object remove(io.vertx.ext.shell.session.Session j_receiver, java.lang.String key) {
public static io.vertx.ext.shell.session.Session put(io.vertx.ext.shell.session.Session j_receiver, java.lang.String key, java.lang.Object obj) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.put(key, io.vertx.core.impl.ConversionHelper.toObject(obj))); return j_receiver; } public static <T>java.lang.Object get(io.vertx.ext.shell.session.Session j_receiver, java.lang.String key) {
@Test public void testSuspendReadyProcess(TestContext context) { CommandBuilder builder = CommandBuilder.command("hello"); builder.processHandler(process -> context.fail()); Process process = builder.build(vertx).createProcess().setSession(Session.create()).setTty(Pty.create().slave()); try { process.suspend(); context.fail(); } catch (Exception ignore) { } }
public static <T>java.lang.Object remove(io.vertx.ext.shell.session.Session j_receiver, java.lang.String key) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.remove(key)); } }
@Override public void process(CommandProcess process) { InternalCommandManager mgr = process.session().get("vert.x-command-manager"); List<Command> commands = mgr.getResolvers().stream().flatMap(r -> r.commands().stream()).distinct().collect(Collectors.toList()); process.write("available commands:\n"); for (Command command : commands) { process.write(command.name()).write("\n"); } process.end(); } }
public ShellImpl(Term term, InternalCommandManager commandManager) { session.put("vert.x-command-manager", commandManager); this.id = UUID.randomUUID().toString(); this.jobController = new JobControllerImpl(); this.commandManager = commandManager; this.closedFuture = Future.future(); this.term = term; if (term != null) { term.setSession(session); jobController.foregroundUpdatedHandler(job -> { if (job == null) { readline(); } }); } }
@Test public void testResumeReadyProcess(TestContext context) { CommandBuilder builder = CommandBuilder.command("hello"); builder.processHandler(process -> context.fail()); Process process = builder.build(vertx).createProcess().setSession(Session.create()).setTty(Pty.create().slave()); try { process.resume(); context.fail(); } catch (Exception ignore) { } }