@Override public void run() throws SuspendExecution, InterruptedException { // Get first result Channel<Channel<T>> resWrapper = results.receive(); while (resWrapper != null) { // Get wrapper Channel<T> res = resWrapper.receive(); // Get first actual result T out = res.receive(); while(out != null) { // Send to output channel to.send(out); // Increment counter transferred.incrementAndGet(); // Get next result out = res.receive(); } resWrapper = results.receive(); } // No more results, quit } })).start();
@Suspendable public T receive() { try { return channel.receive(); } catch (Exception e) { throw new VertxException(e); } }
@Suspendable public T receive(long timeout) { try { return channel.receive(timeout, TimeUnit.MILLISECONDS); } catch (Exception e) { throw new VertxException(e); } } }
private void sequentialTransfer() throws InterruptedException, SuspendExecution { S s = from.receive(); while (s != null) { // Build result channel final Channel<T> res = resultChannelBuilder.run(); // Process transformer.call(s, res); T out = res.receive(); while(out != null) { // Send to output channel to.send(out); // Increment counter transferred.incrementAndGet(); // Get next result out = res.receive(); } s = from.receive(); } } }
private void assertEvents(Channel<TimingEvent<Integer>> eventCh, int start, int end) throws SuspendExecution, InterruptedException { Set<Integer> actual = Sets.newHashSetWithExpectedSize(end - start); Set<Integer> expected = Sets.newHashSetWithExpectedSize(end - start); for (int i = start; i < end; ++i) { expected.add(i); } int cur = start; while (true) { TimingEvent<Integer> t = eventCh.receive(); if (t == null) { break; } Integer i = t.response; actual.add(i); cur++; } assertEquals(cur, end); assertEquals(actual, expected); }
@Override @Suspendable public void start() throws Exception { ai = new AsyncInterfaceImpl(vertx); completeChannel = Channels.newChannel(1, Channels.OverflowPolicy.THROW); try { String testName = config().getString("testName"); Method meth = this.getClass().getDeclaredMethod(testName); meth.setAccessible(true); meth.invoke(this); } catch (AssertionError e) { e.printStackTrace(); throw new IllegalStateException("Tests failed", e); } catch (Exception e) { e.printStackTrace(); throw new IllegalStateException("Failed to invoke test", e); } completeChannel.receive(10, TimeUnit.SECONDS); }
@Override @Suspendable public void start() throws Exception { ai = new AsyncInterfaceImpl(vertx); completeChannel = Channels.newChannel(1, Channels.OverflowPolicy.THROW); try { String testName = config().getString("testName"); Method meth = this.getClass().getDeclaredMethod(testName); meth.setAccessible(true); meth.invoke(this); } catch (AssertionError e) { e.printStackTrace(); throw new IllegalStateException("Tests failed", e); } catch (Exception e) { e.printStackTrace(); throw new IllegalStateException("Failed to invoke test", e); } completeChannel.receive(10, TimeUnit.SECONDS); }
@Override public void run() throws SuspendExecution, InterruptedException { // Get first job Pair<S, Channel<Channel<T>>> job = jobs.receive(); while(job != null) { // Build result channel final Channel<T> res = resultChannelBuilder.run(); // Process transformer.call(job.getFirst(), res); final Channel<Channel<T>> resWrapper = job.getSecond(); // Send result asynchronously strandFactory.newStrand(SuspendableUtils.runnableToCallable(new SuspendableRunnable() { @Override public void run() throws SuspendExecution, InterruptedException { resWrapper.send(res); } })).start(); // Get next job job = jobs.receive(); } // No more jobs, close results channel and quit worker results.close(); } })).start();