public class MemcacheClientBuilder<V>
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<HostAndPort> |
addresses |
private BackoffFunction |
backoffFunction |
private int |
batchSize |
private java.lang.Class<? extends io.netty.channel.Channel> |
channelClass |
private java.nio.charset.Charset |
charset |
private int |
connections |
private long |
connectionTimeoutMillis |
private static java.lang.String |
DEFAULT_HOSTNAME |
private static int |
DEFAULT_MAX_OUTSTANDING |
private static int |
DEFAULT_MAX_SET_LENGTH |
private static int |
DEFAULT_PORT |
private static java.util.function.Supplier<java.util.concurrent.Executor> |
DEFAULT_REPLY_EXECUTOR
Lazily instantiated singleton default executor.
|
private static java.util.function.Supplier<java.util.concurrent.ScheduledExecutorService> |
DEFAULT_SCHEDULED_EXECUTOR
Lazily instantiated singleton default scheduled executor.
|
private io.netty.channel.EventLoopGroup |
eventLoopGroup |
private java.util.function.Supplier<java.util.concurrent.Executor> |
executor |
private int |
maxKeyLength |
private int |
maxOutstandingRequests |
private int |
maxSetLength |
private Metrics |
metrics |
private java.util.List<PlaintextAuthenticator> |
passwords |
private Resolver |
resolver |
private long |
resolveRefreshPeriod |
private boolean |
retry |
private long |
shutdownDelay |
private boolean |
skipAuth |
private java.lang.String |
srvRecord |
private com.spotify.dns.DnsSrvResolver |
srvResolver |
private Tracer |
tracer |
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,
Authenticator authenticator)
Connect a raw memcached client without any protocol specific methods.
|
private RawMemcacheClient |
createClient(HostAndPort address,
boolean binary,
Authenticator authenticator) |
private java.util.List<RawMemcacheClient> |
createClients(java.util.List<HostAndPort> addresses,
boolean binary,
Authenticator authenticator) |
private RawMemcacheClient |
createReconnectingClient(HostAndPort address,
boolean binary,
Authenticator authenticator) |
private RawMemcacheClient |
createResolvingClient(boolean binary,
Authenticator authenticator) |
private Authenticator |
getAuthenticator(Authenticator defaultValue) |
static MemcacheClientBuilder<byte[]> |
newByteArrayClient()
Create a client builder for byte array values.
|
static MemcacheClientBuilder<java.io.Serializable> |
newSerializableObjectClient()
Create a client builder for serializable object values.
|
static MemcacheClientBuilder<java.lang.String> |
newStringClient()
Create a client builder with a basic string transcoder using the UTF-8 Charset.
|
static MemcacheClientBuilder<java.lang.String> |
newStringClient(java.nio.charset.Charset charset)
Create a client builder with a basic string transcoder using the supplied Charset.
|
private void |
updateResolver()
Used for backwards compatibility for srvRecord and srvResolver.
|
MemcacheClientBuilder<V> |
withAddress(java.lang.String hostname)
Define which memcache server to connect to.
|
MemcacheClientBuilder<V> |
withAddress(java.lang.String host,
int port)
Define which memcache server to connect to.
|
MemcacheClientBuilder<V> |
withBackoff(BackoffFunction backoffFunction)
Specify how long the client should wait between reconnects.
|
MemcacheClientBuilder<V> |
withChannelClass(java.lang.Class<? extends io.netty.channel.Channel> channelClass)
Set a Netty
Channel class for the client. |
MemcacheClientBuilder<V> |
withConnections(int connections)
Use multiple connections to each memcache server.
|
MemcacheClientBuilder<V> |
withConnectionTimeoutMillis(long timeoutMillis)
Set the maximum time to wait before considering the connection to be dead and should be closed
and recreated.
|
MemcacheClientBuilder<V> |
withEventLoopGroup(io.netty.channel.EventLoopGroup eventLoopGroup)
Set an Netty
EventLoopGroup for the client. |
MemcacheClientBuilder<V> |
withKeyCharset(java.nio.charset.Charset charset)
Define the charset encoding for keys.
|
MemcacheClientBuilder<V> |
withMaxKeyLength(int maxKeyLength)
Set the maximum key length of the byte representation of the input string.
|
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.
|
(package private) MemcacheClientBuilder<V> |
withoutAuthenticationValidation()
Disable authentication validation - only useful for tests against jmemcached which does not
support binary NOOP
|
MemcacheClientBuilder<V> |
withReplyExecutor(java.util.concurrent.Executor executor)
Specify an executor to execute all replies on.
|
MemcacheClientBuilder<V> |
withRequestBatchSize(int batchSize)
Specify the maximum number of operations that will be batched together in one network request.
|
MemcacheClientBuilder<V> |
withRequestTimeoutMillis(long timeoutMillis)
Deprecated.
|
MemcacheClientBuilder<V> |
withResolver(Resolver resolver)
Use a dynamic resolved instead of a fixed set of addresses.
|
MemcacheClientBuilder<V> |
withResolveRefreshPeriod(long periodMillis)
This is only used for the dynamic ketama client.
|
MemcacheClientBuilder<V> |
withResolveShutdownDelay(long shutdownDelay)
This is only used for the dynamic ketama client.
|
MemcacheClientBuilder<V> |
withRetry(boolean retry)
Specify if the client should retry once if the connection is closed.
|
MemcacheClientBuilder<V> |
withSRVRecord(java.lang.String srvRecord)
Deprecated.
Use
withResolver(Resolver) with SrvResolver instead. |
MemcacheClientBuilder<V> |
withSRVRefreshPeriod(long periodMillis)
Deprecated.
|
MemcacheClientBuilder<V> |
withSrvResolver(com.spotify.dns.DnsSrvResolver srvResolver)
Deprecated.
Use
withResolver(Resolver) with SrvResolver instead |
MemcacheClientBuilder<V> |
withSRVShutdownDelay(long shutdownDelay)
Deprecated.
|
MemcacheClientBuilder<V> |
withTracer(Tracer tracer)
Specify how to collect tracing.
|
MemcacheClientBuilder<V> |
withUsernamePassword(java.lang.String username,
java.lang.String password)
Authenticate with memcached using plaintext SASL.
|
private static final int DEFAULT_MAX_SET_LENGTH
private static final int DEFAULT_MAX_OUTSTANDING
private static final java.lang.String DEFAULT_HOSTNAME
private static final int DEFAULT_PORT
private static final java.util.function.Supplier<java.util.concurrent.Executor> DEFAULT_REPLY_EXECUTOR
private static final java.util.function.Supplier<java.util.concurrent.ScheduledExecutorService> DEFAULT_SCHEDULED_EXECUTOR
private final java.util.List<HostAndPort> addresses
private int maxOutstandingRequests
private int batchSize
private final Transcoder<V> valueTranscoder
private Metrics metrics
private Tracer tracer
private BackoffFunction backoffFunction
private int connections
private boolean retry
private java.util.function.Supplier<java.util.concurrent.Executor> executor
private java.nio.charset.Charset charset
private Resolver resolver
private com.spotify.dns.DnsSrvResolver srvResolver
private java.lang.String srvRecord
private long resolveRefreshPeriod
private long shutdownDelay
private long connectionTimeoutMillis
private int maxSetLength
private int maxKeyLength
private io.netty.channel.EventLoopGroup eventLoopGroup
private java.lang.Class<? extends io.netty.channel.Channel> channelClass
private final java.util.List<PlaintextAuthenticator> passwords
private boolean skipAuth
public MemcacheClientBuilder(Transcoder<V> valueTranscoder)
valueTranscoder - the transcoder to use to encode/decode values.public static MemcacheClientBuilder<byte[]> newByteArrayClient()
public static MemcacheClientBuilder<java.lang.String> newStringClient()
public static MemcacheClientBuilder<java.lang.String> newStringClient(java.nio.charset.Charset charset)
charset - the Charset to encode and decode String objects with.public static MemcacheClientBuilder<java.io.Serializable> newSerializableObjectClient()
public MemcacheClientBuilder<V> withKeyCharset(java.nio.charset.Charset charset)
UTF-8 and most single-byte charsets should be fine though.
charset - The charset encoding for keys. The default is UTF-8.public MemcacheClientBuilder<V> withAddress(java.lang.String hostname)
hostname - a server, using the default memcached port (11211).public MemcacheClientBuilder<V> withAddress(java.lang.String host, int port)
host - The server hostnameport - The port where memcached is runningpublic MemcacheClientBuilder<V> withResolver(Resolver resolver)
resolver - the resolver to use.private void updateResolver()
@Deprecated public MemcacheClientBuilder<V> withSRVRecord(java.lang.String srvRecord)
withResolver(Resolver) with SrvResolver instead.public MemcacheClientBuilder<V> withResolveRefreshPeriod(long periodMillis)
periodMillis - time in milliseonds. The default is 60 seconds.@Deprecated public MemcacheClientBuilder<V> withSRVRefreshPeriod(long periodMillis)
withResolveRefreshPeriod(long)public MemcacheClientBuilder<V> withResolveShutdownDelay(long shutdownDelay)
shutdownDelay - time in milliseconds. The default is 60 seconds.@Deprecated public MemcacheClientBuilder<V> withSRVShutdownDelay(long shutdownDelay)
withResolveShutdownDelay(long)@Deprecated public MemcacheClientBuilder<V> withSrvResolver(com.spotify.dns.DnsSrvResolver srvResolver)
withResolver(Resolver) with SrvResolver insteadpublic MemcacheClientBuilder<V> withMetrics(Metrics metrics)
metrics - Default is NoopMetrics - which doesn't collect anything.public MemcacheClientBuilder<V> withTracer(Tracer tracer)
tracer - Default is NoopTracer - 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> withRequestBatchSize(int batchSize)
If the client's batch-size is larger than your memcached server's value, you may experience an increase in `conn_yields` on your memcached server's stats...which indicates your server is switching to other I/O connections during the batch request to not starve other connections.
If this value is too low, your will make more network requests per operation, thus reducing your server's overall throughput.
The optimal value should be matched to your workload and roughly the same value as your memcached server's `-R` argument, which defaults to 20.
batchSize - the maximum number of operations per batched client request. Default is
.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(java.util.concurrent.Executor executor)
ForkJoinPool in
async mode with one thread per processor.
If null is specified, replies will be executed on EventLoopGroup directly.
Note: Calling non-async methods on the CompletionStages
returned by MemcacheClient that have already completed will cause the supplied function
to be executed directly on the calling thread.
executor - the executor to use.public MemcacheClientBuilder<V> withConnections(int connections)
connections - Number of connections, must be 1 or greater. The default is 1@Deprecated public MemcacheClientBuilder<V> withRequestTimeoutMillis(long timeoutMillis)
Do not use this to enforce request timeouts. Instead, set a timeout on the request futures using orTimeout() or some other manual mechanism.
timeoutMillis - The timeout in milliseconds. The default is 3000 ms.public MemcacheClientBuilder<V> withConnectionTimeoutMillis(long timeoutMillis)
Do not use this to enforce request timeouts. Instead, set a timeout on the request futures using orTimeout() or some other manual mechanism.
timeoutMillis - The timeout in milliseconds. The default is 3000 ms.public MemcacheClientBuilder<V> withMaxSetLength(int maxSetLength)
If this limit is set higher than the actual limit in the memcache service, the memcache service may return a SERVER_ERROR which will close the connection to prevent any corrupted state.
The default value is 1 MiB
maxSetLength - The maximum size in bytespublic MemcacheClientBuilder<V> withEventLoopGroup(io.netty.channel.EventLoopGroup eventLoopGroup)
EventLoopGroup for the client.
If not specified, an event loop group will be created, with default thread count.
eventLoopGroup - an event loop group instancepublic MemcacheClientBuilder<V> withChannelClass(java.lang.Class<? extends io.netty.channel.Channel> channelClass)
Channel class for the client.
If not specified, it'll use a Channel class, according to the EventLoopGroup in use.
channelClass - a class of channel to use.public MemcacheClientBuilder<V> withMaxKeyLength(int maxKeyLength)
maxKeyLength - The maximum key length in bytespublic MemcacheClientBuilder<V> withUsernamePassword(java.lang.String username, java.lang.String password)
You may call this multiple times, to set multiple authentication attempts. This is typically only useful during a password rotation to avoid downtime.
username - password - MemcacheClientBuilder<V> withoutAuthenticationValidation()
public BinaryMemcacheClient<V> connectBinary()
BinaryMemcacheClientprivate Authenticator getAuthenticator(Authenticator defaultValue)
public AsciiMemcacheClient<V> connectAscii()
AsciiMemcacheClientprotected RawMemcacheClient connectRaw(boolean binary, Authenticator authenticator)
binary - whether to use the binary protocol or not.private java.util.List<RawMemcacheClient> createClients(java.util.List<HostAndPort> addresses, boolean binary, Authenticator authenticator)
private RawMemcacheClient createResolvingClient(boolean binary, Authenticator authenticator)
private RawMemcacheClient createClient(HostAndPort address, boolean binary, Authenticator authenticator)
private RawMemcacheClient createReconnectingClient(HostAndPort address, boolean binary, Authenticator authenticator)
Copyright © 2020 Spotify AB. All Rights Reserved.