当前位置: 首页>>代码示例>>Java>>正文


Java ListenableFutureTask类代码示例

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


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

示例1: submitListenable

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<?> submitListenable (Runnable task)
{
   ExecutorService executor = getThreadPoolExecutor ();
   try
   {
      ListenableFutureTask<Object> future =
         new ListenableFutureTask<Object> (task, null);
      executor.execute (future);
      return future;
   }
   catch (RejectedExecutionException ex)
   {
      throw new TaskRejectedException ("Executor [" + executor +
         "] did not accept task: " + task, ex);
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:18,代码来源:FairThreadPoolTaskExecutor.java

示例2: submitListenable

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	ExecutorService executor = getThreadPoolExecutor();
	try {
		ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
		executor.execute(future);
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:ThreadPoolTaskExecutor.java

示例3: submitListenable

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	ExecutorService executor = getScheduledExecutor();
	try {
		ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
		executor.execute(errorHandlingTask(future, false));
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:ThreadPoolTaskScheduler.java

示例4: main

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public static void main(String[] args) {
    ListenableFutureTask listenableFutureTask = new ListenableFutureTask(() -> {
        log.info("listenable future begin to execute");
        TimeUnit.SECONDS.sleep(5);
        return "listenable future task done";
    });

    listenableFutureTask.addCallback(new ListenableFutureCallback() {
        @Override
        public void onFailure(Throwable ex) {
            log.info("listenable future task execute failed, cause: {}", ex.getMessage());
        }

        @Override
        public void onSuccess(Object result) {
            log.info("listenable future task execute successfully, result: {}", result);
        }
    });

    ExecutorService executor = Executors.newSingleThreadExecutor();
    try {
        executor.execute(listenableFutureTask);
        //log.info(listenableFutureTask.get());
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:xitongjiagoushi,项目名称:java-basic-skills,代码行数:28,代码来源:ListenableFutureDemo.java

示例5: handleListenableFutureException

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@MessageMapping("failure")
public ListenableFutureTask<String> handleListenableFutureException() {
	this.future = new ListenableFutureTask<String>(() -> {
		throw new IllegalStateException();
	});
	return this.future;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:SimpAnnotationMethodMessageHandlerTests.java

示例6: getVoidFuture

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
private static ListenableFutureTask<Void> getVoidFuture() {
	ListenableFutureTask<Void> futureTask = new ListenableFutureTask<>(new Callable<Void>() {
		@Override
		public Void call() throws Exception {
			return null;
		}
	});
	futureTask.run();
	return futureTask;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:StompBrokerRelayMessageHandlerTests.java

示例7: getBooleanFuture

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
private static ListenableFutureTask<Boolean> getBooleanFuture() {
	ListenableFutureTask<Boolean> futureTask = new ListenableFutureTask<>(new Callable<Boolean>() {
		@Override
		public Boolean call() throws Exception {
			return null;
		}
	});
	futureTask.run();
	return futureTask;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:StompBrokerRelayMessageHandlerTests.java

示例8: submitListenable

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	try {
		ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
		this.concurrentExecutor.execute(future);
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:TaskExecutorAdapter.java

示例9: doHandshakeInternal

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions, Map<String, Object> attributes) {

	int port = getPort(uri);
	InetSocketAddress localAddress = new InetSocketAddress(getLocalHost(), port);
	InetSocketAddress remoteAddress = new InetSocketAddress(uri.getHost(), port);

	final StandardWebSocketSession session = new StandardWebSocketSession(headers,
			attributes, localAddress, remoteAddress);

	final ClientEndpointConfig endpointConfig = ClientEndpointConfig.Builder.create()
			.configurator(new StandardWebSocketClientConfigurator(headers))
			.preferredSubprotocols(protocols)
			.extensions(adaptExtensions(extensions)).build();

	endpointConfig.getUserProperties().putAll(getUserProperties());

	final Endpoint endpoint = new StandardWebSocketHandlerAdapter(webSocketHandler, session);

	Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
		@Override
		public WebSocketSession call() throws Exception {
			webSocketContainer.connectToServer(endpoint, endpointConfig, uri);
			return session;
		}
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<WebSocketSession>(connectTask);
		task.run();
		return task;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:StandardWebSocketClient.java

示例10: doHandshakeInternal

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions,  Map<String, Object> attributes) {

	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	request.setSubProtocols(protocols);

	for (WebSocketExtension e : extensions) {
		request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
	}

	for (String header : headers.keySet()) {
		request.setHeader(header, headers.get(header));
	}

	Principal user = getUser();
	final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
	final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);

	Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
		@Override
		public WebSocketSession call() throws Exception {
			Future<Session> future = client.connect(listener, uri, request);
			future.get();
			return wsSession;
		}
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<WebSocketSession>(connectTask);
		task.run();
		return task;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:JettyWebSocketClient.java

示例11: doHandshake

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler handler, WebSocketHttpHeaders headers, URI uri) {
	this.webSocketHandler = handler;
	this.headers = headers;
	this.uri = uri;
	return new ListenableFutureTask<>(() -> null);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:WebSocketConnectionManagerTests.java

示例12: onMessage

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public void onMessage(String name) {
	for (DeferredResult<Person> deferredResult : this.deferredResults) {
		deferredResult.setResult(new Person(name));
		this.deferredResults.remove(deferredResult);
	}
	for (ListenableFutureTask<Person> futureTask : this.futureTasks) {
		futureTask.run();
		this.futureTasks.remove(futureTask);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AsyncTests.java

示例13: shouldCreateExecutableFromEndpointMethodWithListenableFutureTaskReturnType

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Test
public void shouldCreateExecutableFromEndpointMethodWithListenableFutureTaskReturnType() throws Exception {
	EndpointCallExecutable<ListenableFutureTask<String>, String> executable = factory
			.create(new SimpleEndpointMethod(SomeType.class.getMethod("future")), delegate);

	String result = "future result";

	ListenableFutureTask<String> future = executable.execute(() -> result, null);

	assertEquals(result, future.get());
	assertEquals(delegate.returnType(), executable.returnType());

	verify(delegate).execute(any(), anyVararg());
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:15,代码来源:ListenableFutureTaskEndpointCallExecutableFactoryTest.java

示例14: submitListenable

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<?> submitListenable(Runnable task) {
	try {
		ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
		doExecute(this.concurrentExecutor, this.taskDecorator, future);
		return future;
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException(
				"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:13,代码来源:TaskExecutorAdapter.java

示例15: shouldCancel

import org.springframework.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Test
public void shouldCancel() {
    final ListenableFuture<Void> original = new ListenableFutureTask<>(() -> {}, null);
    final CompletableFuture<Void> unit = preserveCancelability(original);
    original.addCallback(unit::complete, unit::completeExceptionally);

    unit.cancel(true);

    assertThat(original.isCancelled(), is(true));
}
 
开发者ID:zalando,项目名称:riptide,代码行数:11,代码来源:CancelableCompletableFutureTest.java


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