Java 类org.apache.camel.management.event.AbstractExchangeEvent 实例源码

项目:springboot-camel-metrics-publisher    文件:CamelMetricsUpdater.java   
@Override
public void notify(EventObject event) throws Exception {
    boolean covered = false;

    if (event instanceof AbstractExchangeEvent) {
        AbstractExchangeEvent ev = AbstractExchangeEvent.class.cast(event);

        final Exchange exchange = ev.getExchange();
        String metricPrefix = exchange.getFromRouteId();

        // if we can't find the prefix for the metrics then don't capture any
        if (metricPrefix == null || metricPrefix.equals("")) { return; }

        if (ev instanceof ExchangeCompletedEvent || ev instanceof ExchangeFailedEvent || ev instanceof ExchangeRedeliveryEvent) {
            onExchangeCompletedEvent(ev, metricPrefix);
            covered = true;
        } else {
            metrics.meter(name(event.getClass(), metricPrefix)).mark();
        }
    }

    if (!covered)
        LOGGER.debug("Not covered: Type {} ({})", event.getClass(), event);
}
项目:Camel    文件:DebugExceptionEventBreakpointTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();

    breakpoint = new BreakpointSupport() {
        public void onEvent(Exchange exchange, EventObject event, ProcessorDefinition<?> definition) {
            AbstractExchangeEvent aee = (AbstractExchangeEvent) event;
            Exception e = aee.getExchange().getException();
            logs.add("Breakpoint at " + definition + " caused by: " + e.getClass().getSimpleName() + "[" + e.getMessage() + "]");
        }
    };

    exceptionCondition = new ConditionSupport() {
        public boolean matchEvent(Exchange exchange, EventObject event) {
            return event instanceof ExchangeFailedEvent;
        }
    };
}
项目:Camel    文件:CdiCamelExtension.java   
private <T extends EventObject> void camelEventNotifiers(@Observes ProcessObserverMethod<T, ?> pom) {
    // Only activate Camel event notifiers for explicit Camel event observers, that is, an observer method for a super type won't activate notifiers.
    Type type = pom.getObserverMethod().getObservedType();
    // Camel events are raw types
    if (type instanceof Class && Class.class.cast(type).getPackage().equals(AbstractExchangeEvent.class.getPackage())) {
        Set<Annotation> qualifiers = pom.getObserverMethod().getObservedQualifiers();
        if (qualifiers.isEmpty()) {
            eventQualifiers.add(ANY);
        } else if (qualifiers.size() == 1 && qualifiers.stream()
            .filter(isAnnotationType(Named.class)).findAny().isPresent()) {
            eventQualifiers.add(DEFAULT);
        } else {
            eventQualifiers.addAll(qualifiers);
        }
    }
}
项目:Camel    文件:CdiEventConsumer.java   
void notify(T event) {
    logger.debug("Consuming CDI event [{}] with {}", event, this);

    Exchange exchange = getEndpoint().createExchange();
    // TODO: would that be possible to propagate the event metadata?
    exchange.getIn().setBody(event);

    // Avoid infinite loop of exchange events
    if (event instanceof AbstractExchangeEvent) {
        exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.TRUE);
    }
    try {
        getProcessor().process(exchange);
    } catch (Exception cause) {
        throw new RuntimeExchangeException("Error while processing CDI event", exchange, cause);
    } finally {
        if (event instanceof AbstractExchangeEvent) {
            exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.FALSE);
        }
    }
}
项目:camel-cdi    文件:CdiEventConsumer.java   
void notify(T event) {
    logger.debug("Consuming CDI event [{}] with {}", event, this);

    Exchange exchange = getEndpoint().createExchange();
    // TODO: propagate the event metadata
    exchange.getIn().setBody(event);

    // Avoid infinite loop of exchange events
    if (event instanceof AbstractExchangeEvent)
        exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.TRUE);

    try {
        getProcessor().process(exchange);
    } catch (Exception cause) {
        throw new RuntimeExchangeException("Error while processing CDI event", exchange, cause);
    } finally {
        if (event instanceof AbstractExchangeEvent)
            exchange.setProperty(Exchange.NOTIFY_EVENT, Boolean.FALSE);
    }
}
项目:Camel    文件:DefaultDebugger.java   
@Override
public void notify(EventObject event) throws Exception {
    AbstractExchangeEvent aee = (AbstractExchangeEvent) event;
    Exchange exchange = aee.getExchange();
    onEvent(exchange, event);

    if (event instanceof ExchangeCompletedEvent) {
        // fail safe to ensure we remove single steps when the Exchange is complete
        singleSteps.remove(exchange.getExchangeId());
    }
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private <T extends EventObject> void camelEventNotifiers(@Observes ProcessObserverMethod<T, ?> pom) {
    // Only activate Camel event notifiers for explicit Camel event observers, that is,
    // an observer method for a super type won't activate notifiers.
    Type type = pom.getObserverMethod().getObservedType();
    // Camel events are raw types
    if (type instanceof Class && Class.class.cast(type).getPackage().equals(AbstractExchangeEvent.class.getPackage())) {
        Set<Annotation> qualifiers = pom.getObserverMethod().getObservedQualifiers();
        if (qualifiers.isEmpty())
            eventQualifiers.add(ANY);
        else if (qualifiers.size() == 1 && qualifiers.stream().anyMatch(isAnnotationType(Named.class)))
            eventQualifiers.add(DEFAULT);
        else
            eventQualifiers.addAll(qualifiers);
    }
}
项目:springboot-camel-metrics-publisher    文件:CamelMetricsUpdater.java   
protected void onExchangeCompletedEvent(AbstractExchangeEvent event, String metricPrefix) {
    Period p = new Period(event.getExchange().getProperty(Exchange.CREATED_TIMESTAMP, Date.class).getTime(), System.currentTimeMillis());

    metrics.timer(name(event.getClass(), metricPrefix)).update(p.getMillis(), TimeUnit.MILLISECONDS);
}
项目:Camel    文件:DefaultDebugger.java   
@Override
public boolean isEnabled(EventObject event) {
    return event instanceof AbstractExchangeEvent;
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
private void onAnyExchangeEvent(@Observes AbstractExchangeEvent event, @Named("anyContext") List<Class> events) {
    events.add(event.getClass());
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
private void onDefaultExchangeEvent(@Observes @Default AbstractExchangeEvent event, List<Class> events) {
    events.add(event.getClass());
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
private void onFirstExchangeEvent(@Observes @ContextName("first") AbstractExchangeEvent event, @ContextName("first") List<Class> events) {
    events.add(event.getClass());
}
项目:Camel    文件:MultiContextEventNotifierTest.java   
private void onSecondExchangeEvent(@Observes @ContextName("second") AbstractExchangeEvent event, @ContextName("second") List<Class> events) {
    events.add(event.getClass());
}
项目:Camel    文件:CamelEventNotifierTest.java   
private void onExchangeEvent(@Observes AbstractExchangeEvent event, List<Class> events) {
    events.add(event.getClass());
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
private void onAnyExchangeEvent(@Observes AbstractExchangeEvent event, @Named("anyContext") List<Class> events) {
    events.add(event.getClass());
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
private void onDefaultExchangeEvent(@Observes @Default AbstractExchangeEvent event, @Named("defaultContext") List<Class> events) {
    events.add(event.getClass());
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
private void onFirstExchangeEvent(@Observes @ContextName("first") AbstractExchangeEvent event, @ContextName("first") List<Class> events) {
    events.add(event.getClass());
}
项目:camel-cdi    文件:MultiContextEventNotifierTest.java   
private void onSecondExchangeEvent(@Observes @ContextName("second") AbstractExchangeEvent event, @ContextName("second") List<Class> events) {
    events.add(event.getClass());
}
项目:camel-cdi    文件:CamelEventNotifierTest.java   
private void onExchangeEvent(@Observes AbstractExchangeEvent event, List<Class> events) {
    events.add(event.getClass());
}