Search in sources :

Example 1 with IdleEndpointRemovedEvent

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));
    }
}
Also used : EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) HashMap(java.util.HashMap) IdleEndpointRemovedEvent(com.couchbase.client.core.cnc.events.service.IdleEndpointRemovedEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IdleEndpointRemovedEvent (com.couchbase.client.core.cnc.events.service.IdleEndpointRemovedEvent)1 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1