ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/websocket/FutureToSendHandler.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/websocket/FutureToSendHandler.java
Status
scanned
Type
file
Name
FutureToSendHandler.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3647 (3.6 KB)
MD5
8b801d08b3a70f097435fe96e45d3581
SHA1
094f330395ddb4363b35ef4c049db74d272e4126
SHA256
517a9c26ed7f7c8db9801cc7eeac726ad54bf1fa6fe458207e5fd9d08724366f
SHA512

      
    
SHA1_git
d7c71c381dc8ad990a6fe067e0b4b764a17e78ce
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
FutureToSendHandler.java | 3.6 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.websocket; import java.util.Locale; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; import jakarta.websocket.SendHandler; import jakarta.websocket.SendResult; import org.apache.tomcat.util.res.StringManager; /** * Converts a Future to a SendHandler. */ class FutureToSendHandler implements Future<Void>, SendHandler { private static final StringManager sm = StringManager.getManager(FutureToSendHandler.class); private final CountDownLatch latch = new CountDownLatch(1); private final WsSession wsSession; private final AtomicReference<SendResult> result = new AtomicReference<>(null); FutureToSendHandler(WsSession wsSession) { this.wsSession = wsSession; } // --------------------------------------------------------- SendHandler @Override public void onResult(SendResult result) { this.result.compareAndSet(null, result); latch.countDown(); } // -------------------------------------------------------------- Future @Override public boolean cancel(boolean mayInterruptIfRunning) { // Cancelling the task is not supported return false; } @Override public boolean isCancelled() { // Cancelling the task is not supported return false; } @Override public boolean isDone() { return latch.getCount() == 0; } @Override public Void get() throws InterruptedException, ExecutionException { try { wsSession.registerFuture(this); latch.await(); } finally { wsSession.unregisterFuture(this); } if (result.get().getException() != null) { throw new ExecutionException(result.get().getException()); } return null; } @Override public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { boolean retval; try { wsSession.registerFuture(this); retval = latch.await(timeout, unit); } finally { wsSession.unregisterFuture(this); } if (!retval) { throw new TimeoutException(sm.getString("futureToSendHandler.timeout", Long.valueOf(timeout), unit.toString().toLowerCase(Locale.ENGLISH))); } if (result.get().getException() != null) { throw new ExecutionException(result.get().getException()); } return null; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
33.81
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9