use of org.apache.camel.spi.NodeIdFactory in project fabric8 by jboss-fuse.
the class Tracer method forceAutoAssigningIds.
private void forceAutoAssigningIds() {
for (RouteContext routeContext : routeContexts) {
CamelContext camelContext = routeContext.getCamelContext();
NodeIdFactory factory = camelContext.getNodeIdFactory();
if (factory != null) {
for (ProcessorDefinition<?> child : processors) {
// ensure also the children get ids assigned
RouteDefinitionHelper.forceAssignIds(camelContext, child);
}
}
}
}
use of org.apache.camel.spi.NodeIdFactory in project camel by apache.
the class AbstractCamelContextFactoryBean method setupCustomServices.
private void setupCustomServices() {
ModelJAXBContextFactory modelJAXBContextFactory = getBeanForType(ModelJAXBContextFactory.class);
if (modelJAXBContextFactory != null) {
LOG.info("Using custom ModelJAXBContextFactory: {}", modelJAXBContextFactory);
getContext().setModelJAXBContextFactory(modelJAXBContextFactory);
}
ClassResolver classResolver = getBeanForType(ClassResolver.class);
if (classResolver != null) {
LOG.info("Using custom ClassResolver: {}", classResolver);
getContext().setClassResolver(classResolver);
}
FactoryFinderResolver factoryFinderResolver = getBeanForType(FactoryFinderResolver.class);
if (factoryFinderResolver != null) {
LOG.info("Using custom FactoryFinderResolver: {}", factoryFinderResolver);
getContext().setFactoryFinderResolver(factoryFinderResolver);
}
ExecutorServiceManager executorServiceStrategy = getBeanForType(ExecutorServiceManager.class);
if (executorServiceStrategy != null) {
LOG.info("Using custom ExecutorServiceStrategy: {}", executorServiceStrategy);
getContext().setExecutorServiceManager(executorServiceStrategy);
}
ThreadPoolFactory threadPoolFactory = getBeanForType(ThreadPoolFactory.class);
if (threadPoolFactory != null) {
LOG.info("Using custom ThreadPoolFactory: {}", threadPoolFactory);
getContext().getExecutorServiceManager().setThreadPoolFactory(threadPoolFactory);
}
ProcessorFactory processorFactory = getBeanForType(ProcessorFactory.class);
if (processorFactory != null) {
LOG.info("Using custom ProcessorFactory: {}", processorFactory);
getContext().setProcessorFactory(processorFactory);
}
Debugger debugger = getBeanForType(Debugger.class);
if (debugger != null) {
LOG.info("Using custom Debugger: {}", debugger);
getContext().setDebugger(debugger);
}
UuidGenerator uuidGenerator = getBeanForType(UuidGenerator.class);
if (uuidGenerator != null) {
LOG.info("Using custom UuidGenerator: {}", uuidGenerator);
getContext().setUuidGenerator(uuidGenerator);
}
NodeIdFactory nodeIdFactory = getBeanForType(NodeIdFactory.class);
if (nodeIdFactory != null) {
LOG.info("Using custom NodeIdFactory: {}", nodeIdFactory);
getContext().setNodeIdFactory(nodeIdFactory);
}
StreamCachingStrategy streamCachingStrategy = getBeanForType(StreamCachingStrategy.class);
if (streamCachingStrategy != null) {
LOG.info("Using custom StreamCachingStrategy: {}", streamCachingStrategy);
getContext().setStreamCachingStrategy(streamCachingStrategy);
}
MessageHistoryFactory messageHistoryFactory = getBeanForType(MessageHistoryFactory.class);
if (messageHistoryFactory != null) {
LOG.info("Using custom MessageHistoryFactory: {}", messageHistoryFactory);
getContext().setMessageHistoryFactory(messageHistoryFactory);
}
}
use of org.apache.camel.spi.NodeIdFactory in project camel by apache.
the class CustomIdFactoryTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// use our own id factory so we can generate the keys we like to use
context.setNodeIdFactory(new NodeIdFactory() {
public String createId(NamedNode definition) {
return "#" + definition.getShortName() + ++counter + "#";
}
});
// add our debugger so we can debug camel routes when we send in messages
context.addInterceptStrategy(new MyDebuggerCheckingId());
// a little content based router so we got 2 paths to route at runtime
from("direct:start").choice().when(body().contains("Hello")).to("mock:hello").otherwise().log("Hey").to("mock:other").end();
}
};
}
use of org.apache.camel.spi.NodeIdFactory in project fabric8 by jboss-fuse.
the class CamelAutoTestService method onConfigured.
@Override
protected void onConfigured() throws Exception {
LOG.debug("onConfigured. mockOutputs: " + mockOutputs + " mockInputs: " + mockInputs + " messageFolder: " + messageFolder);
FabricService fabricService = this.fabricService.getOptional();
// lets find the camel contexts to test in this container
MBeanServer mbeanServerValue = mbeanServer;
if (mbeanServerValue != null && fabricService != null) {
Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
Set<String> configurationFileNames = effectiveProfile.getConfigurationFileNames();
for (CamelContext camelContext : camelContexts.values()) {
String camelContextID = camelContext.getName();
// check we only add testing stuff to each context once
if (camelContext instanceof ModelCamelContext) {
final ModelCamelContext modelCamelContext = (ModelCamelContext) camelContext;
List<RouteDefinition> routeDefinitions = modelCamelContext.getRouteDefinitions();
if (camelContextsConfigured.add(camelContextID)) {
NodeIdFactory nodeIdFactory = camelContext.getNodeIdFactory();
if (mockInputs || mockOutputs) {
for (RouteDefinition routeDefinition : routeDefinitions) {
String routeId = routeDefinition.idOrCreate(nodeIdFactory);
modelCamelContext.stopRoute(routeId);
final String routeKey = camelContextID + "." + routeId;
LOG.info("Mocking Camel route: " + routeKey);
routeDefinition.adviceWith(modelCamelContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
if (mockOutputs) {
modelCamelContext.addRegisterEndpointCallback(strategy);
}
}
});
// the advised route is automatic restarted
}
}
String path = messageFolder;
if (Strings.isNotBlank(path)) {
path += "/";
}
path += camelContextID;
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
try {
for (RouteDefinition routeDefinition : routeDefinitions) {
String routeId = routeDefinition.idOrCreate(nodeIdFactory);
String routePath = path + "/" + routeId + "/";
List<FromDefinition> inputs = routeDefinition.getInputs();
for (FromDefinition input : inputs) {
Endpoint endpoint = input.getEndpoint();
if (endpoint == null) {
String uri = input.getUri();
if (Strings.isNullOrBlank(uri)) {
String ref = input.getRef();
if (Strings.isNotBlank(ref)) {
uri = "ref:" + ref;
}
}
if (Strings.isNotBlank(uri)) {
endpoint = camelContext.getEndpoint(uri);
}
}
if (endpoint == null) {
LOG.warn("Cannot find endpoint, uri or ref of input " + input + " on route " + routeId + " camelContext: " + camelContextID);
} else {
for (String configFile : configurationFileNames) {
if (configFile.startsWith(routePath)) {
LOG.info("Sending file: " + configFile + " to " + endpoint);
byte[] data = effectiveProfile.getFileConfiguration(configFile);
if (data != null) {
// lest send this message to this endpoint
producerTemplate.sendBody(endpoint, data);
}
}
}
}
}
}
} finally {
producerTemplate.stop();
}
}
}
}
}
}
Aggregations