@Override public void afterProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition, long timeTaken) { CamelTestSupport.this.debugAfter(exchange, processor, definition, definition.getId(), definition.getLabel(), timeTaken); } }
@Override public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) { CamelTestSupport.this.debugBefore(exchange, processor, definition, definition.getId(), definition.getLabel()); }
@Override public boolean process(final Exchange exchange, final AsyncCallback callback) { LOG.debug("Setting current processor defintion '" + definition.getId() + "'"); exchange.setProperty(CURRENT_PROCESSOR_DEFINITION, definition); return processor.process(exchange, callback); } };
public ObjectName getObjectNameForProcessor(CamelContext context, Processor processor, ProcessorDefinition<?> definition) throws MalformedObjectNameException { StringBuilder buffer = new StringBuilder(); buffer.append(domainName).append(":"); buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(","); buffer.append(KEY_TYPE + "=").append(TYPE_PROCESSOR).append(","); RouteDefinition route = ProcessorDefinitionHelper.getRoute(definition); if (route != null) { buffer.append(KEY_ROUTE + "=").append(route.getId()).append(","); } buffer.append(KEY_NAME + "=").append(ObjectName.quote(definition.getId())); return createObjectName(buffer); }
/** * Return a TID managed by this handler, creating if necessary. * * @param exchange - the exchange this tid is used in. * @return The TID managed by this handler. * @throws Exception * Thrown if unable to return TID. */ protected String getTID(Exchange exchange) throws Exception { ProcessorDefinition<?> definition = exchange.getProperty(CurrentProcessorDefinitionInterceptStrategy.CURRENT_PROCESSOR_DEFINITION, ProcessorDefinition.class); if (definition == null) { LOG.warn("Current processor definition not found in exchange: please install org.fusesource.camel.component.sap.CurrentProcessorDefinitionInterceptStrategy into Camel container"); return destination.createTID(); } String tid = tidMap.get(definition.getId()); if (tid == null) { tid = destination.createTID(); tidMap.put(definition.getId(), tid); } return tid; }
protected void appendStats(StringBuilder sb, ProcessorDefinition<?> definition) { Stats stats = statistics.get(definition); if (stats != null) { sb.append("<processor"); if (definition.getId() != null) { sb.append(" id=\"").append(definition.getId()).append("\""); } sb.append(" definition=\"").append(StringHelper.xmlEncode(definition.toString())).append("\""); if (definition.getLabel() != null) { sb.append(" label=\"").append(definition.getLabel()).append("\""); } sb.append(" count=\"").append(stats.getCount()).append("\""); sb.append(" self=\"").append(stats.getSelf()).append("\""); sb.append(" total=\"").append(stats.getTotal()).append("\""); sb.append(">"); for (ProcessorDefinition<?> child : statistics.keySet()) { if (child.getParent() == definition) { appendStats(sb, child); } } sb.append("</processor>"); } }
protected void appendStats(StringBuilder sb, ProcessorDefinition<?> definition) { Stats stats = statistics.get(definition); if (stats != null) { sb.append("<processor"); if (definition.getId() != null) { sb.append(" id=\"").append(definition.getId()).append("\""); } sb.append(" definition=\"").append(StringHelper.xmlEncode(definition.toString())).append("\""); if (definition.getLabel() != null) { sb.append(" label=\"").append(definition.getLabel()).append("\""); } sb.append(" count=\"").append(stats.getCount()).append("\""); sb.append(" self=\"").append(stats.getSelf()).append("\""); sb.append(" total=\"").append(stats.getTotal()).append("\""); sb.append(">"); for (ProcessorDefinition<?> child : statistics.keySet()) { if (child.getParent() == definition) { appendStats(sb, child); } } sb.append("</processor>"); } }
private void configureCamelContext(@Observes AfterDeploymentValidation adv, BeanManager manager) throws Exception { CamelContext context = manager.createInstance().select(CamelContext.class).get(); context.addInterceptStrategy((camel, definition, target, next) -> definition.hasCustomIdAssigned() ? nodePointcuts.stream().filter(node -> definition.getId().equals(node.value())).findFirst() .map(node -> (Processor) new DelegateAsyncProcessor(target) { public boolean process(Exchange exchange, AsyncCallback callback) { manager.fireEvent(exchange, node); return super.process(exchange, callback); } }).orElse(target) : target); manager.createInstance().select(RoutesBuilder.class).forEach(rethrow(context::addRoutes)); context.start(); } }
String toNode = processorDefinition.getId(); String exchangeId = exchange.getExchangeId(); String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn()); String routeId = routeDefinition.getId(); TracerEventMessage pseudo = new TracerEventMessage(tracer.incrementTraceCounter(), created, routeId, exchangeId, messageAsXml); queue.add(pseudo);
@Override public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception { if (this.tracker == null) { return target; } if (definition instanceof PipelineDefinition) { final String id = definition.getId(); if (ObjectHelper.isEmpty(id)) { return target; } final String stepId = StringHelper.after(id, "step:"); if (ObjectHelper.isEmpty(stepId)) { return target; } return new EventProcessor(target); } return target; }
String toNode = processorDefinition.getId(); String exchangeId = exchange.getExchangeId(); String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn()); String routeId = routeDefinition.getId(); TracerEventMessage pseudo = new TracerEventMessage(tracer.incrementTraceCounter(), created, routeId, exchangeId, messageAsXml); queue.add(pseudo);
@SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidCatchingGenericException"}) @Override public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception { if (!definition.hasCustomIdAssigned()) { // skip over processors with a generated id return target; } return exchange -> { String id = KeyGenerator.createKey(); long startedAt = System.nanoTime(); try { target.process(exchange); } catch (RuntimeException e) { exchange.setException(e); } finally { // currentTimeMillis is not monotonic, nanoTime likely is long duration = System.nanoTime() - startedAt; System.out.println(toJsonObject( "exchange", exchange.getExchangeId(), "step", definition.getId(), "id", id, "duration", duration, "failure", failure(exchange))); } }; }
@Override public Processor wrapProcessorInInterceptors(CamelContext context, ProcessorDefinition<?> definition, Processor target, Processor nextTarget) throws Exception { // First processor needs to handle the in message as the out message from the consumer since // we can't intercept consumers FromDefinition from = getFromDefinition(definition); boolean captureIn = from!=null; boolean captureOut = definition.hasCustomIdAssigned(); if (captureIn || captureOut) { return AsyncProcessorConverterHelper.convert(exchange -> { if( captureIn ) { addToMap(exchange, from.getId(), exchange.getIn()); } target.process(exchange); if( captureOut ) { Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn(); addToMap(exchange, definition.getId(), message); } }); } else { // skip over processors with a generated id return target; } }