public class MemcacheClientBuilder<V> extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
MemcacheClientBuilder.DefaultDnsResolver
Lazily instantiated singleton default srvResolver.
|
private static class |
MemcacheClientBuilder.DefaultExecutor
Lazily instantiated singleton default executor.
|
private static class |
MemcacheClientBuilder.DefaultScheduledExecutor
Lazily instantiated singleton default scheduled executor.
|
| Modifier and Type | Field and Description |
|---|---|
private List<com.google.common.net.HostAndPort> |
addresses |
private BackoffFunction |
backoffFunction |
private Charset |
charset |
private int |
connections |
private static String |
DEFAULT_HOSTNAME |
private static int |
DEFAULT_MAX_OUTSTANDING |
private static int |
DEFAULT_MAX_SET_LENGTH |
private static int |
DEFAULT_PORT |
private long |
dnsRefreshPeriod |
private Executor |
executor |
private int |
maxOutstandingRequests |
private int |
maxSetLength |
private Metrics |
metrics |
private boolean |
retry |
private long |
shutdownDelay |
private String |
srvRecord |
private com.spotify.dns.DnsSrvResolver |
srvResolver |
private long |
timeoutMillis |
private Transcoder<V> |
valueTranscoder |
| Constructor and Description |
|---|
MemcacheClientBuilder(Transcoder<V> valueTranscoder)
Create a client builder with the provided value transcoder.
|
| Modifier and Type | Method and Description |
|---|---|
AsciiMemcacheClient<V> |
connectAscii()
Create a client that uses the ascii memcache protocol.
|
BinaryMemcacheClient<V> |
connectBinary()
Create a client that uses the binary memcache protocol.
|
protected RawMemcacheClient |
connectRaw(boolean binary)
Connect a raw memcached client without any protocol specific methods.
|
private RawMemcacheClient |
createClient(com.google.common.net.HostAndPort address,
boolean binary) |
private List<RawMemcacheClient> |
createClients(List<com.google.common.net.HostAndPort> addresses,
boolean binary) |
private RawMemcacheClient |
createReconnectingClient(com.google.common.net.HostAndPort address,
boolean binary) |
private RawMemcacheClient |
createSRVClient(boolean binary) |
static MemcacheClientBuilder<byte[]> |
newByteArrayClient()
Create a client builder for byte array values.
|
static MemcacheClientBuilder<Serializable> |
newSerializableObjectClient()
Create a client builder for serializable object values.
|
static MemcacheClientBuilder<String> |
newStringClient()
Create a client builder with a basic string transcoder using the UTF-8
Charset.
|
static MemcacheClientBuilder<String> |
newStringClient(Charset charset)
Create a client builder with a basic string transcoder using the supplied
Charset.
|
MemcacheClientBuilder<V> |
withAddress(com.google.common.net.HostAndPort address)
Define which memcache server to connect to.
|
MemcacheClientBuilder<V> |
withAddress(String hostname)
Define which memcache server to connect to.
|
MemcacheClientBuilder<V> |
withAddresses(List<com.google.common.net.HostAndPort> addresses)
Define which memcache servers to connect to.
|
MemcacheClientBuilder<V> |
withBackoff(BackoffFunction backoffFunction)
Specify how long the client should wait between reconnects.
|
MemcacheClientBuilder<V> |
withConnections(int connections)
Use multiple connections to each memcache server.
|
MemcacheClientBuilder<V> |
withKeyCharset(Charset charset)
Define the charset encoding for keys.
|
MemcacheClientBuilder<V> |
withMaxOutstandingRequests(int maxOutstandingRequests)
Specify the maximum number of requests in the queue per server connection.
|
MemcacheClientBuilder<V> |
withMaxSetLength(int maxSetLength)
Set the maximum value size for set requests.
|
MemcacheClientBuilder<V> |
withMetrics(Metrics metrics)
Specify how to collect metrics.
|
MemcacheClientBuilder<V> |
withReplyExecutor(Executor executor)
Specify an executor to execute all replies on.
|
MemcacheClientBuilder<V> |
withRequestTimeoutMillis(long timeoutMillis)
Enforce a timeout for requests to complete, closing the connection and reconnecting if the
timeout is exceeded.
|
MemcacheClientBuilder<V> |
withRetry(boolean retry)
Specify if the client should retry once if the connection is closed.
|
MemcacheClientBuilder<V> |
withSRVRecord(String srvRecord)
Use SRV to lookup nodes instead of a fixed set of addresses.
|
MemcacheClientBuilder<V> |
withSRVRefreshPeriod(long periodMillis)
This is only used for the SRV based ketama client.
|
MemcacheClientBuilder<V> |
withSrvResolver(com.spotify.dns.DnsSrvResolver srvResolver)
Use a specific SRV resolver.
|
MemcacheClientBuilder<V> |
withSRVShutdownDelay(long shutdownDelay)
This is only used for the SRV based ketama client.
|
private static final int DEFAULT_MAX_SET_LENGTH
private static final int DEFAULT_MAX_OUTSTANDING
private static final String DEFAULT_HOSTNAME
private static final int DEFAULT_PORT
private List<com.google.common.net.HostAndPort> addresses
private int maxOutstandingRequests
private final Transcoder<V> valueTranscoder
private Metrics metrics
private BackoffFunction backoffFunction
private int connections
private boolean retry
private Executor executor
private Charset charset
private com.spotify.dns.DnsSrvResolver srvResolver
private String srvRecord
private long dnsRefreshPeriod
private long shutdownDelay
private long timeoutMillis
private int maxSetLength
public MemcacheClientBuilder(Transcoder<V> valueTranscoder)
valueTranscoder - the transcoder to use to encode/decode values.public static MemcacheClientBuilder<byte[]> newByteArrayClient()
public static MemcacheClientBuilder<String> newStringClient()
public static MemcacheClientBuilder<String> newStringClient(Charset charset)
charset - the Charset to encode and decode String objects with.public static MemcacheClientBuilder<Serializable> newSerializableObjectClient()
public MemcacheClientBuilder<V> withKeyCharset(Charset charset)
charset - The charset encoding for keys. The default is UTF-8.public MemcacheClientBuilder<V> withAddress(String hostname)
hostname - a server, using the default memcached port (11211).public MemcacheClientBuilder<V> withAddress(com.google.common.net.HostAndPort address)
address - a server.public MemcacheClientBuilder<V> withAddresses(List<com.google.common.net.HostAndPort> addresses)
addresses - a list of servers.public MemcacheClientBuilder<V> withSRVRecord(String srvRecord)
srvRecord - the SRV record to use.public MemcacheClientBuilder<V> withSRVRefreshPeriod(long periodMillis)
periodMillis - time in milliseonds. The default is 60 seconds.public MemcacheClientBuilder<V> withSRVShutdownDelay(long shutdownDelay)
shutdownDelay - time in milliseconds. The default is 60 seconds.public MemcacheClientBuilder<V> withSrvResolver(com.spotify.dns.DnsSrvResolver srvResolver)
srvResolver - the resolver to use. Default is a caching resolver from
DnsSrvResolverspublic MemcacheClientBuilder<V> withMetrics(Metrics metrics)
metrics - Default is NoopMetrics - which doesn't collect anything.public MemcacheClientBuilder<V> withMaxOutstandingRequests(int maxOutstandingRequests)
MemcacheOverloadedException.
If this is set too high, there is a risk of having high latency requests and delaying the
time to notice that the system is malfunctioning.maxOutstandingRequests - the maximum number of requests that can be in queue.
Default is 1000.public MemcacheClientBuilder<V> withBackoff(BackoffFunction backoffFunction)
backoffFunction - A custom backoff function. Default is exponential backoff.public MemcacheClientBuilder<V> withRetry(boolean retry)
retry - Default is truepublic MemcacheClientBuilder<V> withReplyExecutor(Executor executor)
ForkJoinPool in
async mode with one thread per processor.executor - the executor to use.public MemcacheClientBuilder<V> withConnections(int connections)
connections - Number of connections, must be 1 or greater. The default is 1public MemcacheClientBuilder<V> withRequestTimeoutMillis(long timeoutMillis)
timeoutMillis - The timeout in milliseconds. The default is 3000 ms.public MemcacheClientBuilder<V> withMaxSetLength(int maxSetLength)
maxSetLength - The maximum size in bytespublic BinaryMemcacheClient<V> connectBinary()
BinaryMemcacheClientpublic AsciiMemcacheClient<V> connectAscii()
AsciiMemcacheClientprotected RawMemcacheClient connectRaw(boolean binary)
binary - whether to use the binary protocol or not.private List<RawMemcacheClient> createClients(List<com.google.common.net.HostAndPort> addresses, boolean binary)
private RawMemcacheClient createSRVClient(boolean binary)
private RawMemcacheClient createClient(com.google.common.net.HostAndPort address, boolean binary)
private RawMemcacheClient createReconnectingClient(com.google.common.net.HostAndPort address, boolean binary)
Copyright © 2017 Spotify AB. All Rights Reserved.