/** * Set a resume handler, this handler is called when the command is resumed, for instance user * types <code>bg</code> or <code>fg</code> to resume the command. * @param handler the interrupt handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess resumeHandler(Handler<Void> handler) { delegate.resumeHandler(handler); return this; }
/** * Set a resume handler, this handler is called when the command is resumed, for instance user * types <code>bg</code> or <code>fg</code> to resume the command. * @param handler the interrupt handler * @return this command */ public io.vertx.rxjava.ext.shell.command.CommandProcess resumeHandler(Handler<Void> handler) { delegate.resumeHandler(handler); return this; }
private void scheduleSleep(CommandProcess process, long millis) { Vertx vertx = process.vertx(); if (millis > 0) { long now = System.currentTimeMillis(); AtomicLong remaining = new AtomicLong(-1); long id = process.vertx().setTimer(millis, v -> { process.end(); }); process.suspendHandler(v -> { vertx.cancelTimer(id); remaining.set(millis - (System.currentTimeMillis() - now)); }); process.resumeHandler(v -> { scheduleSleep(process, remaining.get()); }); process.interruptHandler(v -> { process.end(); }); process.endHandler(v -> { vertx.cancelTimer(id); }); } else { process.end(); } } }
process.resumeHandler(v -> { context.assertTrue(process.isForeground()); context.assertEquals(0L, latch2.getCount());
cmdContext.set(Vertx.currentContext()); process.suspendHandler(v -> fooSusp.complete()); process.resumeHandler(v -> fooResumed.complete()); process.endHandler(v -> { endLatch.complete();
@Test public void testResumeSuspendedProcess(TestContext context) throws Exception { CommandBuilder builder = CommandBuilder.command("hello"); AtomicInteger status = new AtomicInteger(); Async runningLatch = context.async(); Async suspendedLatch = context.async(); Async resumedLatch = context.async(2); builder.processHandler(process -> { process.suspendHandler(v -> { suspendedLatch.complete(); }); process.resumeHandler(v -> { context.assertEquals(0, status.getAndIncrement()); resumedLatch.countDown(); }); runningLatch.complete(); }); Context ctx = vertx.getOrCreateContext(); Process process = createProcessInContext(ctx, builder.build(vertx)); process.run(); runningLatch.awaitSuccess(10000); process.suspend(); suspendedLatch.awaitSuccess(10000); process.resume(v -> { context.assertEquals(ctx, Vertx.currentContext()); context.assertEquals(1, status.getAndIncrement()); resumedLatch.countDown(); }); }
@Test public void testSetStdinOnResumeToForeground(TestContext context) throws Exception { Async fooRunning = context.async(); Async fooSusp = context.async(); Async fooResumed = context.async(); Async readLatch = context.async(); commands.add( CommandBuilder.command("foo").processHandler(process -> { process.suspendHandler(v -> fooSusp.complete()); process.resumeHandler(v -> fooResumed.complete()); process.stdinHandler(line -> { context.assertEquals("foo_msg", line); readLatch.complete(); }); fooRunning.complete(); })); TestTtyConnection conn = new TestTtyConnection(vertx); ShellImpl shell = createShell(conn); shell.init().readline(); conn.read("foo\r"); fooRunning.awaitSuccess(2000); conn.sendEvent(TtyEvent.SUSP); fooSusp.awaitSuccess(2000); conn.read("fg\r"); fooResumed.awaitSuccess(2000); conn.read("foo_msg"); }
CommandBuilder.command("foo").processHandler(process -> { process.suspendHandler(v -> fooSusp.complete()); process.resumeHandler(v -> fooResumed.complete()); process.foregroundHandler(v -> fooToForeground.complete()); process.stdinHandler(line -> {
process.resumeHandler(v -> { context.assertFalse(process.isForeground()); context.assertEquals(0, latch2.count());
latch2.countDown(); }); process.resumeHandler(v -> { context.assertFalse(process.isForeground()); });