public class CouchbaseConnectionFactoryBuilder
extends net.spy.memcached.ConnectionFactoryBuilder
CouchbaseConnectionFactoryBuilder
enables the customization of
CouchbaseConnectionFactory
settings.
Some of the provides setter methods are for internal usage only, see the individual documentation for setter methods on this class for their impact, usage and defaults.
The builder should be used like this:
// Create the builder
CouchbaseConnectionFactoryBuilder builder =
new CouchbaseConnectionFactoryBuilder();
// Change a setting
builder.setOpTimeout(3000);
// Build the factory and use it
List<URI> nodes = Arrays.asList(URI.create("..."));
CouchbaseClient client = new CouchbaseClient(
builder.buildCouchbaseConnection(nodes, "bucket", "password")
);
Modifier and Type | Field and Description |
---|---|
protected long |
authWaitTime |
protected net.spy.memcached.metrics.MetricCollector |
collector |
protected java.util.concurrent.ExecutorService |
executorService |
protected net.spy.memcached.metrics.MetricType |
metricType |
authDescriptor, failureMode, hashAlg, initialObservers, isDaemon, locator, maxReconnectDelay, opFact, opQueueFactory, opQueueMaxBlockTime, opTimeout, readBufSize, readQueueFactory, shouldOptimize, timeoutExceptionThreshold, transcoder, useNagle, writeQueueFactory
Constructor and Description |
---|
CouchbaseConnectionFactoryBuilder() |
Modifier and Type | Method and Description |
---|---|
CouchbaseConnectionFactory |
buildCouchbaseConnection()
Build the
CouchbaseConnectionFactory set up with the provided
settings. |
CouchbaseConnectionFactory |
buildCouchbaseConnection(java.util.List<java.net.URI> baseList,
java.lang.String bucketName,
java.lang.String pwd)
Build the
CouchbaseConnectionFactory set up with the provided
settings. |
CouchbaseConnectionFactory |
buildCouchbaseConnection(java.util.List<java.net.URI> baseList,
java.lang.String bucketName,
java.lang.String usr,
java.lang.String pwd)
Deprecated.
|
long |
getAuthWaitTime()
Returns the currently configured authentication wait time.
|
long |
getObsPollInterval()
Returns the currently set observe poll interval.
|
int |
getObsPollMax()
Deprecated.
|
long |
getObsTimeout()
Returns the currently set observe timeout.
|
CouchbaseNodeOrder |
getStreamingNodeOrder()
Returns the currently configured streaming node order.
|
Config |
getVBucketConfig()
Returns a potentially set configuration.
|
int |
getViewConnsPerNode()
The currently configured number of maximum open view connections per node.
|
int |
getViewTimeout()
Returns the currently set view timeout.
|
int |
getViewWorkerSize()
The currently configured number of view workers.
|
net.spy.memcached.ConnectionFactoryBuilder |
setAuthWaitTime(long authWaitTime)
Sets a custom waiting time until authentication completes.
|
net.spy.memcached.ConnectionFactoryBuilder |
setEnableMetrics(net.spy.memcached.metrics.MetricType type)
Enable the collection of runtime metrics.
|
net.spy.memcached.ConnectionFactoryBuilder |
setListenerExecutorService(java.util.concurrent.ExecutorService executorService)
Set a custom
ExecutorService to execute the listener callbacks and
other callback-type operations. |
net.spy.memcached.ConnectionFactoryBuilder |
setMetricCollector(net.spy.memcached.metrics.MetricCollector collector)
Allows to provide a custom
MetricCollector . |
CouchbaseConnectionFactoryBuilder |
setObsPollInterval(long interval)
Sets a custom interval between observe poll cycles.
|
CouchbaseConnectionFactoryBuilder |
setObsPollMax(int maxPoll)
Deprecated.
|
CouchbaseConnectionFactoryBuilder |
setObsTimeout(long timeout)
Sets the absolute per-operation timeout for observe calls.
|
CouchbaseConnectionFactoryBuilder |
setReconnectThresholdTime(long time,
java.util.concurrent.TimeUnit unit)
Sets a custom reconnect threshold.
|
CouchbaseConnectionFactoryBuilder |
setStreamingNodeOrder(CouchbaseNodeOrder order)
Changes the node ordering for streaming connections.
|
CouchbaseConnectionFactoryBuilder |
setVBucketConfig(Config config)
Sets a custom
Config to use. |
CouchbaseConnectionFactoryBuilder |
setViewConnsPerNode(int conns)
Changes the maximum parallel open connections per node for view operations.
|
CouchbaseConnectionFactoryBuilder |
setViewTimeout(int timeout)
Sets a custom timeout for view operations.
|
CouchbaseConnectionFactoryBuilder |
setViewWorkerSize(int workers)
Sets a custom worker count for view operations.
|
build, setAuthDescriptor, setDaemon, setFailureMode, setHashAlg, setInitialObservers, setLocatorType, setMaxReconnectDelay, setOpFact, setOpQueueFactory, setOpQueueMaxBlockTime, setOpTimeout, setProtocol, setReadBufferSize, setReadOpQueueFactory, setShouldOptimize, setTimeoutExceptionThreshold, setTranscoder, setUseNagleAlgorithm, setWriteOpQueueFactory
protected net.spy.memcached.metrics.MetricType metricType
protected net.spy.memcached.metrics.MetricCollector collector
protected java.util.concurrent.ExecutorService executorService
protected long authWaitTime
public CouchbaseConnectionFactoryBuilder setVBucketConfig(Config config)
Config
to use.
Note that this method is only used for internal purposes and should not be used by regular applications. Use with care!
config
- the configuration to use.public CouchbaseConnectionFactoryBuilder setReconnectThresholdTime(long time, java.util.concurrent.TimeUnit unit)
If operations are failing for a period of time, the attached streaming connection for configuration updates is considered invalid and the client tries to establish a new connection by reconnecting. This threshold sets the time between those reconnect attempts to not overwhelm the server if it is already in a potentially unstable state.
Defaults to:
CouchbaseConnectionFactory.DEFAULT_MIN_RECONNECT_INTERVAL
time
- the time for the threshold.unit
- the unit for the time.public CouchbaseConnectionFactoryBuilder setObsPollInterval(long interval)
Every time a mutation operation with constraints (like
CouchbaseClient.set(String, Object, net.spy.memcached.PersistTo,
net.spy.memcached.ReplicateTo)
) is used, internally a poller observes the
server state until the required constraints can be met. This configuration
setting tunes this poll interval. If you expect faster replication or
persistence timings on the server than provided by the default interval,
set it to a lower value. If this value gets adjusted, it might make sense
to also adjust setObsTimeout(long)
.
Defaults to:
CouchbaseConnectionFactory.DEFAULT_OBS_POLL_INTERVAL
interval
- the interval in milliseconds.public CouchbaseConnectionFactoryBuilder setObsTimeout(long timeout)
This is the total timeout that the observe poller spends polling for
the desired constraint specified through a call like
CouchbaseClient.set(String, Object, net.spy.memcached.PersistTo,
net.spy.memcached.ReplicateTo)
. Together with
setObsPollInterval(long)
, both settings provide the tuning knobs
for observe-related behavior.
Defaults to:
CouchbaseConnectionFactory.DEFAULT_OBS_TIMEOUT
.
timeout
- the timeout in milliseconds.@Deprecated public CouchbaseConnectionFactoryBuilder setObsPollMax(int maxPoll)
This method has been deprecated. Do not use this method directly, but
instead use a combination of setObsPollInterval(long)
and
setObsTimeout(long)
to achieve the same effect. This setting
is ignored and has no impact on client behavior.
maxPoll
- the maximum number of polls to run before giving up.public CouchbaseConnectionFactoryBuilder setViewTimeout(int timeout)
A custom timeout in miliseconds can be specified to overrule the default timeout. If tuning this value significantly lower, it should be taken into consideration that view results take eventually longer to return than their key-based counterparts.
If a timeout lower than 500ms is applied, it will be capped to 500ms as a precaution and a warning will be issued. If it is lower than 2.5 seconds, a warning is also issued to notify a potential configuration issue.
Defaults to:
CouchbaseConnectionFactory.DEFAULT_VIEW_TIMEOUT
.
timeout
- the timeout in miliseconds.public CouchbaseConnectionFactoryBuilder setViewWorkerSize(int workers)
View requests are dispatched to asynchronous workers. This setting normally only needs to be tuned if there is a very high view workload and there is a suspicion that the default worker size is the bottleneck and cannot handle the needed traffic. If increased, also consider increasing the maximum connections per node.
Defaults to
CouchbaseConnectionFactory.DEFAULT_VIEW_WORKER_SIZE
.
workers
- the number of workers.public CouchbaseConnectionFactoryBuilder setViewConnsPerNode(int conns)
View connections are openend on demand to each node, so with increasing traffic more and more parallel connections are opened to satisfy the workload needs. This setting allows to change the upper limit of open connections per node.
Defaults to
CouchbaseConnectionFactory.DEFAULT_VIEW_CONNS_PER_NODE
.
conns
- maximum parallel open connections per node.public CouchbaseConnectionFactoryBuilder setStreamingNodeOrder(CouchbaseNodeOrder order)
To prevent the case where all streaming connections are opened on the first node in the bootstrap list (and potentially overwhelm the server), the default ordering mixes the nodes before attaching the connection. This provides better distribution of the streaming connection. If old behavior should be forced or there is a specific reason to fallback to the same ordering, the setting can be changed.
Defaults to
CouchbaseConnectionFactory.DEFAULT_STREAMING_NODE_ORDER
.
order
- the ordering to use.public net.spy.memcached.ConnectionFactoryBuilder setEnableMetrics(net.spy.memcached.metrics.MetricType type)
Runtime metrics collection can be enabled to provide better insight to what is happening inside the client library. Since the collection of metrics comes with a performance penalty, it is disable by default and can be enabled to a variety of different metric collection types. The debug mode subsumes the performance mode and provides the deepest insight.
Defaults to DefaultConnectionFactory.DEFAULT_METRIC_TYPE
.
setEnableMetrics
in class net.spy.memcached.ConnectionFactoryBuilder
type
- the metric type to use (or disable).public net.spy.memcached.ConnectionFactoryBuilder setMetricCollector(net.spy.memcached.metrics.MetricCollector collector)
MetricCollector
.
If metrics should be collected in a different way, a custom collector can be passed in which will then receive the metrics exposed by the client library. This is considered advanced functionality and should normally not be overriden.
setMetricCollector
in class net.spy.memcached.ConnectionFactoryBuilder
collector
- the metric collector to use.public net.spy.memcached.ConnectionFactoryBuilder setListenerExecutorService(java.util.concurrent.ExecutorService executorService)
ExecutorService
to execute the listener callbacks and
other callback-type operations.
If the executor is created inside the client library, it is also shut down automatically. If a custom one gets passed in, it is the responsibility of the caller to shut it down since the client library does not know who else is depending on the executor.
Passing in a custom executor service is handy if it should be shared
across many CouchbaseClient
instances or if the application already
uses a thread pool for long running tasks and it can be shared with the
client library.
Defaults to a thread pool executor which can scale up to the number of
configured CPUs as exposed by the Runtime.availableProcessors()
setting.
setListenerExecutorService
in class net.spy.memcached.ConnectionFactoryBuilder
executorService
- the ExecutorService to use.public net.spy.memcached.ConnectionFactoryBuilder setAuthWaitTime(long authWaitTime)
This setting does not need to be changed normally, but if the client logs indicate that authentication to server nodes takes longer than expected, it might pay off to increase the wait time. That said, in general this indicates some odd behavior and should be looked into separately.
Defaults to
CouchbaseConnectionFactory.DEFAULT_AUTH_WAIT_TIME
.
setAuthWaitTime
in class net.spy.memcached.ConnectionFactoryBuilder
authWaitTime
- the wait time in miliseconds.public CouchbaseConnectionFactory buildCouchbaseConnection(java.util.List<java.net.URI> baseList, java.lang.String bucketName, java.lang.String pwd) throws java.io.IOException
CouchbaseConnectionFactory
set up with the provided
settings.baseList
- list of seed nodes.bucketName
- the name of the bucket.pwd
- the password of the bucket.CouchbaseConnectionFactory
.java.io.IOException
- if the connection could not be established.@Deprecated public CouchbaseConnectionFactory buildCouchbaseConnection(java.util.List<java.net.URI> baseList, java.lang.String bucketName, java.lang.String usr, java.lang.String pwd) throws java.io.IOException
CouchbaseConnectionFactory
set up with the provided
settings.
This method is deprecated since the username does not need to be
provided - only the name of the bucket. Use the
buildCouchbaseConnection(java.util.List, String, String)
method
instead.
baseList
- list of seed nodes.bucketName
- the name of the bucket.usr
- the username.pwd
- the password of the bucket.CouchbaseConnectionFactory
.java.io.IOException
- if the connection could not be established.public CouchbaseConnectionFactory buildCouchbaseConnection() throws java.io.IOException
CouchbaseConnectionFactory
set up with the provided
settings.
If this method is used, the seed nodes, bucket name and password are picked from system properties instead of the actual method params. They are:
The following properties need to be set in order to bootstrap: - cbclient.nodes: ;-separated list of URIs - cbclient.bucket: name of the bucket - cbclient.password: password of the bucket
CouchbaseConnectionFactory
.java.io.IOException
- if the connection could not be established.public long getObsPollInterval()
@Deprecated public int getObsPollMax()
public long getObsTimeout()
public int getViewTimeout()
public int getViewWorkerSize()
public int getViewConnsPerNode()
public long getAuthWaitTime()
public Config getVBucketConfig()
For internal use only.
public CouchbaseNodeOrder getStreamingNodeOrder()
Copyright © 2006-2009 Dustin Sallings, 2009-2012 Couchbase, Inc.