MCPcopy Index your code
hub / github.com/apache/tomcat / FutureToSendHandler

Class FutureToSendHandler

java/org/apache/tomcat/websocket/FutureToSendHandler.java:36–110  ·  view source on GitHub ↗

Converts a Future to a SendHandler.

Source from the content-addressed store, hash-verified

34 * Converts a Future to a SendHandler.
35 */
36class FutureToSendHandler implements Future<Void>, SendHandler {
37
38 private static final StringManager sm = StringManager.getManager(FutureToSendHandler.class);
39
40 private final CountDownLatch latch = new CountDownLatch(1);
41 private final WsSession wsSession;
42 private final AtomicReference<SendResult> result = new AtomicReference<>(null);
43
44 FutureToSendHandler(WsSession wsSession) {
45 this.wsSession = wsSession;
46 }
47
48
49 // --------------------------------------------------------- SendHandler
50
51 @Override
52 public void onResult(SendResult result) {
53 this.result.compareAndSet(null, result);
54 latch.countDown();
55 }
56
57
58 // -------------------------------------------------------------- Future
59
60 @Override
61 public boolean cancel(boolean mayInterruptIfRunning) {
62 // Cancelling the task is not supported
63 return false;
64 }
65
66 @Override
67 public boolean isCancelled() {
68 // Cancelling the task is not supported
69 return false;
70 }
71
72 @Override
73 public boolean isDone() {
74 return latch.getCount() == 0;
75 }
76
77 @Override
78 public Void get() throws InterruptedException, ExecutionException {
79 try {
80 wsSession.registerFuture(this);
81 latch.await();
82 } finally {
83 wsSession.unregisterFuture(this);
84 }
85 if (result.get().getException() != null) {
86 throw new ExecutionException(result.get().getException());
87 }
88 return null;
89 }
90
91 @Override
92 public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
93 boolean retval;

Callers

nothing calls this directly

Calls 1

getManagerMethod · 0.95

Tested by

no test coverage detected