Search in sources :

Example 1 with ExchangeCreatedEvent

use of org.apache.camel.management.event.ExchangeCreatedEvent 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)

Example 2 with ExchangeCreatedEvent

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

the class DefaultDebugger method addSingleStepBreakpoint.

@Override
public void addSingleStepBreakpoint(final Breakpoint breakpoint, Condition... conditions) {
    // wrap the breakpoint into single step breakpoint so we can automatic enable/disable the single step mode
    Breakpoint singlestep = new Breakpoint() {

        @Override
        public State getState() {
            return breakpoint.getState();
        }

        @Override
        public void suspend() {
            breakpoint.suspend();
        }

        @Override
        public void activate() {
            breakpoint.activate();
        }

        @Override
        public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
            breakpoint.beforeProcess(exchange, processor, definition);
        }

        @Override
        public void afterProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition, long timeTaken) {
            breakpoint.afterProcess(exchange, processor, definition, timeTaken);
        }

        @Override
        public void onEvent(Exchange exchange, EventObject event, ProcessorDefinition<?> definition) {
            if (event instanceof ExchangeCreatedEvent) {
                exchange.getContext().getDebugger().startSingleStepExchange(exchange.getExchangeId(), this);
            } else if (event instanceof ExchangeCompletedEvent) {
                exchange.getContext().getDebugger().stopSingleStepExchange(exchange.getExchangeId());
            }
            breakpoint.onEvent(exchange, event, definition);
        }

        @Override
        public String toString() {
            return breakpoint.toString();
        }
    };
    addBreakpoint(singlestep, conditions);
}
Also used : Exchange(org.apache.camel.Exchange) Breakpoint(org.apache.camel.spi.Breakpoint) ExchangeCreatedEvent(org.apache.camel.management.event.ExchangeCreatedEvent) Processor(org.apache.camel.Processor) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) ExchangeCompletedEvent(org.apache.camel.management.event.ExchangeCompletedEvent) EventObject(java.util.EventObject)

Aggregations

ExchangeCreatedEvent (org.apache.camel.management.event.ExchangeCreatedEvent)2 EventObject (java.util.EventObject)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)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 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)1 Breakpoint (org.apache.camel.spi.Breakpoint)1