Search in sources :

Example 6 with KeyValueRequest

use of com.couchbase.client.core.msg.kv.KeyValueRequest in project couchbase-jvm-clients by couchbase.

the class PartitionSelectionStrategy method select.

@Override
public <R extends Request<? extends Response>> Endpoint select(final R request, final List<Endpoint> endpoints) {
    int size = endpoints.size();
    if (size == 0) {
        return null;
    }
    short partition = ((KeyValueRequest<?>) request).partition();
    Endpoint endpoint = size == 1 ? endpoints.get(0) : endpoints.get(partition % size);
    if (endpoint != null && endpoint.state() == EndpointState.CONNECTED && endpoint.freeToWrite()) {
        return endpoint;
    }
    return null;
}
Also used : KeyValueRequest(com.couchbase.client.core.msg.kv.KeyValueRequest) Endpoint(com.couchbase.client.core.endpoint.Endpoint) Endpoint(com.couchbase.client.core.endpoint.Endpoint)

Aggregations

KeyValueRequest (com.couchbase.client.core.msg.kv.KeyValueRequest)6 MemcachedBucketConfig (com.couchbase.client.core.config.MemcachedBucketConfig)3 Response (com.couchbase.client.core.msg.Response)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 RequestTracer (com.couchbase.client.core.cnc.RequestTracer)2 ChannelClosedProactivelyEvent (com.couchbase.client.core.cnc.events.io.ChannelClosedProactivelyEvent)2 InvalidRequestDetectedEvent (com.couchbase.client.core.cnc.events.io.InvalidRequestDetectedEvent)2 ConfigurationProvider (com.couchbase.client.core.config.ConfigurationProvider)2 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)2 CollectionNotFoundException (com.couchbase.client.core.error.CollectionNotFoundException)2 Service (com.couchbase.client.core.service.Service)2 ServiceType (com.couchbase.client.core.service.ServiceType)2 Optional (java.util.Optional)2 Test (org.junit.jupiter.api.Test)2 CoreContext (com.couchbase.client.core.CoreContext)1 CbTracing (com.couchbase.client.core.cnc.CbTracing)1 EventBus (com.couchbase.client.core.cnc.EventBus)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 CollectionOutdatedHandledEvent (com.couchbase.client.core.cnc.events.io.CollectionOutdatedHandledEvent)1 KeyValueErrorMapCodeHandledEvent (com.couchbase.client.core.cnc.events.io.KeyValueErrorMapCodeHandledEvent)1