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.impl.client.cache;
28
29 import java.util.concurrent.ExecutionException;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.apache.http.HttpHost;
34 import org.apache.http.HttpResponse;
35 import org.apache.http.ProtocolException;
36 import org.apache.http.client.cache.HttpCacheContext;
37 import org.apache.http.client.cache.HttpCacheEntry;
38 import org.apache.http.client.methods.HttpRequestWrapper;
39 import org.apache.http.concurrent.BasicFuture;
40 import org.apache.http.concurrent.FutureCallback;
41
42
43
44
45
46 class AsynchronousAsyncValidationRequest implements Runnable {
47 private final AsynchronousAsyncValidator parent;
48 private final CachingHttpAsyncClient cachingAsyncClient;
49 private final HttpHost target;
50 private final HttpRequestWrapper request;
51 private final HttpCacheContext clientContext;
52 private final HttpCacheEntry cacheEntry;
53 private final String identifier;
54
55 private final Log log = LogFactory.getLog(getClass());
56
57
58
59
60
61 AsynchronousAsyncValidationRequest(final AsynchronousAsyncValidator parent,
62 final CachingHttpAsyncClient cachingClient, final HttpHost target, final HttpRequestWrapper request,
63 final HttpCacheContext clientContext, final HttpCacheEntry cacheEntry, final String identifier) {
64 this.parent = parent;
65 this.cachingAsyncClient = cachingClient;
66 this.target = target;
67 this.request = request;
68 this.clientContext = clientContext;
69 this.cacheEntry = cacheEntry;
70 this.identifier = identifier;
71 }
72
73 @Override
74 public void run() {
75 try {
76 final FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {
77
78 @Override
79 public void cancelled() {
80 }
81
82 @Override
83 public void completed(final HttpResponse httpResponse) {
84 }
85
86 @Override
87 public void failed(final Exception e) {
88 log.debug("Asynchronous revalidation failed", e);
89 }
90 };
91 final BasicFuture<HttpResponse> future = new BasicFuture<HttpResponse>(callback);
92 this.cachingAsyncClient.revalidateCacheEntry(future, this.target, this.request,
93 this.clientContext, this.cacheEntry);
94 future.get();
95 } catch (final ProtocolException pe) {
96 this.log.error("ProtocolException thrown during asynchronous revalidation", pe);
97 } catch (final ExecutionException e) {
98 this.log.error("Exception thrown during asynchronous revalidation", e.getCause());
99 } catch (final InterruptedException e) {
100 Thread.currentThread().interrupt();
101 } finally {
102 this.parent.markComplete(this.identifier);
103 }
104 }
105
106 String getIdentifier() {
107 return this.identifier;
108 }
109
110 }