Java Code Examples for org.springframework.util.concurrent.SettableListenableFuture#set()

The following examples show how to use org.springframework.util.concurrent.SettableListenableFuture#set() . These examples are extracted from open source projects. 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
@Override
public ListenableFuture<Void> send(Message<byte[]> message) {
	updateLastWriteTime();
	SettableListenableFuture<Void> future = new SettableListenableFuture<>();
	try {
		WebSocketSession session = this.session;
		Assert.state(session != null, "No WebSocketSession available");
		session.sendMessage(this.codec.encode(message, session.getClass()));
		future.set(null);
	}
	catch (Throwable ex) {
		future.setException(ex);
	}
	finally {
		updateLastWriteTime();
	}
	return future;
}
 
Example 2
@Override
public ListenableFuture<Void> send(Message<byte[]> message) {
	updateLastWriteTime();
	SettableListenableFuture<Void> future = new SettableListenableFuture<>();
	try {
		WebSocketSession session = this.session;
		Assert.state(session != null, "No WebSocketSession available");
		session.sendMessage(this.codec.encode(message, session.getClass()));
		future.set(null);
	}
	catch (Throwable ex) {
		future.setException(ex);
	}
	finally {
		updateLastWriteTime();
	}
	return future;
}
 
Example 3
@Override
public ListenableFuture<Void> send(Message<byte[]> message) {
	updateLastWriteTime();
	SettableListenableFuture<Void> future = new SettableListenableFuture<Void>();
	try {
		this.session.sendMessage(this.codec.encode(message, this.session.getClass()));
		future.set(null);
	}
	catch (Throwable ex) {
		future.setException(ex);
	}
	finally {
		updateLastWriteTime();
	}
	return future;
}
 
Example 4
@Override
public ListenableFuture<Void> shutdown() {
	if (this.stopping) {
		SettableListenableFuture<Void> future = new SettableListenableFuture<>();
		future.set(null);
		return future;
	}

	this.stopping = true;

	Mono<Void> result;
	if (this.channelGroup != null) {
		result = FutureMono.from(this.channelGroup.close());
		if (this.loopResources != null) {
			result = result.onErrorResume(ex -> Mono.empty()).then(this.loopResources.disposeLater());
		}
		if (this.poolResources != null) {
			result = result.onErrorResume(ex -> Mono.empty()).then(this.poolResources.disposeLater());
		}
		result = result.onErrorResume(ex -> Mono.empty()).then(stopScheduler());
	}
	else {
		result = stopScheduler();
	}

	return new MonoToListenableFutureAdapter<>(result);
}
 
Example 5
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);

	this.sessionHandler = mock(StompSessionHandler.class);
	this.connectHeaders = new StompHeaders();
	this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders);
	this.session.setMessageConverter(new StringMessageConverter());

	SettableListenableFuture<Void> future = new SettableListenableFuture<>();
	future.set(null);
	given(this.connection.send(this.messageCaptor.capture())).willReturn(future);
}
 
Example 6
@Override
public ListenableFuture<Void> shutdown() {
	if (this.stopping) {
		SettableListenableFuture<Void> future = new SettableListenableFuture<>();
		future.set(null);
		return future;
	}

	this.stopping = true;

	Mono<Void> result;
	if (this.channelGroup != null) {
		result = FutureMono.from(this.channelGroup.close());
		if (this.loopResources != null) {
			result = result.onErrorResume(ex -> Mono.empty()).then(this.loopResources.disposeLater());
		}
		if (this.poolResources != null) {
			result = result.onErrorResume(ex -> Mono.empty()).then(this.poolResources.disposeLater());
		}
		result = result.onErrorResume(ex -> Mono.empty()).then(stopScheduler());
	}
	else {
		result = stopScheduler();
	}

	return new MonoToListenableFutureAdapter<>(result);
}
 
Example 7
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);

	this.sessionHandler = mock(StompSessionHandler.class);
	this.connectHeaders = new StompHeaders();
	this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders);
	this.session.setMessageConverter(new StringMessageConverter());

	SettableListenableFuture<Void> future = new SettableListenableFuture<>();
	future.set(null);
	when(this.connection.send(this.messageCaptor.capture())).thenReturn(future);
}
 
Example 8
@Override
public ListenableFuture<Void> ack() {
	SettableListenableFuture<Void> settableListenableFuture = new SettableListenableFuture<>();

	try {
		this.ackReplyConsumer.ack();
		settableListenableFuture.set(null);
	}
	catch (Throwable throwable) {
		settableListenableFuture.setException(throwable);
	}

	return settableListenableFuture;
}
 
Example 9
@Override
public ListenableFuture<Void> nack() {
	SettableListenableFuture<Void> settableListenableFuture = new SettableListenableFuture<>();

	try {
		this.ackReplyConsumer.nack();
		settableListenableFuture.set(null);
	}
	catch (Throwable throwable) {
		settableListenableFuture.setException(throwable);
	}

	return settableListenableFuture;
}
 
Example 10
@Before
public void setUp() {
	this.message = new GenericMessage<byte[]>("testPayload".getBytes(),
			new MapBuilder<String, Object>()
					.put("key1", "value1")
					.put("key2", "value2")
					.build());
	SettableListenableFuture<String> future = new SettableListenableFuture<>();
	future.set("benfica");
	when(this.pubSubTemplate.publish(eq("testTopic"),
			eq("testPayload".getBytes()), isA(Map.class)))
			.thenReturn(future);
	this.adapter = new PubSubMessageHandler(this.pubSubTemplate, "testTopic");

}
 
Example 11
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	this.sessionHandler = mock(StompSessionHandler.class);
	this.connectHeaders = new StompHeaders();
	this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders);
	this.session.setMessageConverter(new StringMessageConverter());

	SettableListenableFuture<Void> future = new SettableListenableFuture<>();
	future.set(null);
	when(this.connection.send(this.messageCaptor.capture())).thenReturn(future);
}
 
Example 12
@Override
public ListenableFuture<ClientHttpResponse> executeAsync() throws IOException {
	SettableListenableFuture<ClientHttpResponse> future = new SettableListenableFuture<>();
	future.set(execute());
	return future;
}
 
Example 13
@Override
public ListenableFuture<ClientHttpResponse> executeAsync() throws IOException {
	SettableListenableFuture<ClientHttpResponse> future = new SettableListenableFuture<>();
	future.set(execute());
	return future;
}
 
Example 14
@Override
public ListenableFuture<ClientHttpResponse> executeAsync() throws IOException {
	SettableListenableFuture<ClientHttpResponse> future = new SettableListenableFuture<ClientHttpResponse>();
	future.set(execute());
	return future;
}
 
Example 15
@Override
public ListenableFuture<String> createFinishedFuture() {
    SettableListenableFuture<String> future = new SettableListenableFuture<>();
    future.set(AbstractConverterTest.VALUE);
    return future;
}