• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SettableListenableFuture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.util.concurrent.SettableListenableFuture的典型用法代码示例。如果您正苦于以下问题:Java SettableListenableFuture类的具体用法?Java SettableListenableFuture怎么用?Java SettableListenableFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SettableListenableFuture类属于org.springframework.util.concurrent包,在下文中一共展示了SettableListenableFuture类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: mockTemplate

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <K, V> KafkaTemplate<K, V> mockTemplate()
        throws InterruptedException, ExecutionException, TimeoutException {
    KafkaTemplate<K, V> template = mock(KafkaTemplate.class);
    SettableListenableFuture future = mock(SettableListenableFuture.class);
    when(future.get(30000, TimeUnit.MILLISECONDS)).thenReturn(null);
    when(template.send(any(), any(), any())).thenReturn(future);
    return template;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:10,代码来源:MockKafkaTemplateFactory.java


示例2: sendWithExecutionException

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Test
public void sendWithExecutionException() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	IllegalStateException exception = new IllegalStateException("simulated exception");
	SettableListenableFuture<Void> future = new SettableListenableFuture<>();
	future.setException(exception);

	when(this.connection.send(any())).thenReturn(future);
	this.expected.expect(MessageDeliveryException.class);
	this.expected.expectCause(Matchers.sameInstance(exception));

	this.session.send("/topic/foo", "sample payload".getBytes(UTF_8));

	verifyNoMoreInteractions(this.connection);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:DefaultStompSessionTests.java


示例3: connect

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
	final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<WebSocketSession>();
	WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
	handler = new ClientSockJsWebSocketHandler(session);
	request.addTimeoutTask(session.getTimeoutTask());

	URI url = request.getTransportUrl();
	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
	if (logger.isDebugEnabled()) {
		logger.debug("Starting WebSocket session url=" + url);
	}
	this.webSocketClient.doHandshake(handler, headers, url).addCallback(
			new ListenableFutureCallback<WebSocketSession>() {
				@Override
				public void onSuccess(WebSocketSession webSocketSession) {
					// WebSocket session ready, SockJS Session not yet
				}
				@Override
				public void onFailure(Throwable ex) {
					future.setException(ex);
				}
			});
	return future;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:WebSocketTransport.java


示例4: doHandshake

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
public final ListenableFuture<WebSocketSession> doHandshake(
		WebSocketHandler handler, WebSocketHttpHeaders headers, URI url) {

	Assert.notNull(handler, "WebSocketHandler is required");
	Assert.notNull(url, "URL is required");

	String scheme = url.getScheme();
	if (!supportedProtocols.contains(scheme)) {
		throw new IllegalArgumentException("Invalid scheme: '" + scheme + "'");
	}

	SettableListenableFuture<WebSocketSession> connectFuture = new SettableListenableFuture<WebSocketSession>();
	try {
		SockJsUrlInfo sockJsUrlInfo = new SockJsUrlInfo(url);
		ServerInfo serverInfo = getServerInfo(sockJsUrlInfo, getHttpRequestHeaders(headers));
		createRequest(sockJsUrlInfo, headers, serverInfo).connect(handler, connectFuture);
	}
	catch (Throwable exception) {
		if (logger.isErrorEnabled()) {
			logger.error("Initial SockJS \"Info\" request to server failed, url=" + url, exception);
		}
		connectFuture.setException(exception);
	}
	return connectFuture;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:SockJsClient.java


示例5: connect

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
	SettableListenableFuture<WebSocketSession> connectFuture = new SettableListenableFuture<WebSocketSession>();
	XhrClientSockJsSession session = new XhrClientSockJsSession(request, handler, this, connectFuture);
	request.addTimeoutTask(session.getTimeoutTask());

	URI receiveUrl = request.getTransportUrl();
	if (logger.isDebugEnabled()) {
		logger.debug("Starting XHR " +
				(isXhrStreamingDisabled() ? "Polling" : "Streaming") + "session url=" + receiveUrl);
	}

	HttpHeaders handshakeHeaders = new HttpHeaders();
	handshakeHeaders.putAll(getRequestHeaders());
	handshakeHeaders.putAll(request.getHandshakeHeaders());

	connectInternal(request, handler, receiveUrl, handshakeHeaders, session, connectFuture);
	return connectFuture;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:AbstractXhrTransport.java


示例6: send

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:WebSocketStompClient.java


示例7: executeInternal

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
	final SettableListenableFuture<ClientHttpResponse> responseFuture =
			new SettableListenableFuture<ClientHttpResponse>();

	ChannelFutureListener connectionListener = new ChannelFutureListener() {
		@Override
		public void operationComplete(ChannelFuture future) throws Exception {
			if (future.isSuccess()) {
				Channel channel = future.channel();
				channel.pipeline().addLast(new RequestExecuteHandler(responseFuture));
				FullHttpRequest nettyRequest = createFullHttpRequest(headers);
				channel.writeAndFlush(nettyRequest);
			}
			else {
				responseFuture.setException(future.cause());
			}
		}
	};

	this.bootstrap.connect(this.uri.getHost(), getPort(this.uri)).addListener(connectionListener);

	return responseFuture;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:Netty4ClientHttpRequest.java


示例8: validateAndStoreSpans

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
ListenableFuture<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec codec,
    byte[] body) {
  SettableListenableFuture<ResponseEntity<?>> result = new SettableListenableFuture<>();
  metrics.incrementMessages();
  if (encoding != null && encoding.contains("gzip")) {
    try {
      body = gunzip(body);
    } catch (IOException e) {
      metrics.incrementMessagesDropped();
      result.set(ResponseEntity.badRequest().body("Cannot gunzip spans: " + e.getMessage() + "\n"));
    }
  }
  collector.acceptSpans(body, codec, new Callback<Void>() {
    @Override public void onSuccess(@Nullable Void value) {
      result.set(SUCCESS);
    }

    @Override public void onError(Throwable t) {
      String message = t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage();
      result.set(t.getMessage() == null || message.startsWith("Cannot store")
          ? ResponseEntity.status(500).body(message + "\n")
          : ResponseEntity.status(400).body(message + "\n"));
    }
  });
  return result;
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:27,代码来源:ZipkinHttpCollector.java


示例9: executeInternal

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) {
    final SettableListenableFuture<ClientHttpResponse> responseFuture = new SettableListenableFuture<>();

    ChannelFutureListener connectionListener = future -> {
        if (future.isSuccess()) {
            Channel channel = future.channel();
            channel.pipeline().addLast(new NettyResponseHandler(responseFuture));
            FullHttpRequest nettyRequest = createFullHttpRequest(headers);
            channel.writeAndFlush(nettyRequest);
        }
        else {
            responseFuture.setException(future.cause());
        }
    };

    this.bootstrap.connect(this.uri.getHost(), getPort(this.uri)).addListener(connectionListener);

    return responseFuture;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:20,代码来源:NettyRequest.java


示例10: getBuilds

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
public ListenableFuture<List<Build>> getBuilds(String projectId, String baseBuildNumber) {
  SettableListenableFuture<List<Build>> builds = new SettableListenableFuture<>();
  ListenableFuture<List<BuildStep>> projectBuildSteps = getProjectBuildSteps(projectId);
  projectBuildSteps.addCallback(
      buildSteps -> {
        List<ListenableFuture<StepBuilds>> allBuilds = new ArrayList<>();
        buildSteps.forEach(buildStep -> {
          allBuilds.add(fetchBuildsForStep(buildStep));
        });
        ListenableFuture<List<StepBuilds>> buildsOnFuture = asyncUtil.flatMapCommands(allBuilds);
        buildsOnFuture.addCallback(
            buildsList -> {
              Collections.sort(buildsList);
              List<Build> relatedBuilds = new ArrayList<>();
              buildsList.forEach(currentBuilds -> {
                addRelatedBuildStep(currentBuilds.getBuild(), relatedBuilds, baseBuildNumber);
              });
              builds.set(relatedBuilds);
            },
            builds::setException);
      },
      builds::setException);
  return builds;
}
 
开发者ID:STeveShary,项目名称:buildTube,代码行数:25,代码来源:TeamCityService.java


示例11: publish

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
public ListenableFuture<String> publish(final String topic, PubsubMessage pubsubMessage) {
	ApiFuture<String> publishFuture =
			this.publisherFactory.createPublisher(topic).publish(pubsubMessage);

	final SettableListenableFuture<String> settableFuture = new SettableListenableFuture<>();
	ApiFutures.addCallback(publishFuture, new ApiFutureCallback<String>() {

		@Override
		public void onFailure(Throwable throwable) {
			LOGGER.warn("Publishing to " + topic + " topic failed.", throwable);
			settableFuture.setException(throwable);
		}

		@Override
		public void onSuccess(String result) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug(
						"Publishing to " + topic + " was successful. Message ID: " + result);
			}
			settableFuture.set(result);
		}

	});

	return settableFuture;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:28,代码来源:PubSubTemplate.java


示例12: setUp

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Before
public void setUp() {
	this.message = new GenericMessage<>("testPayload",
			ImmutableMap.of("key1", "value1", "key2", "value2"));
	SettableListenableFuture<String> future = new SettableListenableFuture<>();
	future.set("benfica");
	when(this.pubSubTemplate.publish(eq("testTopic"),
			eq(ByteString.copyFrom("testPayload", Charset.defaultCharset())),
			isA(Map.class)))
			.thenReturn(future);
	this.adapter = new PubSubMessageHandler(this.pubSubTemplate, "testTopic");

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:PubSubMessageHandlerTests.java


示例13: setUp

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:DefaultStompSessionTests.java


示例14: AbstractClientSockJsSession

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
protected AbstractClientSockJsSession(TransportRequest request, WebSocketHandler handler,
		SettableListenableFuture<WebSocketSession> connectFuture) {

	Assert.notNull(request, "'request' is required");
	Assert.notNull(handler, "'handler' is required");
	Assert.notNull(connectFuture, "'connectFuture' is required");
	this.request = request;
	this.webSocketHandler = handler;
	this.connectFuture = connectFuture;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AbstractClientSockJsSession.java


示例15: connectInternal

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
protected void connectInternal(final TransportRequest transportRequest, final WebSocketHandler handler,
		final URI receiveUrl, final HttpHeaders handshakeHeaders, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	getTaskExecutor().execute(new Runnable() {
		@Override
		public void run() {
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			XhrRequestCallback requestCallback = new XhrRequestCallback(handshakeHeaders);
			XhrRequestCallback requestCallbackAfterHandshake = new XhrRequestCallback(httpHeaders);
			XhrReceiveExtractor responseExtractor = new XhrReceiveExtractor(session);
			while (true) {
				if (session.isDisconnected()) {
					session.afterTransportClosed(null);
					break;
				}
				try {
					if (logger.isTraceEnabled()) {
						logger.trace("Starting XHR receive request, url=" + receiveUrl);
					}
					getRestTemplate().execute(receiveUrl, HttpMethod.POST, requestCallback, responseExtractor);
					requestCallback = requestCallbackAfterHandshake;
				}
				catch (Throwable ex) {
					if (!connectFuture.isDone()) {
						connectFuture.setException(ex);
					}
					else {
						session.handleTransportError(ex);
						session.afterTransportClosed(new CloseStatus(1006, ex.getMessage()));
					}
					break;
				}
			}
		}
	});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:RestTemplateXhrTransport.java


示例16: connectInternal

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
@Override
protected void connectInternal(TransportRequest request, WebSocketHandler handler, URI receiveUrl,
		HttpHeaders handshakeHeaders, XhrClientSockJsSession session,
		SettableListenableFuture<WebSocketSession> connectFuture) {

	executeReceiveRequest(request, receiveUrl, handshakeHeaders, session, connectFuture);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:UndertowXhrTransport.java


示例17: executeReceiveRequest

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.undertowBufferSupport.httpClientConnect(this.httpClient, clientCallback, url, worker, this.optionMap);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:UndertowXhrTransport.java


示例18: SockJsResponseListener

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
public SockJsResponseListener(TransportRequest request, ClientConnection connection, URI url,
		HttpHeaders headers, XhrClientSockJsSession sockJsSession,
		SettableListenableFuture<WebSocketSession> connectFuture) {

	this.request = request;
	this.connection = connection;
	this.url = url;
	this.headers = headers;
	this.session = sockJsSession;
	this.connectFuture = connectFuture;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:UndertowXhrTransport.java


示例19: XhrClientSockJsSession

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
public XhrClientSockJsSession(TransportRequest request, WebSocketHandler handler,
		XhrTransport transport, SettableListenableFuture<WebSocketSession> connectFuture) {

	super(request, handler, connectFuture);
	Assert.notNull(transport, "'restTemplate' is required");
	this.transport = transport;
	this.headers = request.getHttpRequestHeaders();
	this.sendHeaders = new HttpHeaders();
	if (this.headers != null) {
		this.sendHeaders.putAll(this.headers);
	}
	this.sendHeaders.setContentType(MediaType.APPLICATION_JSON);
	this.sendUrl = request.getSockJsUrlInfo().getTransportUrl(TransportType.XHR_SEND);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:XhrClientSockJsSession.java


示例20: connect

import org.springframework.util.concurrent.SettableListenableFuture; //导入依赖的package包/类
public void connect(WebSocketHandler handler, SettableListenableFuture<WebSocketSession> future) {
	if (logger.isTraceEnabled()) {
		logger.trace("Starting " + this);
	}
	ConnectCallback connectCallback = new ConnectCallback(handler, future);
	scheduleConnectTimeoutTask(connectCallback);
	this.transport.connect(this, handler).addCallback(connectCallback);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:DefaultTransportRequest.java



注:本文中的org.springframework.util.concurrent.SettableListenableFuture类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Objects类代码示例发布时间:2022-05-22
下一篇:
Java SingleConfigurableEditor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap