Search in sources :

Example 6 with ListenableFutureTask

use of org.springframework.util.concurrent.ListenableFutureTask in project spring-framework by spring-projects.

the class JettyWebSocketClient method doHandshakeInternal.

@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<>(connectTask);
        task.run();
        return task;
    }
}
Also used : WebSocketExtension(org.springframework.web.socket.WebSocketExtension) JettyWebSocketSession(org.springframework.web.socket.adapter.jetty.JettyWebSocketSession) JettyWebSocketHandlerAdapter(org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter) Callable(java.util.concurrent.Callable) WebSocketSession(org.springframework.web.socket.WebSocketSession) JettyWebSocketSession(org.springframework.web.socket.adapter.jetty.JettyWebSocketSession) ListenableFutureTask(org.springframework.util.concurrent.ListenableFutureTask) WebSocketToJettyExtensionConfigAdapter(org.springframework.web.socket.adapter.jetty.WebSocketToJettyExtensionConfigAdapter) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) Principal(java.security.Principal) WebSocketSession(org.springframework.web.socket.WebSocketSession) Session(org.eclipse.jetty.websocket.api.Session) JettyWebSocketSession(org.springframework.web.socket.adapter.jetty.JettyWebSocketSession)

Example 7 with ListenableFutureTask

use of org.springframework.util.concurrent.ListenableFutureTask in project spring-framework by spring-projects.

the class ThreadPoolTaskExecutor method submitListenable.

@Override
public ListenableFuture<?> submitListenable(Runnable task) {
    ExecutorService executor = getThreadPoolExecutor();
    try {
        ListenableFutureTask<Object> future = new ListenableFutureTask<>(task, null);
        executor.execute(future);
        return future;
    } catch (RejectedExecutionException ex) {
        throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) ListenableFutureTask(org.springframework.util.concurrent.ListenableFutureTask) ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 8 with ListenableFutureTask

use of org.springframework.util.concurrent.ListenableFutureTask in project spring-framework by spring-projects.

the class TaskExecutorAdapter method submitListenable.

@Override
public ListenableFuture<?> submitListenable(Runnable task) {
    try {
        ListenableFutureTask<Object> future = new ListenableFutureTask<>(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);
    }
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) ListenableFutureTask(org.springframework.util.concurrent.ListenableFutureTask) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

ListenableFutureTask (org.springframework.util.concurrent.ListenableFutureTask)8 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 TaskRejectedException (org.springframework.core.task.TaskRejectedException)6 ExecutorService (java.util.concurrent.ExecutorService)4 Callable (java.util.concurrent.Callable)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 WebSocketSession (org.springframework.web.socket.WebSocketSession)2 InetSocketAddress (java.net.InetSocketAddress)1 Principal (java.security.Principal)1 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)1 Endpoint (javax.websocket.Endpoint)1 Session (org.eclipse.jetty.websocket.api.Session)1 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)1 WebSocketExtension (org.springframework.web.socket.WebSocketExtension)1 JettyWebSocketHandlerAdapter (org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter)1 JettyWebSocketSession (org.springframework.web.socket.adapter.jetty.JettyWebSocketSession)1 WebSocketToJettyExtensionConfigAdapter (org.springframework.web.socket.adapter.jetty.WebSocketToJettyExtensionConfigAdapter)1 StandardWebSocketHandlerAdapter (org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter)1 StandardWebSocketSession (org.springframework.web.socket.adapter.standard.StandardWebSocketSession)1