reactor.rx.Promises Java Examples

The following examples show how to use reactor.rx.Promises. 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: Reactor2TcpClient.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy) {
	Assert.notNull(connectionHandler, "TcpConnectionHandler must not be null");
	Assert.notNull(strategy, "ReconnectStrategy must not be null");

	TcpClient<Message<P>, Message<P>> tcpClient;
	synchronized (this.tcpClients) {
		if (this.stopping) {
			IllegalStateException ex = new IllegalStateException("Shutting down.");
			connectionHandler.afterConnectFailure(ex);
			return new PassThroughPromiseToListenableFutureAdapter<Void>(Promises.<Void>error(ex));
		}
		tcpClient = NetStreams.tcpClient(REACTOR_TCP_CLIENT_TYPE, this.tcpClientSpecFactory);
		this.tcpClients.add(tcpClient);
	}

	Stream<Tuple2<InetSocketAddress, Integer>> stream = tcpClient.start(
			new MessageChannelStreamHandler<P>(connectionHandler),
			new ReactorReconnectAdapter(strategy));

	return new PassThroughPromiseToListenableFutureAdapter<Void>(stream.next().after());
}
 
Example #2
Source File: Reactor2TcpClient.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Publisher<Void> apply(ChannelStream<Message<P>, Message<P>> channelStream) {
	Promise<Void> closePromise = Promises.prepare();
	this.connectionHandler.afterConnected(new Reactor2TcpConnection<P>(channelStream, closePromise));
	channelStream
			.finallyDo(new Consumer<Signal<Message<P>>>() {
				@Override
				public void accept(Signal<Message<P>> signal) {
					if (signal.isOnError()) {
						connectionHandler.handleFailure(signal.getThrowable());
					}
					else if (signal.isOnComplete()) {
						connectionHandler.afterConnectionClosed();
					}
				}
			})
			.consume(new Consumer<Message<P>>() {
				@Override
				public void accept(Message<P> message) {
					connectionHandler.handleMessage(message);
				}
			});

	return closePromise;
}
 
Example #3
Source File: ReactorTcpServerTests.java    From reactive-ipc-jvm with Apache License 2.0 5 votes vote down vote up
@Test
public void writeMultipleValues() throws IOException {
    Promise<ByteBuf> chunk1 = Promises.success(Unpooled.buffer().writeBytes("This is".getBytes()));
    Promise<ByteBuf> chunk2 = Promises.success(Unpooled.buffer().writeBytes(" a test!".getBytes()));
    reactorServer.start(connection -> connection.writeWith(Streams.concat(chunk1, chunk2)));
    assertEquals("This is a test!", SocketTestUtils.read("localhost", reactorServer.getPort()));
}
 
Example #4
Source File: Reactor2TcpConnection.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public ListenableFuture<Void> send(Message<P> message) {
	Promise<Void> afterWrite = Promises.prepare();
	this.channelStream.writeWith(Streams.just(message)).subscribe(afterWrite);
	return new PassThroughPromiseToListenableFutureAdapter<Void>(afterWrite);
}
 
Example #5
Source File: FreeIpaClientRequest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public FreeIpaClientRequest(Long stackId) {
    this.stackId = requireNonNull(stackId);
    result = Promises.prepare();
}
 
Example #6
Source File: CloudPlatformRequest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public CloudPlatformRequest(CloudContext cloudContext, CloudCredential cloudCredential) {
    this.cloudContext = cloudContext;
    this.cloudCredential = cloudCredential;
    result = Promises.prepare();
}
 
Example #7
Source File: ResourceNotification.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public ResourceNotification(CloudResource cloudResource, CloudContext cloudContext, ResourceNotificationType type) {
    this.cloudResource = cloudResource;
    this.cloudContext = cloudContext;
    promise = Promises.prepare();
    this.type = type;
}