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 package org.apache.http.client.methods;
28
29 import java.io.IOException;
30 import java.util.concurrent.atomic.AtomicMarkableReference;
31
32 import org.apache.http.HttpRequest;
33 import org.apache.http.client.utils.CloneUtils;
34 import org.apache.http.concurrent.Cancellable;
35 import org.apache.http.conn.ClientConnectionRequest;
36 import org.apache.http.conn.ConnectionReleaseTrigger;
37 import org.apache.http.message.AbstractHttpMessage;
38
39 @SuppressWarnings("deprecation")
40 public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage implements
41 HttpExecutionAware, AbortableHttpRequest, Cloneable, HttpRequest {
42
43 private final AtomicMarkableReference<Cancellable> cancellableRef;
44
45 protected AbstractExecutionAwareRequest() {
46 super();
47 this.cancellableRef = new AtomicMarkableReference<Cancellable>(null, false);
48 }
49
50
51
52
53 @Override
54 @Deprecated
55 public void setConnectionRequest(final ClientConnectionRequest connRequest) {
56 setCancellable(new Cancellable() {
57
58 @Override
59 public boolean cancel() {
60 connRequest.abortRequest();
61 return true;
62 }
63
64 });
65 }
66
67
68
69
70 @Override
71 @Deprecated
72 public void setReleaseTrigger(final ConnectionReleaseTrigger releaseTrigger) {
73 setCancellable(new Cancellable() {
74
75 @Override
76 public boolean cancel() {
77 try {
78 releaseTrigger.abortConnection();
79 return true;
80 } catch (final IOException ex) {
81 return false;
82 }
83 }
84
85 });
86 }
87
88 @Override
89 public void abort() {
90 while (!cancellableRef.isMarked()) {
91 final Cancellable actualCancellable = cancellableRef.getReference();
92 if (cancellableRef.compareAndSet(actualCancellable, actualCancellable, false, true)) {
93 if (actualCancellable != null) {
94 actualCancellable.cancel();
95 }
96 }
97 }
98 }
99
100 @Override
101 public boolean isAborted() {
102 return this.cancellableRef.isMarked();
103 }
104
105
106
107
108 @Override
109 public void setCancellable(final Cancellable cancellable) {
110 final Cancellable actualCancellable = cancellableRef.getReference();
111 if (!cancellableRef.compareAndSet(actualCancellable, cancellable, false, false)) {
112 cancellable.cancel();
113 }
114 }
115
116 @Override
117 public Object clone() throws CloneNotSupportedException {
118 final AbstractExecutionAwareRequestche/http/client/methods/AbstractExecutionAwareRequest.html#AbstractExecutionAwareRequest">AbstractExecutionAwareRequest clone = (AbstractExecutionAwareRequest) super.clone();
119 clone.headergroup = CloneUtils.cloneObject(this.headergroup);
120 clone.params = CloneUtils.cloneObject(this.params);
121 return clone;
122 }
123
124
125
126
127
128
129 @Deprecated
130 public void completed() {
131 this.cancellableRef.set(null, false);
132 }
133
134
135
136
137
138
139 public void reset() {
140 for (;;) {
141 final boolean marked = cancellableRef.isMarked();
142 final Cancellable actualCancellable = cancellableRef.getReference();
143 if (actualCancellable != null) {
144 actualCancellable.cancel();
145 }
146 if (cancellableRef.compareAndSet(actualCancellable, null, marked, false)) {
147 break;
148 }
149 }
150 }
151
152 }