use of com.couchbase.client.core.cnc.events.config.CollectionMapRefreshSucceededEvent in project couchbase-jvm-clients by couchbase.
the class DefaultConfigurationProvider method refreshCollectionId.
@Override
public synchronized void refreshCollectionId(final CollectionIdentifier identifier) {
if (collectionRefreshInProgress(identifier)) {
eventBus.publish(new CollectionMapRefreshIgnoredEvent(core.context(), identifier));
return;
}
collectionMapRefreshInProgress.add(identifier);
long start = System.nanoTime();
GetCollectionIdRequest request = new GetCollectionIdRequest(core.context().environment().timeoutConfig().kvTimeout(), core.context(), BestEffortRetryStrategy.INSTANCE, identifier);
core.send(request);
request.response().whenComplete((response, throwable) -> {
try {
final Duration duration = Duration.ofNanos(System.nanoTime() - start);
if (throwable != null) {
eventBus.publish(new CollectionMapRefreshFailedEvent(duration, core.context(), identifier, throwable, CollectionMapRefreshFailedEvent.Reason.FAILED));
return;
}
if (response.status().success()) {
if (response.collectionId().isPresent()) {
long cid = response.collectionId().get();
collectionMap.put(identifier, UnsignedLEB128.encode(cid));
eventBus.publish(new CollectionMapRefreshSucceededEvent(duration, core.context(), identifier, cid));
} else {
eventBus.publish(new CollectionMapRefreshFailedEvent(duration, core.context(), identifier, null, CollectionMapRefreshFailedEvent.Reason.COLLECTION_ID_NOT_PRESENT));
}
} else {
Throwable cause = null;
CollectionMapRefreshFailedEvent.Reason reason;
if (response.status() == ResponseStatus.UNKNOWN || response.status() == ResponseStatus.NO_COLLECTIONS_MANIFEST) {
reason = CollectionMapRefreshFailedEvent.Reason.NOT_SUPPORTED;
} else if (response.status() == ResponseStatus.UNKNOWN_COLLECTION) {
reason = CollectionMapRefreshFailedEvent.Reason.UNKNOWN_COLLECTION;
} else if (response.status() == ResponseStatus.UNKNOWN_SCOPE) {
reason = CollectionMapRefreshFailedEvent.Reason.UNKNOWN_SCOPE;
} else if (response.status() == ResponseStatus.INVALID_REQUEST) {
reason = CollectionMapRefreshFailedEvent.Reason.INVALID_REQUEST;
} else {
cause = new CouchbaseException(response.toString());
reason = CollectionMapRefreshFailedEvent.Reason.UNKNOWN;
}
eventBus.publish(new CollectionMapRefreshFailedEvent(duration, core.context(), identifier, cause, reason));
}
} finally {
collectionMapRefreshInProgress.remove(identifier);
}
});
}
Aggregations