reactor.fn.Function Java Examples

The following examples show how to use reactor.fn.Function. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestListenAddress.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void testBindZero() throws Exception {
	Environment.initializeIfEmpty().assignErrorJournal();

	HttpServer<Buffer, Buffer> httpServer = NetStreams
			.httpServer(new Function<HttpServerSpec<Buffer, Buffer>, HttpServerSpec<Buffer, Buffer>>() {

				@Override
				public HttpServerSpec<Buffer, Buffer> apply(HttpServerSpec<Buffer, Buffer> server) {
					return server
							.codec(new GpfdistCodec())
							.listen(0);
				}
			});
	httpServer.start().awaitSuccess();
	InetSocketAddress address = httpServer.getListenAddress();
	assertThat(address, notNullValue());
	assertThat(address.getPort(), not(0));
	httpServer.shutdown();
}
 
Example #2
Source File: Reactor2StompCodec.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Function<Buffer, Message<byte[]>> decoder(final Consumer<Message<byte[]>> messageConsumer) {
	return new DecodingFunction(this.stompDecoder, messageConsumer);
}
 
Example #3
Source File: Reactor2StompCodec.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Function<Message<byte[]>, Buffer> encoder() {
	return this.encodingFunction;
}
 
Example #4
Source File: GpfdistCodec.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Override
public Function<Buffer, Buffer> decoder(Consumer<Buffer> next) {
	return null;
}
 
Example #5
Source File: GpfdistServer.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
private HttpServer<Buffer, Buffer> createProtocolListener()
		throws Exception {

	final Stream<Buffer> stream = Streams
	.wrap(processor)
	.window(flushCount, flushTime, TimeUnit.SECONDS)
	.flatMap(new Function<Stream<Buffer>, Publisher<Buffer>>() {

		@Override
		public Publisher<Buffer> apply(Stream<Buffer> t) {

			return t.reduce(new Buffer(), new BiFunction<Buffer, Buffer, Buffer>() {

				@Override
				public Buffer apply(Buffer prev, Buffer next) {
					return prev.append(next);
				}
			});
		}
	})
	.process(RingBufferWorkProcessor.<Buffer>create("gpfdist-sink-worker", 8192, false));

	HttpServer<Buffer, Buffer> httpServer = NetStreams
			.httpServer(new Function<HttpServerSpec<Buffer, Buffer>, HttpServerSpec<Buffer, Buffer>>() {

				@Override
				public HttpServerSpec<Buffer, Buffer> apply(HttpServerSpec<Buffer, Buffer> server) {
					return server
							.codec(new GpfdistCodec())
							.listen(port);
				}
			});

	httpServer.get("/data", new ReactorChannelHandler<Buffer, Buffer, HttpChannel<Buffer,Buffer>>() {

		@Override
		public Publisher<Void> apply(HttpChannel<Buffer, Buffer> request) {
			request.responseHeaders().removeTransferEncodingChunked();
			request.addResponseHeader("Content-type", "text/plain");
			request.addResponseHeader("Expires", "0");
			request.addResponseHeader("X-GPFDIST-VERSION", "Spring Dataflow");
			request.addResponseHeader("X-GP-PROTO", "1");
			request.addResponseHeader("Cache-Control", "no-cache");
			request.addResponseHeader("Connection", "close");

			return request.writeWith(stream
					.take(batchCount)
					.timeout(batchTimeout, TimeUnit.SECONDS, Streams.<Buffer>empty())
					.concatWith(Streams.just(Buffer.wrap(new byte[0]))))
					.capacity(1l);
		}
	});

	httpServer.start().awaitSuccess();
	log.info("Server running using address=[" + httpServer.getListenAddress() + "]");
	localPort = httpServer.getListenAddress().getPort();
	return httpServer;
}