use of com.couchbase.client.core.cnc.events.service.IdleEndpointRemovedEvent in project couchbase-jvm-clients by couchbase.
the class PooledService method publishIdleEndpointRemovedEvent.
/**
* Helper method to publish an event with enriched context when an idle endpoint has been removed.
*
* @param endpoint the endpoint that got removed.
* @param actualIdleTime the actual idle time of that endpoint.
*/
private void publishIdleEndpointRemovedEvent(final Endpoint endpoint, final long actualIdleTime) {
if (endpoint.context() != null) {
final EndpointContext enrichedContext = new EndpointContext(endpoint.context()) {
@Override
public void injectExportableParams(final Map<String, Object> input) {
super.injectExportableParams(input);
Map<String, Object> serviceInfo = new HashMap<>();
input.put("actualIdleTimeMillis", TimeUnit.NANOSECONDS.toMillis(actualIdleTime));
serviceInfo.put("remainingEndpoints", endpoints.size());
serviceInfo.put("reservedEndpoints", reservedEndpoints.size());
serviceInfo.put("state", state());
input.put("service", serviceInfo);
}
};
serviceContext.environment().eventBus().publish(new IdleEndpointRemovedEvent(enrichedContext));
}
}
Aggregations