本文整理汇总了Java中org.apache.http.concurrent.FutureCallback类的典型用法代码示例。如果您正苦于以下问题:Java FutureCallback类的具体用法?Java FutureCallback怎么用?Java FutureCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FutureCallback类属于org.apache.http.concurrent包,在下文中一共展示了FutureCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
Future<HttpResponse> delete(final String key) {
final URI uri = URI.create(baseUri + key);
return httpClient.execute(new HttpDelete(uri), new FutureCallback<HttpResponse>() {
@Override
public void cancelled() {
log.warn("Attempt to delete {} to was cancelled", key);
}
@Override
public void completed(HttpResponse arg0) {
log.info("Succeeded deleting {}", key);
}
@Override
public void failed(Exception e) {
log.warn("Failed deleting {}", key, e);
}
});
}
示例2: lease
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p/>
* Please note that this class does not maintain its own pool of execution
* {@link Thread}s. Therefore, one <b>must</b> call {@link Future#get()}
* or {@link Future#get(long, TimeUnit)} method on the {@link Future}
* returned by this method in order for the lease operation to complete.
*/
public Future<E> lease(final T route, final Object state, final FutureCallback<E> callback) {
Args.notNull(route, "Route");
Asserts.check(!this.isShutDown, "Connection pool shut down");
return new PoolEntryFuture<E>(this.lock, callback) {
@Override
public E getPoolEntry(
final long timeout,
final TimeUnit tunit)
throws InterruptedException, TimeoutException, IOException {
final E entry = getPoolEntryBlocking(route, state, timeout, tunit, this);
onLease(entry);
return entry;
}
};
}
示例3: execute
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
/**
* Schedule a request for execution.
*
* @param <T>
*
* @param request
* request to execute
* @param context
* optional context; use null if not needed.
* @param responseHandler
* handler that will process the response.
* @param callback
* callback handler that will be called when the request is scheduled,
* started, completed, failed, or cancelled.
* @return HttpAsyncClientFutureTask for the scheduled request.
* @throws InterruptedException
*/
public <T> HttpRequestFutureTask<T> execute(
final HttpUriRequest request,
final HttpContext context,
final ResponseHandler<T> responseHandler,
final FutureCallback<T> callback) {
if(closed.get()) {
throw new IllegalStateException("Close has been called on this httpclient instance.");
}
metrics.getScheduledConnections().incrementAndGet();
final HttpRequestTaskCallable<T> callable = new HttpRequestTaskCallable<T>(
httpclient, request, context, responseHandler, callback, metrics);
final HttpRequestFutureTask<T> httpRequestFutureTask = new HttpRequestFutureTask<T>(
request, callable);
executorService.execute(httpRequestFutureTask);
return httpRequestFutureTask;
}
示例4: ServiceCallManager_callServiceWith_UnitTests
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ServiceCallManager_callServiceWith_UnitTests(String serviceCall, String data, String contentType, String serviceEndpoint, Map<String,String> tokenLookup, HttpResponse httpResponse, HttpResponse expectedResponse, boolean isDataTest) throws InterruptedException, ExecutionException
{
this.serviceCall = serviceCall;
this.expectedResponse = expectedResponse;
this.data = data;
this.contentType = contentType;
this.isDataTest = isDataTest;
this.context = mock(ServiceCallContext.class);
when(this.context.getTokenLookup()).thenReturn(tokenLookup);
IServiceContracts contract = mock(IServiceContracts.class);
when(contract.getEndpointFromAlias(serviceCall, context)).thenReturn(serviceEndpoint);
Future<HttpResponse> response = mock(Future.class);
when(response.get()).thenReturn(httpResponse);
this.client = mock(DefaultHttpAsyncClient.class);
when(this.client.execute(any(HttpUriRequest.class), any(FutureCallback.class))).thenReturn(response);
this.service.setHttpClient(client)
.setServiceContracts(contract);
}
示例5: before
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
config = new ESPluginConfig(new Config(false));
client = mock(CloseableHttpAsyncClient.class);
es = mock(ElasticSearch.class);
meta = new UIDMeta(UniqueIdType.METRIC, new byte[] { 1 }, "sys.cpu.user");
index = config.getString("tsd.search.elasticsearch.index");
doc_type = config.getString("tsd.search.elasticsearch.uidmeta_type");
when(es.httpClient()).thenReturn(client);
when(es.host()).thenReturn(HOST);
when(es.index()).thenReturn(index);
when(es.config()).thenReturn(config);
when(client.execute(any(HttpUriRequest.class),
any(FutureCallback.class)))
.thenAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
request = (HttpUriRequest) invocation.getArguments()[0];
cb = (FutureCallback<HttpResponse>) invocation.getArguments()[1];
return null;
}
});
}
示例6: GET
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
public static Future<HttpResponse> GET(String url, FutureCallback<HttpResponse> callback,
Map<String, String> headers) {
HttpGet get = new HttpGet(url);
headers.forEach((key, value) -> {
get.setHeader(key, value);
});
return HTTP_CLIENT.execute(get, callback);
}
示例7: POST
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
public static Future<HttpResponse> POST(String url, FutureCallback<HttpResponse> callback,
List<NameValuePair> params, String encoding, Map<String, String> headers) {
HttpPost post = new HttpPost(url);
headers.forEach((key, value) -> {
post.setHeader(key, value);
});
HttpEntity entity = new UrlEncodedFormEntity(params, HttpClientUtil.getEncode(encoding));
post.setEntity(entity);
return HTTP_CLIENT.execute(post, callback);
}
示例8: lease
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p/>
* Please note that this class does not maintain its own pool of execution
* {@link Thread}s. Therefore, one <b>must</b> call {@link Future#get()}
* or {@link Future#get(long, TimeUnit)} method on the {@link Future}
* returned by this method in order for the lease operation to complete.
*/
public Future<E> lease(final T route, final Object state, final FutureCallback<E> callback) {
if (route == null) {
throw new IllegalArgumentException("Route may not be null");
}
if (this.isShutDown) {
throw new IllegalStateException("Connection pool shut down");
}
return new PoolEntryFuture<E>(this.lock, callback) {
@Override
public E getPoolEntry(
long timeout,
TimeUnit tunit)
throws InterruptedException, TimeoutException, IOException {
return getPoolEntryBlocking(route, state, timeout, tunit, this);
}
};
}
示例9: executeCallback
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
private void executeCallback(HttpEntityEnclosingRequestBase request, String json, FutureCallback<HttpResponse> httpCallback) {
if (json != null && json.length() > 0) {
request.addHeader("Content-Type", "application/json");
if (!this.httpCompress) {
request.setEntity(generateStringEntity(json));
} else {
request.addHeader("Accept-Encoding", "gzip, deflate");
request.setEntity(generateGZIPCompressEntity(json));
}
}
FutureCallback<HttpResponse> responseCallback = null;
if (httpCallback != null) {
unCompletedTaskNum.incrementAndGet();
responseCallback = this.httpResponseCallbackFactory.wrapUpBaseHttpFutureCallback(httpCallback);
}
httpclient.execute(request,responseCallback);
}
示例10: createBatchPutDataCallback
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
public FutureCallback<HttpResponse> createBatchPutDataCallback(
final String address,
final AbstractBatchPutCallback<?> batchPutCallback,
final List<Point> pointList,
final HiTSDBConfig config,
final int batchPutRetryCount
) {
FutureCallback<HttpResponse> httpCallback = new BatchPutHttpResponseCallback (
address,
hitsdbHttpclient,
batchPutCallback,
pointList,
config,
config.getBatchPutRetryCount()
);
return httpCallback;
}
示例11: createNoLogicBatchPutHttpFutureCallback
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
public FutureCallback<HttpResponse> createNoLogicBatchPutHttpFutureCallback(
final String address,
final List<Point> pointList,
final HiTSDBConfig config,
final int batchPutRetryTimes
) {
FutureCallback<HttpResponse> httpCallback =
new BatchPutHttpResponseCallback (
address,
hitsdbHttpclient,
null,
pointList,
config,
batchPutRetryTimes
);
return httpCallback;
}
示例12: errorRetry
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
private void errorRetry() {
String newAddress;
boolean acquire;
int retryTimes = this.batchPutRetryTimes;
while(true) {
newAddress = getNextAddress();
acquire = this.hitsdbHttpClient.getSemaphoreManager().acquire(newAddress);
retryTimes--;
if(acquire || retryTimes <= 0) {
break;
}
}
if(retryTimes == 0) {
this.hitsdbHttpClient.getSemaphoreManager().release(address);
return ;
}
// retry!
LOGGER.warn("retry put data!");
HttpResponseCallbackFactory httpResponseCallbackFactory = this.hitsdbHttpClient.getHttpResponseCallbackFactory();
FutureCallback<HttpResponse> retryCallback;
if (batchPutCallback != null) {
retryCallback = httpResponseCallbackFactory.createBatchPutDataCallback(newAddress,this.batchPutCallback,this.pointList, this.config, retryTimes);
} else {
retryCallback = httpResponseCallbackFactory.createNoLogicBatchPutHttpFutureCallback(newAddress,this.pointList,this.config, retryTimes);
}
String jsonString = JSON.toJSONString(pointList);
this.hitsdbHttpClient.post(HttpAPI.PUT, jsonString, retryCallback);
}
示例13: asyncExecuteHttp
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
private ListenableFuture<HttpResponse> asyncExecuteHttp(final HttpUriRequest request) {
final SettableFuture<HttpResponse> future = SettableFuture.create();
httpClient.execute(request, new FutureCallback<HttpResponse>() {
@Override
public void completed(HttpResponse httpResponse) {
future.set(httpResponse);
}
@Override
public void failed(Exception e) {
future.setException(e);
}
@Override
public void cancelled() {
future.setException(new InterruptedException());
}
});
return future;
}
示例14: setUp
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
@Before
public void setUp() {
config = Configuration.buildFromConfig("config-mock.properties");
when(connectionStrategy.getHttpClient()).thenReturn(asyncHttpClient);
HttpResponse response = mock(HttpResponse.class);
Future<HttpResponse> future = ConcurrentUtils.constantFuture(response);
when(asyncHttpClient.execute(any(HttpUriRequest.class),any(FutureCallback.class))).thenReturn(future, null);
HttpEntity httpEntity = mock(HttpEntity.class);
when(response.getEntity()).thenReturn(httpEntity);
StatusLine statusLine = mock(StatusLine.class);
when(response.getStatusLine()).thenReturn(statusLine);
when(statusLine.getStatusCode()).thenReturn(200);
try {
InputStream inputStream = IOUtils.toInputStream(SERVER_RESPONSE_EXPECTED, "UTF-8");
when(httpEntity.getContent()).thenReturn(inputStream);
client = new LogInsightClient(config, connectionStrategy);
// client.connect(user, password);
assertEquals("Invalid session id!!",
"qyOLWEe7f/GjdM1WnczrCeQure97B/NpTbWTeqqYPBd1AYMf9cMNfQYqltITI4ffPMx822Sz9i/X47t8VwsDb0oGckclJUdn83cyIPk6WlsOpI4Yjw6WpurAnv9RhDsYSzKhAMzskzhTOJKfDHZjWR5v576WwtJA71wqI7igFrG91LG5c/3GfzMb68sUHF6hV+meYtGS4A1y/lUItvfkqTTAxBtTCZNoKrvCJZ4R+b6vuAAYoBNSWL7ycIy2LsALrVFxftAkA8n9DBAZYA9T5A==",
client.getSessionId());
} catch (Exception e) {
logger.error("Exception raised " + ExceptionUtils.getStackTrace(e));
}
}
示例15: doGet
import org.apache.http.concurrent.FutureCallback; //导入依赖的package包/类
protected void doGet(URI uri, final HTTPCallback httpCallback) {
HttpGet httpGet = new HttpGet(uri);
getClient(uri.getScheme().startsWith("https")).execute(httpGet, new FutureCallback<HttpResponse>() {
@Override
public void failed(Exception e) {
httpCallback.onRequestFailed(e);
}
@Override
public void completed(HttpResponse response) {
httpCallback.onRequestCompleted(response, false);
}
@Override
public void cancelled() {
httpCallback.onRequestCompleted(null, false);
}
});
}