Search in sources :

Example 1 with RouteRemovedEvent

use of org.apache.camel.management.event.RouteRemovedEvent in project camel by apache.

the class DefaultRuntimeEndpointRegistry method notify.

@Override
public void notify(EventObject event) throws Exception {
    if (event instanceof RouteAddedEvent) {
        RouteAddedEvent rse = (RouteAddedEvent) event;
        Endpoint endpoint = rse.getRoute().getEndpoint();
        String routeId = rse.getRoute().getId();
        // a HashSet is fine for inputs as we only have a limited number of those
        Set<String> uris = new HashSet<String>();
        uris.add(endpoint.getEndpointUri());
        inputs.put(routeId, uris);
        // use a LRUCache for outputs as we could potential have unlimited uris if dynamic routing is in use
        // and therefore need to have the limit in use
        outputs.put(routeId, new LRUCache<String, String>(limit));
    } else if (event instanceof RouteRemovedEvent) {
        RouteRemovedEvent rse = (RouteRemovedEvent) event;
        String routeId = rse.getRoute().getId();
        inputs.remove(routeId);
        outputs.remove(routeId);
        if (extended) {
            String uri = rse.getRoute().getEndpoint().getEndpointUri();
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                inputUtilization.remove(key);
            }
        }
    } else if (extended && event instanceof ExchangeCreatedEvent) {
        // we only capture details in extended mode
        ExchangeCreatedEvent ece = (ExchangeCreatedEvent) event;
        Endpoint endpoint = ece.getExchange().getFromEndpoint();
        if (endpoint != null) {
            String routeId = ece.getExchange().getFromRouteId();
            String uri = endpoint.getEndpointUri();
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                inputUtilization.onHit(key);
            }
        }
    } else if (event instanceof ExchangeSendingEvent) {
        ExchangeSendingEvent ese = (ExchangeSendingEvent) event;
        Endpoint endpoint = ese.getEndpoint();
        String routeId = getRouteId(ese.getExchange());
        String uri = endpoint.getEndpointUri();
        Map<String, String> uris = outputs.get(routeId);
        if (uris != null && !uris.containsKey(uri)) {
            uris.put(uri, uri);
        }
        if (extended) {
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                outputUtilization.onHit(key);
            }
        }
    }
}
Also used : RouteAddedEvent(org.apache.camel.management.event.RouteAddedEvent) ExchangeCreatedEvent(org.apache.camel.management.event.ExchangeCreatedEvent) ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent) Endpoint(org.apache.camel.Endpoint) RouteRemovedEvent(org.apache.camel.management.event.RouteRemovedEvent) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Endpoint (org.apache.camel.Endpoint)1 ExchangeCreatedEvent (org.apache.camel.management.event.ExchangeCreatedEvent)1 ExchangeSendingEvent (org.apache.camel.management.event.ExchangeSendingEvent)1 RouteAddedEvent (org.apache.camel.management.event.RouteAddedEvent)1 RouteRemovedEvent (org.apache.camel.management.event.RouteRemovedEvent)1