use of org.apache.camel.impl.InterceptSendToEndpoint in project camel by apache.
the class MockEndpoint method assertIsSatisfied.
/**
* Asserts that all the expectations on any {@link MockEndpoint} instances registered
* in the given context are valid
*
* @param context the camel context used to find all the available endpoints to be asserted
* @param timeout timeout
* @param unit time unit
*/
public static void assertIsSatisfied(CamelContext context, long timeout, TimeUnit unit) throws InterruptedException {
ObjectHelper.notNull(context, "camelContext");
ObjectHelper.notNull(unit, "unit");
Collection<Endpoint> endpoints = context.getEndpoints();
long millis = unit.toMillis(timeout);
for (Endpoint endpoint : endpoints) {
// if the endpoint was intercepted we should get the delegate
if (endpoint instanceof InterceptSendToEndpoint) {
endpoint = ((InterceptSendToEndpoint) endpoint).getDelegate();
}
if (endpoint instanceof MockEndpoint) {
MockEndpoint mockEndpoint = (MockEndpoint) endpoint;
mockEndpoint.setResultWaitTime(millis);
mockEndpoint.assertIsSatisfied();
}
}
}
use of org.apache.camel.impl.InterceptSendToEndpoint in project camel by apache.
the class InterceptSendToEndpointDefinition method createProcessor.
@Override
public Processor createProcessor(final RouteContext routeContext) throws Exception {
// create the detour
final Processor detour = this.createChildProcessor(routeContext, true);
final String matchURI = getUri();
// register endpoint callback so we can proxy the endpoint
routeContext.getCamelContext().addRegisterEndpointCallback(new EndpointStrategy() {
public Endpoint registerEndpoint(String uri, Endpoint endpoint) {
if (endpoint instanceof InterceptSendToEndpoint) {
// endpoint already decorated
return endpoint;
} else if (matchURI == null || matchPattern(routeContext.getCamelContext(), uri, matchURI)) {
// only proxy if the uri is matched decorate endpoint with our proxy
// should be false by default
boolean skip = getSkipSendToOriginalEndpoint() != null && getSkipSendToOriginalEndpoint();
InterceptSendToEndpoint proxy = new InterceptSendToEndpoint(endpoint, skip);
proxy.setDetour(detour);
return proxy;
} else {
// no proxy so return regular endpoint
return endpoint;
}
}
});
// remove the original intercepted route from the outputs as we do not intercept as the regular interceptor
// instead we use the proxy endpoints producer do the triggering. That is we trigger when someone sends
// an exchange to the endpoint, see InterceptSendToEndpoint for details.
RouteDefinition route = routeContext.getRoute();
List<ProcessorDefinition<?>> outputs = route.getOutputs();
outputs.remove(this);
return new InterceptEndpointProcessor(matchURI, detour);
}
use of org.apache.camel.impl.InterceptSendToEndpoint in project camel by apache.
the class SendProcessor method doStart.
protected void doStart() throws Exception {
if (producerCache == null) {
// use a single producer cache as we need to only hold reference for one destination
// and use a regular HashMap as we do not want a soft reference store that may get re-claimed when low on memory
// as we want to ensure the producer is kept around, to ensure its lifecycle is fully managed,
// eg stopping the producer when we stop etc.
producerCache = new ProducerCache(this, camelContext, new HashMap<String, Producer>(1));
// do not add as service as we do not want to manage the producer cache
}
ServiceHelper.startService(producerCache);
// the destination could since have been intercepted by a interceptSendToEndpoint so we got to
// lookup this before we can use the destination
Endpoint lookup = camelContext.hasEndpoint(destination.getEndpointKey());
if (lookup instanceof InterceptSendToEndpoint) {
if (LOG.isDebugEnabled()) {
LOG.debug("Intercepted sending to {} -> {}", URISupport.sanitizeUri(destination.getEndpointUri()), URISupport.sanitizeUri(lookup.getEndpointUri()));
}
destination = lookup;
}
// warm up the producer by starting it so we can fail fast if there was a problem
// however must start endpoint first
ServiceHelper.startService(destination);
// this SendProcessor is used a lot in Camel (eg every .to in the route DSL) and therefore we
// want to optimize for regular producers, by using the producer directly instead of the ProducerCache
// Only for pooled and non singleton producers we have to use the ProducerCache as it supports these
// kind of producer better (though these kind of producer should be rare)
Producer producer = producerCache.acquireProducer(destination);
if (producer instanceof ServicePoolAware || !producer.isSingleton()) {
// no we cannot optimize it - so release the producer back to the producer cache
// and use the producer cache for sending
producerCache.releaseProducer(destination, producer);
} else {
// yes we can optimize and use the producer directly for sending
this.producer = AsyncProcessorConverterHelper.convert(producer);
}
}
use of org.apache.camel.impl.InterceptSendToEndpoint in project camel by apache.
the class MockEndpoint method setAssertPeriod.
/**
* Sets the assert period on all the expectations on any {@link MockEndpoint} instances registered
* in the given context.
*
* @param context the camel context used to find all the available endpoints
* @param period the period in millis
*/
public static void setAssertPeriod(CamelContext context, long period) {
ObjectHelper.notNull(context, "camelContext");
Collection<Endpoint> endpoints = context.getEndpoints();
for (Endpoint endpoint : endpoints) {
// if the endpoint was intercepted we should get the delegate
if (endpoint instanceof InterceptSendToEndpoint) {
endpoint = ((InterceptSendToEndpoint) endpoint).getDelegate();
}
if (endpoint instanceof MockEndpoint) {
MockEndpoint mockEndpoint = (MockEndpoint) endpoint;
mockEndpoint.setAssertPeriod(period);
}
}
}
use of org.apache.camel.impl.InterceptSendToEndpoint in project camel by apache.
the class MockEndpoint method assertIsSatisfied.
/**
* Asserts that all the expectations on any {@link MockEndpoint} instances registered
* in the given context are valid
*
* @param context the camel context used to find all the available endpoints to be asserted
*/
public static void assertIsSatisfied(CamelContext context) throws InterruptedException {
ObjectHelper.notNull(context, "camelContext");
Collection<Endpoint> endpoints = context.getEndpoints();
for (Endpoint endpoint : endpoints) {
// if the endpoint was intercepted we should get the delegate
if (endpoint instanceof InterceptSendToEndpoint) {
endpoint = ((InterceptSendToEndpoint) endpoint).getDelegate();
}
if (endpoint instanceof MockEndpoint) {
MockEndpoint mockEndpoint = (MockEndpoint) endpoint;
mockEndpoint.assertIsSatisfied();
}
}
}
Aggregations