private void upload(HttpEntity entity, Integer connectionTimeoutInMillis, FutureCallback<UploadResponse> asyncHandler) { try { Async.newInstance().execute(Request.Post(documentUploadAddress.toURI()) .addHeader(USER_AGENT_HEADER_KEY, DefaultValues.USER_AGENT) .connectTimeout(connectionTimeoutInMillis) .body(entity), new ResponseHandlerAdapter<UploadResponse>(asyncHandler) { @Override public UploadResponse convertHttpResponse(HttpResponse httpResponse) { logger.info(MESSAGES.UPLOAD_COMPLETE); int statusCode = httpResponse.getStatusLine().getStatusCode(); String errorMessage = httpResponse.getStatusLine().getReasonPhrase(); if (statusCode == POSSIBLE_BAD_CREDENTIALS) { errorMessage = errorMessage + MESSAGES.FAILED_FILE_UPLOAD_CREDENTIALS; } return new UploadResponse(statusCode, errorMessage); } }); } catch (URISyntaxException e) { if (logger.isErrorEnabled()) { logger.error(String.format(MESSAGES.UPLOAD_ERROR, e.getMessage())); } asyncHandler.onFailure(new MovilizerWebServiceException(e)); } }
public HttpStorageCaching() { threadpool = Executors.newFixedThreadPool(100); asyncHttp = Async.newInstance().use(threadpool); cacheWeighter = new Weigher<String, byte[]>() { @Override public int weigh(String key, byte[] value) { return value.length; } }; cache = CacheBuilder.newBuilder() .weigher(cacheWeighter) .maximumWeight(CACHE_WEIGHT) .build(); }
public HttpStorage() { threadpool = Executors.newFixedThreadPool(100); asyncHttp = Async.newInstance().use(threadpool); }
protected void setupAsync(){ threadpool = Executors.newFixedThreadPool(2); async = Async.newInstance().use(threadpool); }