1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.http.nio.command;
29
30 import org.apache.hc.core5.annotation.Internal;
31 import org.apache.hc.core5.http.ConnectionClosedException;
32 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
33 import org.apache.hc.core5.reactor.Command;
34 import org.apache.hc.core5.reactor.IOSession;
35 import org.apache.hc.core5.util.Args;
36
37
38
39
40
41
42 @Internal
43 public final class CommandSupport {
44
45
46
47
48 static public void failCommands(final IOSession ioSession, final Exception ex) {
49 Args.notNull(ioSession, "I/O session");
50 Command command;
51 while ((command = ioSession.poll()) != null) {
52 if (command instanceof RequestExecutionCommand) {
53 final AsyncClientExchangeHandler exchangeHandler = ((RequestExecutionCommand) command).getExchangeHandler();
54 try {
55 exchangeHandler.failed(ex);
56 } finally {
57 exchangeHandler.releaseResources();
58 }
59 } else {
60 command.cancel();
61 }
62 }
63 }
64
65
66
67
68 static public void cancelCommands(final IOSession ioSession) {
69 Args.notNull(ioSession, "I/O session");
70 Command command;
71 while ((command = ioSession.poll()) != null) {
72 if (command instanceof RequestExecutionCommand) {
73 final AsyncClientExchangeHandler exchangeHandler = ((RequestExecutionCommand) command).getExchangeHandler();
74 try {
75 if (!ioSession.isOpen()) {
76 exchangeHandler.failed(new ConnectionClosedException());
77 } else {
78 exchangeHandler.cancel();
79 }
80 } finally {
81 exchangeHandler.releaseResources();
82 }
83 } else {
84 command.cancel();
85 }
86 }
87 }
88
89 }