Search in sources :

Example 1 with ReplicaNotConfiguredException

use of com.couchbase.client.core.error.ReplicaNotConfiguredException in project couchbase-jvm-clients by couchbase.

the class Observe method validateReplicas.

private static int validateReplicas(final BucketConfig bucketConfig, final ObservePersistTo persistTo, final ObserveReplicateTo replicateTo) {
    if (!(bucketConfig instanceof CouchbaseBucketConfig)) {
        throw new FeatureNotAvailableException("Only couchbase buckets support PersistTo and/or ReplicateTo");
    }
    CouchbaseBucketConfig cbc = (CouchbaseBucketConfig) bucketConfig;
    int numReplicas = cbc.numberOfReplicas();
    if (cbc.ephemeral() && persistTo.value() != 0) {
        throw new FeatureNotAvailableException("Ephemeral Buckets do not support " + "PersistTo");
    }
    if (replicateTo.touchesReplica() && replicateTo.value() > numReplicas) {
        throw new ReplicaNotConfiguredException("Not enough replicas configured on " + "the bucket");
    }
    if (persistTo.touchesReplica() && persistTo.value() - 1 > numReplicas) {
        throw new ReplicaNotConfiguredException("Not enough replicas configured on " + "the bucket");
    }
    return numReplicas;
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) ReplicaNotConfiguredException(com.couchbase.client.core.error.ReplicaNotConfiguredException)

Aggregations

CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)1 FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)1 ReplicaNotConfiguredException (com.couchbase.client.core.error.ReplicaNotConfiguredException)1