@Test public void testPumpBasic() throws Exception { FakeReadStream<MyClass> rs = new FakeReadStream<>(); FakeWriteStream<MyClass> ws = new FakeWriteStream<>(); Pump p = Pump.pump(rs, ws, 1001); for (int i = 0; i < 10; i++) { // Repeat a few times p.start(); List<MyClass> inp = new ArrayList<>(); for (int j = 0; j < 10; j++) { MyClass myClass = new MyClass(); inp.add(myClass); rs.addData(myClass); } assertEquals(inp, ws.received); assertFalse(rs.paused); assertEquals(0, rs.pauseCount); assertEquals(0, rs.resumeCount); p.stop(); ws.clearReceived(); MyClass myClass = new MyClass(); rs.addData(myClass); assertEquals(0, ws.received.size()); } }
@Test(expected = NullPointerException.class) public void testPumpReadStreamNull() { FakeReadStream<MyClass> rs = new FakeReadStream<>(); Pump.pump(rs, null); }
/** * Start the Pump. The Pump can be started and stopped multiple times. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.Pump start() { delegate.start(); return this; }
/** * Stop the Pump. The Pump can be started and stopped multiple times. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.Pump stop() { delegate.stop(); return this; }
/** * Return the total number of items pumped by this pump. * @return */ public int numberPumped() { int ret = delegate.numberPumped(); return ret; }
@Test(expected = NullPointerException.class) public void testPumpReadStreamNull2() { FakeReadStream<MyClass> rs = new FakeReadStream<>(); Pump.pump(rs, null, 1000); }
/** * Start the Pump. The Pump can be started and stopped multiple times. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.Pump start() { delegate.start(); return this; }
/** * Stop the Pump. The Pump can be started and stopped multiple times. * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.streams.Pump stop() { delegate.stop(); return this; }
/** * Return the total number of items pumped by this pump. * @return */ public int numberPumped() { int ret = delegate.numberPumped(); return ret; }
@Override public HttpServerFileUpload streamToFileSystem(String filename) { pause(); context.owner().fileSystem().open(filename, new OpenOptions(), ar -> { if (ar.succeeded()) { file = ar.result(); Pump p = Pump.pump(HttpServerFileUploadImpl.this, ar.result()); p.start(); resume(); } else { notifyExceptionHandler(ar.cause()); } }); return this; }
@Test(expected = NullPointerException.class) public void testPumpWriteStreamNull() { FakeWriteStream<MyClass> ws = new FakeWriteStream<>(); Pump.pump(null, ws); }
public void start() { init(); netSocket.pause(); consumer.pause(); // from remote tcp to local bus fromRemoteTcpToLocalBus.start(); // from local bus to remote tcp consumer.handler(bufferMessage -> { boolean isBridged = isBridged(bufferMessage); if (!isBridged) { boolean tenantMatch = tenantMatch(bufferMessage); if(tenantMatch) { netSocketWrapper.sendMessageToClient(bufferMessage.body()); } } }); consumer.resume(); netSocket.resume(); }
/** * Stop the proxy request * * @return the front request if stopped / {@code null} means nothing happened */ private HttpServerRequest stop() { HttpServerRequest request = frontRequest; if (request != null) { // Abrupt close frontRequest = null; if (requestPump != null) { requestPump.stop(); requestPump = null; } if (responsePump != null) { responsePump.stop(); responsePump = null; } return request; } return null; }
@Override public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { req.pause(); String filename = UUID.randomUUID() + ".uploaded"; vertx.fileSystem().open(filename, new OpenOptions(), ares -> { AsyncFile file = ares.result(); Pump pump = Pump.pump(req, file); req.endHandler(v1 -> file.close(v2 -> { System.out.println("Uploaded to " + filename); req.response().end(); })); pump.start(); req.resume(); }); }).listen(8080); } }
@Test public void testPumpBasic() throws Exception { FakeReadStream<MyClass> rs = new FakeReadStream<>(); FakeWriteStream<MyClass> ws = new FakeWriteStream<>(); Pump p = Pump.pump(rs, ws, 1001); for (int i = 0; i < 10; i++) { // Repeat a few times p.start(); List<MyClass> inp = new ArrayList<>(); for (int j = 0; j < 10; j++) { MyClass myClass = new MyClass(); inp.add(myClass); rs.addData(myClass); } assertEquals(inp, ws.received); assertFalse(rs.paused); assertEquals(0, rs.pauseCount); assertEquals(0, rs.resumeCount); p.stop(); ws.clearReceived(); MyClass myClass = new MyClass(); rs.addData(myClass); assertEquals(0, ws.received.size()); } }
@Test(expected = NullPointerException.class) public void testPumpWriteStreamNull2() { FakeWriteStream<MyClass> ws = new FakeWriteStream<>(); Pump.pump(null, ws, 1000); }
public void stop() { // from remote tcp to local bus fromRemoteTcpToLocalBus.stop(); // from local bus to remote tcp netSocketWrapper.stop();// stop write to remote tcp socket consumer.handler(null);// stop read from bus }
@Override public void start() throws Exception { NetServerOptions options = new NetServerOptions() .setSsl(true).setKeyStoreOptions(new JksOptions().setPath("server-keystore.jks").setPassword("wibble")); vertx.createNetServer(options).connectHandler(sock -> { // Create a pump Pump.pump(sock, sock).start(); }).listen(1234); System.out.println("Echo server is now listening"); } }