net.shibboleth.utilities.java.support.httpclient
Class InMemoryCachingHttpClientBuilder

java.lang.Object
  extended by net.shibboleth.utilities.java.support.httpclient.InMemoryCachingHttpClientBuilder

public class InMemoryCachingHttpClientBuilder
extends Object

An HttpClient builder that supports RFC 2616 caching.

This client will cache information retrieved from the remote server in memory. The backing store does not perform any resource management (e.g., removing content that has nominally expired) so, special care must be taken to tune the maxCacheEntries and maxCacheEntrySize appropriately so that the system's memory is not fully consumed.


Field Summary
private  HttpClientBuilder clientBuilder
          Builder of clients used to fetch data from remote servers.
private  int maxCacheEntries
          The maximum number of cached responses.
private  int maxCacheEntrySize
          The maximum response body size, in bytes, that will be eligible for caching.
 
Constructor Summary
InMemoryCachingHttpClientBuilder(HttpClientBuilder builder)
          Constructor.
 
Method Summary
 HttpClient buildClient()
          Builds an HTTP client that performs RFC2616 caching.
 int getMaxCacheEntries()
          Gets the maximum number of cached responses.
 int getMaxCacheEntrySize()
          Gets the maximum response body size, in bytes, that will be eligible for caching.
 void setMaxCacheEntries(int maxEntries)
          Sets the maximum number of cached responses.
 void setMaxCacheEntrySize(int size)
          Sets the maximum response body size, in bytes, that will be eligible for caching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clientBuilder

private final HttpClientBuilder clientBuilder
Builder of clients used to fetch data from remote servers.


maxCacheEntries

private int maxCacheEntries
The maximum number of cached responses. Default: 50


maxCacheEntrySize

private int maxCacheEntrySize
The maximum response body size, in bytes, that will be eligible for caching. Default: 1048576 (1 megabyte)

Constructor Detail

InMemoryCachingHttpClientBuilder

public InMemoryCachingHttpClientBuilder(@Nonnull
                                        HttpClientBuilder builder)
Constructor.

Parameters:
builder - builder of clients used to fetch data from remote servers
Method Detail

getMaxCacheEntries

public int getMaxCacheEntries()
Gets the maximum number of cached responses.

Returns:
maximum number of cached responses

setMaxCacheEntries

public void setMaxCacheEntries(int maxEntries)
Sets the maximum number of cached responses.

Parameters:
maxEntries - maximum number of cached responses, must be greater than zero

getMaxCacheEntrySize

public int getMaxCacheEntrySize()
Gets the maximum response body size, in bytes, that will be eligible for caching.

Returns:
maximum response body size that will be eligible for caching

setMaxCacheEntrySize

public void setMaxCacheEntrySize(int size)
Sets the maximum response body size, in bytes, that will be eligible for caching.

Parameters:
size - maximum response body size that will be eligible for caching, must be greater than zero

buildClient

public HttpClient buildClient()
Builds an HTTP client that performs RFC2616 caching.

Returns:
the constructed HTTP client


Copyright © 1999-2012. All Rights Reserved.