com.fasterxml.clustermate.client.ahc.AHCContentHeader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clustermate-client-ahc Show documentation
Show all versions of clustermate-client-ahc Show documentation
Almost complete ClusterMate NetworkClient implementation built on
Async HTTP Client
The newest version!
package com.fasterxml.clustermate.client.ahc;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.ning.http.client.*;
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
import com.fasterxml.clustermate.api.ClusterMateConstants;
import com.fasterxml.clustermate.api.EntryKey;
import com.fasterxml.clustermate.client.*;
import com.fasterxml.clustermate.client.call.CallConfig;
import com.fasterxml.clustermate.client.call.CallFailure;
import com.fasterxml.clustermate.client.call.ContentHeader;
import com.fasterxml.clustermate.client.call.ReadCallParameters;
import com.fasterxml.storemate.shared.util.IOUtil;
/**
* Helper object for making HEAD requests.
*/
public class AHCContentHeader
extends AHCBasedAccessor
implements ContentHeader
{
public AHCContentHeader(StoreClientConfig storeConfig,
AsyncHttpClient hc, ClusterServerNode server)
{
super(storeConfig, hc, server);
}
/*
/**********************************************************************
/* Call implementation
/**********************************************************************
*/
@Override
public AHCHeadCallResult tryHead(CallConfig config, ReadCallParameters params,
long endOfTime, K contentId)
{
// first: if we can't spend at least 10 msecs, let's give up:
final long startTime = System.currentTimeMillis();
long timeout = Math.min(endOfTime - startTime, config.getGetCallTimeoutMsecs());
if (timeout < config.getMinimumTimeoutMsecs()) {
return new AHCHeadCallResult(CallFailure.timeout(_server, startTime, startTime));
}
try {
AHCPathBuilder path = _server.rootPath();
path = _pathFinder.appendStoreEntryPath(path);
path = _keyConverter.appendToPath(path, contentId);
if (params != null) {
path = params.appendToPath(path, contentId);
}
BoundRequestBuilder reqBuilder = path.headRequest(_httpClient);
HeadHandler hh = new HeadHandler(this, _server, startTime);
ListenableFuture