AbstractExecutionAwareRequest.java (httpcomponents-client-4.5.9-src) | : | AbstractExecutionAwareRequest.java (httpcomponents-client-4.5.10-src) | ||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
* | * | |||
* This software consists of voluntary contributions made by many | * This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | * individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | * information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | * <http://www.apache.org/>. | |||
* | * | |||
*/ | */ | |||
package org.apache.http.client.methods; | package org.apache.http.client.methods; | |||
import java.io.IOException; | import java.io.IOException; | |||
import java.util.concurrent.atomic.AtomicBoolean; | import java.util.concurrent.atomic.AtomicMarkableReference; | |||
import java.util.concurrent.atomic.AtomicReference; | ||||
import org.apache.http.HttpRequest; | import org.apache.http.HttpRequest; | |||
import org.apache.http.client.utils.CloneUtils; | import org.apache.http.client.utils.CloneUtils; | |||
import org.apache.http.concurrent.Cancellable; | import org.apache.http.concurrent.Cancellable; | |||
import org.apache.http.conn.ClientConnectionRequest; | import org.apache.http.conn.ClientConnectionRequest; | |||
import org.apache.http.conn.ConnectionReleaseTrigger; | import org.apache.http.conn.ConnectionReleaseTrigger; | |||
import org.apache.http.message.AbstractHttpMessage; | import org.apache.http.message.AbstractHttpMessage; | |||
@SuppressWarnings("deprecation") | @SuppressWarnings("deprecation") | |||
public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage implements | public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage implements | |||
HttpExecutionAware, AbortableHttpRequest, Cloneable, HttpRequest { | HttpExecutionAware, AbortableHttpRequest, Cloneable, HttpRequest { | |||
private final AtomicBoolean aborted; | private final AtomicMarkableReference<Cancellable> cancellableRef; | |||
private final AtomicReference<Cancellable> cancellableRef; | ||||
protected AbstractExecutionAwareRequest() { | protected AbstractExecutionAwareRequest() { | |||
super(); | super(); | |||
this.aborted = new AtomicBoolean(false); | this.cancellableRef = new AtomicMarkableReference<Cancellable>(null, fal | |||
this.cancellableRef = new AtomicReference<Cancellable>(null); | se); | |||
} | } | |||
/** | /** | |||
* @deprecated Use {@link #setCancellable(Cancellable)} | * @deprecated Use {@link #setCancellable(Cancellable)} | |||
*/ | */ | |||
@Override | @Override | |||
@Deprecated | @Deprecated | |||
public void setConnectionRequest(final ClientConnectionRequest connRequest) { | public void setConnectionRequest(final ClientConnectionRequest connRequest) { | |||
setCancellable(new Cancellable() { | setCancellable(new Cancellable() { | |||
skipping to change at line 93 | skipping to change at line 90 | |||
} catch (final IOException ex) { | } catch (final IOException ex) { | |||
return false; | return false; | |||
} | } | |||
} | } | |||
}); | }); | |||
} | } | |||
@Override | @Override | |||
public void abort() { | public void abort() { | |||
if (this.aborted.compareAndSet(false, true)) { | while (!cancellableRef.isMarked()) { | |||
final Cancellable cancellable = this.cancellableRef.getAndSet(null); | final Cancellable actualCancellable = cancellableRef.getReference(); | |||
if (cancellable != null) { | if (cancellableRef.compareAndSet(actualCancellable, actualCancellabl | |||
cancellable.cancel(); | e, false, true)) { | |||
if (actualCancellable != null) { | ||||
actualCancellable.cancel(); | ||||
} | ||||
} | } | |||
} | } | |||
} | } | |||
@Override | @Override | |||
public boolean isAborted() { | public boolean isAborted() { | |||
return this.aborted.get(); | return this.cancellableRef.isMarked(); | |||
} | } | |||
/** | /** | |||
* @since 4.2 | * @since 4.2 | |||
*/ | */ | |||
@Override | @Override | |||
public void setCancellable(final Cancellable cancellable) { | public void setCancellable(final Cancellable cancellable) { | |||
if (!this.aborted.get()) { | final Cancellable actualCancellable = cancellableRef.getReference(); | |||
this.cancellableRef.set(cancellable); | if (!cancellableRef.compareAndSet(actualCancellable, cancellable, false, | |||
false)) { | ||||
cancellable.cancel(); | ||||
} | } | |||
} | } | |||
@Override | @Override | |||
public Object clone() throws CloneNotSupportedException { | public Object clone() throws CloneNotSupportedException { | |||
final AbstractExecutionAwareRequest clone = (AbstractExecutionAwareReque st) super.clone(); | final AbstractExecutionAwareRequest clone = (AbstractExecutionAwareReque st) super.clone(); | |||
clone.headergroup = CloneUtils.cloneObject(this.headergroup); | clone.headergroup = CloneUtils.cloneObject(this.headergroup); | |||
clone.params = CloneUtils.cloneObject(this.params); | clone.params = CloneUtils.cloneObject(this.params); | |||
return clone; | return clone; | |||
} | } | |||
/** | /** | |||
* @since 4.2 | * @since 4.2 | |||
* | ||||
* @deprecated Do not use. | ||||
*/ | */ | |||
@Deprecated | ||||
public void completed() { | public void completed() { | |||
this.cancellableRef.set(null); | this.cancellableRef.set(null, false); | |||
} | } | |||
/** | /** | |||
* Resets internal state of the request making it reusable. | * Resets internal state of the request making it reusable. | |||
* | * | |||
* @since 4.2 | * @since 4.2 | |||
*/ | */ | |||
public void reset() { | public void reset() { | |||
final Cancellable cancellable = this.cancellableRef.getAndSet(null); | for (;;) { | |||
if (cancellable != null) { | final boolean marked = cancellableRef.isMarked(); | |||
cancellable.cancel(); | final Cancellable actualCancellable = cancellableRef.getReference(); | |||
if (actualCancellable != null) { | ||||
actualCancellable.cancel(); | ||||
} | ||||
if (cancellableRef.compareAndSet(actualCancellable, null, marked, fa | ||||
lse)) { | ||||
break; | ||||
} | ||||
} | } | |||
this.aborted.set(false); | ||||
} | } | |||
} | } | |||
End of changes. 11 change blocks. | ||||
18 lines changed or deleted | 30 lines changed or added |