/** * Build a simple Netty HTTP server listening on 127.0.0.1 and 12012 * @return a simple HTTP Server */ public static HttpServer<Buffer, Buffer> httpServer() { return httpServer(DEFAULT_BIND_ADDRESS); }
return tcpClient(DEFAULT_BIND_ADDRESS, port);
/** * Utils to read the ChannelStream underlying channel */ @SuppressWarnings("unchecked") public static <E, IN, OUT> E delegate(ChannelStream<IN, OUT> channelStream) { return (E) delegate(channelStream, Object.class); }
/** * Bind a new TCP server to "loopback" on port {@literal 12012}. By default the default server implementation is * scanned * from the classpath on Class init. Support for Netty first and ZeroMQ then is provided as long as the relevant * library dependencies are on the classpath. * <p> * To reply data on the active connection, {@link ReactorChannel#writeWith} can subscribe to any passed {@link org.reactivestreams.Publisher}. * <p> * Note that {@link reactor.rx.Stream#getCapacity} will be used to switch on/off a channel in auto-read / flush on * write mode. * If the capacity is Long.MAX_Value, write on flush and auto read will apply. Otherwise, data will be flushed every * capacity batch size and read will pause when capacity number of elements have been dispatched. * <p> * Emitted channels will run on the same thread they have beem receiving IO events. * Apart from dispatching the write, it is possible to use {@link reactor.rx.Stream#dispatchOn} to process requests * asynchronously. * <p> * By default the type of emitted data or received data is {@link reactor.io.buffer.Buffer} * * @return a new Stream of ChannelStream, typically a peer of connections. */ public static TcpServer<Buffer, Buffer> tcpServer() { return tcpServer(DEFAULT_BIND_ADDRESS); }
/** * Bind a new UDP server to the "loopback" address. By default the default server implementation is scanned * from the classpath on Class init. Support for Netty is provided as long as the relevant * library dependencies are on the classpath. * <p> * From the emitted {@link ReactorChannel}, one can decide to add in-channel consumers to read any incoming * data. * <p> * To reply data on the active connection, {@link ReactorChannel#writeWith} can subscribe to any passed {@link org.reactivestreams.Publisher}. * <p> * Note that {@link reactor.rx.Stream#getCapacity} will be used to switch on/off a channel in auto-read / flush on * write mode. * If the capacity is Long.MAX_Value, write on flush and auto read will apply. Otherwise, data will be flushed every * capacity batch size and read will pause when capacity number of elements have been dispatched. * <p> * Emitted channels will run on the same thread they have beem receiving IO events. * Apart from dispatching the write, it is possible to use {@link reactor.rx.Stream#dispatchOn} to process requests * asynchronously. * <p> * By default the type of emitted data or received data is {@link reactor.io.buffer.Buffer} * * @return a new Stream of ChannelStream, typically a peer of connections. */ public static DatagramServer<Buffer, Buffer> udpServer() { return udpServer(DEFAULT_BIND_ADDRESS); }
/** * @return a simple HTTP client */ public static HttpClient<Buffer, Buffer> httpClient() { return httpClient(new Function<Spec.HttpClientSpec<Buffer, Buffer>, Spec.HttpClientSpec<Buffer, Buffer>>() { @Override public Spec.HttpClientSpec<Buffer, Buffer> apply(Spec.HttpClientSpec<Buffer, Buffer> clientSpec) { if (Environment.alive()) { clientSpec.env(Environment.get()); } return clientSpec; } }); }
return tcpServer(bindAddress, DEFAULT_PORT);
/** * Bind a new UDP server to the given bind address. By default the default server implementation is scanned * from the classpath on Class init. Support for Netty is provided as long as the relevant * library dependencies are on the classpath. * <p> * From the emitted {@link ReactorChannel}, one can decide to add in-channel consumers to read any incoming * data. * <p> * To reply data on the active connection, {@link ReactorChannel#writeWith} can subscribe to any passed {@link org.reactivestreams.Publisher}. * <p> * Note that {@link reactor.rx.Stream#getCapacity} will be used to switch on/off a channel in auto-read / flush on * write mode. * If the capacity is Long.MAX_Value, write on flush and auto read will apply. Otherwise, data will be flushed every * capacity batch size and read will pause when capacity number of elements have been dispatched. * <p> * Emitted channels will run on the same thread they have beem receiving IO events. * Apart from dispatching the write, it is possible to use {@link reactor.rx.Stream#dispatchOn} to process requests * asynchronously. * <p> * By default the type of emitted data or received data is {@link reactor.io.buffer.Buffer} * * @param bindAddress bind address (e.g. "127.0.0.1") to create the server on the passed port * @return a new Stream of ChannelStream, typically a peer of connections. */ public static DatagramServer<Buffer, Buffer> udpServer(String bindAddress) { return udpServer(bindAddress, DEFAULT_PORT); }
Function<? super Spec.HttpClientSpec<IN, OUT>, ? extends Spec.HttpClientSpec<IN, OUT>> configuringFunction ) { return httpClient(DEFAULT_HTTP_CLIENT_TYPE, configuringFunction);
/** * Bind a new TCP client to the localhost on port 12012. By default the default client implementation is scanned * from the classpath on Class init. Support for Netty first and ZeroMQ then is provided as long as the relevant * library dependencies are on the classpath. * <p> * A {@link reactor.io.net.tcp.TcpClient} is a specific kind of {@link org.reactivestreams.Publisher} that will emit: * - onNext {@link reactor.io.net.ChannelStream} to consume data from * - onComplete when client is shutdown * - onError when any exception (more specifically IO exception) occurs * From the emitted {@link ReactorChannel}, one can decide to add in-channel consumers to read any incoming * data. * <p> * To reply data on the active connection, {@link ReactorChannel#writeWith} can subscribe to any passed {@link org.reactivestreams.Publisher}. * <p> * Note that {@link reactor.rx.Stream#getCapacity} will be used to switch on/off a channel in auto-read / flush on * write mode. * If the capacity is Long.MAX_Value, write on flush and auto read will apply. Otherwise, data will be flushed every * capacity batch size and read will pause when capacity number of elements have been dispatched. * <p> * Emitted channels will run on the same thread they have beem receiving IO events. * Apart from dispatching the write, it is possible to use {@link reactor.rx.Stream#dispatchOn} to process requests * asynchronously. * <p> * By default the type of emitted data or received data is {@link reactor.io.buffer.Buffer} * * @return a new Stream of ChannelStream, typically a peer of connections. */ public static TcpClient<Buffer, Buffer> tcpClient() { return tcpClient(DEFAULT_BIND_ADDRESS); }
/** * Build a simple Netty HTTP server listening on 127.0.0.1 and 12012 * * @param bindAddress address to listen for (e.g. 0.0.0.0 or 127.0.0.1) * @return a simple HTTP server */ public static HttpServer<Buffer, Buffer> httpServer(String bindAddress) { return httpServer(bindAddress, DEFAULT_PORT); }
return tcpServer(DEFAULT_BIND_ADDRESS, port);
/** * Bind a new UDP server to the "loopback" address and specified port. By default the default server implementation * is scanned * from the classpath on Class init. Support for Netty is provided as long as the relevant * library dependencies are on the classpath. * <p> * From the emitted {@link ReactorChannel}, one can decide to add in-channel consumers to read any incoming * data. * <p> * To reply data on the active connection, {@link ReactorChannel#writeWith} can subscribe to any passed {@link org.reactivestreams.Publisher}. * <p> * Note that {@link reactor.rx.Stream#getCapacity} will be used to switch on/off a channel in auto-read / flush on * write mode. * If the capacity is Long.MAX_Value, write on flush and auto read will apply. Otherwise, data will be flushed every * capacity batch size and read will pause when capacity number of elements have been dispatched. * <p> * Emitted channels will run on the same thread they have beem receiving IO events. * Apart from dispatching the write, it is possible to use {@link reactor.rx.Stream#dispatchOn} to process requests * asynchronously. * <p> * By default the type of emitted data or received data is {@link reactor.io.buffer.Buffer} * * @param port the port to listen on the passed bind address * @return a new Stream of ChannelStream, typically a peer of connections. */ public static DatagramServer<Buffer, Buffer> udpServer(int port) { return udpServer(DEFAULT_BIND_ADDRESS, port); }
return tcpClient(bindAddress, DEFAULT_PORT);
/** * Build a simple Netty HTTP server listening on 127.0.0.1 and the passed port * * @param port the port to listen to * @return a simple HTTP server */ public static HttpServer<Buffer, Buffer> httpServer(int port) { return httpServer(DEFAULT_BIND_ADDRESS, port); }
return tcpServer(new Function<Spec.TcpServerSpec<Buffer, Buffer>, Spec.TcpServerSpec<Buffer, Buffer>>() { @Override public Spec.TcpServerSpec<Buffer, Buffer> apply(Spec.TcpServerSpec<Buffer, Buffer> serverSpec) {
configuringFunction ) { return udpServer(DEFAULT_UDP_SERVER_TYPE, configuringFunction);
Function<? super Spec.TcpClientSpec<IN, OUT>, ? extends Spec.TcpClientSpec<IN, OUT>> configuringFunction ) { return tcpClient(DEFAULT_TCP_CLIENT_TYPE, configuringFunction);
/** * Build a Netty HTTP Server with the passed factory * * @param configuringFunction a factory to build server configuration (see also {@link HttpServerFactory} * @param <IN> incoming data type * @param <OUT> outgoing data type * @return a Netty HTTP server with the passed factory */ public static <IN, OUT> HttpServer<IN, OUT> httpServer( Function<? super Spec.HttpServerSpec<IN, OUT>, ? extends Spec.HttpServerSpec<IN, OUT>> configuringFunction ) { return httpServer(DEFAULT_HTTP_SERVER_TYPE, configuringFunction); }
Function<? super Spec.TcpServerSpec<IN, OUT>, ? extends Spec.TcpServerSpec<IN, OUT>> configuringFunction ) { return tcpServer(DEFAULT_TCP_SERVER_TYPE, configuringFunction);