use of org.apache.camel.spi.SynchronizationRouteAware in project camel by apache.
the class UnitOfWorkHelper method afterRouteSynchronizations.
public static void afterRouteSynchronizations(Route route, Exchange exchange, List<Synchronization> synchronizations, Logger log) {
if (synchronizations != null && !synchronizations.isEmpty()) {
// work on a copy of the list to avoid any modification which may cause ConcurrentModificationException
List<Synchronization> copy = new ArrayList<Synchronization>(synchronizations);
// reverse so we invoke it FILO style instead of FIFO
Collections.reverse(copy);
// and honor if any was ordered by sorting it accordingly
copy.sort(new OrderedComparator());
// invoke synchronization callbacks
for (Synchronization synchronization : copy) {
if (synchronization instanceof SynchronizationRouteAware) {
try {
log.trace("Invoking synchronization.onAfterRoute: {} with {}", synchronization, exchange);
((SynchronizationRouteAware) synchronization).onAfterRoute(route, exchange);
} catch (Throwable e) {
// must catch exceptions to ensure all synchronizations have a chance to run
log.warn("Exception occurred during onAfterRoute. This exception will be ignored.", e);
}
}
}
}
}
use of org.apache.camel.spi.SynchronizationRouteAware in project camel by apache.
the class UnitOfWorkHelper method beforeRouteSynchronizations.
public static void beforeRouteSynchronizations(Route route, Exchange exchange, List<Synchronization> synchronizations, Logger log) {
if (synchronizations != null && !synchronizations.isEmpty()) {
// work on a copy of the list to avoid any modification which may cause ConcurrentModificationException
List<Synchronization> copy = new ArrayList<Synchronization>(synchronizations);
// reverse so we invoke it FILO style instead of FIFO
Collections.reverse(copy);
// and honor if any was ordered by sorting it accordingly
copy.sort(new OrderedComparator());
// invoke synchronization callbacks
for (Synchronization synchronization : copy) {
if (synchronization instanceof SynchronizationRouteAware) {
try {
log.trace("Invoking synchronization.onBeforeRoute: {} with {}", synchronization, exchange);
((SynchronizationRouteAware) synchronization).onBeforeRoute(route, exchange);
} catch (Throwable e) {
// must catch exceptions to ensure all synchronizations have a chance to run
log.warn("Exception occurred during onBeforeRoute. This exception will be ignored.", e);
}
}
}
}
}
Aggregations