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;
}
Aggregations