use of org.apache.camel.Route in project camel by apache.
the class CamelJob method lookupQuartzEndpoint.
protected QuartzEndpoint lookupQuartzEndpoint(CamelContext camelContext, JobExecutionContext quartzContext) throws JobExecutionException {
TriggerKey triggerKey = quartzContext.getTrigger().getKey();
JobDetail jobDetail = quartzContext.getJobDetail();
JobKey jobKey = jobDetail.getKey();
if (LOG.isDebugEnabled()) {
LOG.debug("Looking up existing QuartzEndpoint with triggerKey={}", triggerKey);
}
// as we prefer to use the existing endpoint from the routes
for (Route route : camelContext.getRoutes()) {
Endpoint endpoint = route.getEndpoint();
if (endpoint instanceof DelegateEndpoint) {
endpoint = ((DelegateEndpoint) endpoint).getEndpoint();
}
if (endpoint instanceof QuartzEndpoint) {
QuartzEndpoint quartzEndpoint = (QuartzEndpoint) endpoint;
TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey();
if (LOG.isTraceEnabled()) {
LOG.trace("Checking route endpoint={} with checkTriggerKey={}", quartzEndpoint, checkTriggerKey);
}
if (triggerKey.equals(checkTriggerKey) || (jobDetail.requestsRecovery() && jobKey.getGroup().equals(checkTriggerKey.getGroup()) && jobKey.getName().equals(checkTriggerKey.getName()))) {
return quartzEndpoint;
}
}
}
// fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
String endpointUri = quartzContext.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_ENDPOINT_URI);
QuartzEndpoint result = null;
// Even though the same camelContext.getEndpoint call, but if/else display different log.
if (camelContext.hasEndpoint(endpointUri) != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Getting Endpoint from camelContext.");
}
result = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
} else if ((result = searchForEndpointMatch(camelContext, endpointUri)) != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found match for endpoint URI = " + endpointUri + " by searching endpoint list.");
}
} else {
LOG.warn("Cannot find existing QuartzEndpoint with uri: {}. Creating new endpoint instance.", endpointUri);
result = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
}
if (result == null) {
throw new JobExecutionException("No QuartzEndpoint could be found with endpointUri: " + endpointUri);
}
return result;
}
use of org.apache.camel.Route in project camel by apache.
the class QuartzEndpoint method ensureNoDupTriggerKey.
private void ensureNoDupTriggerKey() {
for (Route route : getCamelContext().getRoutes()) {
if (route.getEndpoint() instanceof QuartzEndpoint) {
QuartzEndpoint quartzEndpoint = (QuartzEndpoint) route.getEndpoint();
TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey();
if (triggerKey.equals(checkTriggerKey)) {
throw new IllegalArgumentException("Trigger key " + triggerKey + " is already in use by " + quartzEndpoint);
}
}
}
}
use of org.apache.camel.Route in project camel by apache.
the class QuartzScheduledPollConsumerJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
LOG.trace("Execute job: {}", context);
CamelContext camelContext = getCamelContext(context);
Runnable task = (Runnable) context.getJobDetail().getJobDataMap().get("task");
if (task == null) {
// if not task then use the route id to lookup the consumer to be used as the task
String routeId = (String) context.getJobDetail().getJobDataMap().get("routeId");
if (routeId != null && camelContext != null) {
// find the consumer
for (Route route : camelContext.getRoutes()) {
if (route.getId().equals(routeId)) {
Consumer consumer = route.getConsumer();
if (consumer instanceof Runnable) {
task = (Runnable) consumer;
break;
}
}
}
}
}
if (task != null) {
LOG.trace("Running task: {}", task);
task.run();
}
}
use of org.apache.camel.Route in project camel by apache.
the class CamelAutoConfigurationTest method shouldDetectRoutes.
@Test
public void shouldDetectRoutes() {
// When
Route route = camelContext.getRoute(TestConfig.ROUTE_ID);
// Then
assertNotNull(route);
}
use of org.apache.camel.Route in project camel by apache.
the class EtcdRoutePolicy method startAllStoppedConsumers.
private void startAllStoppedConsumers() {
synchronized (lock) {
try {
for (Route route : suspendedRoutes) {
LOGGER.debug("Starting consumer for {} ({})", route.getId(), route.getConsumer());
startConsumer(route.getConsumer());
}
suspendedRoutes.clear();
} catch (Exception e) {
handleException(e);
}
}
}
Aggregations