/** * Gets the node id, creating one if not already set. */ public String idOrCreate(NodeIdFactory factory) { if (id == null) { id = factory.createId(this); } return getId(); }
@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(); } }; }
public NodeIdFactory getNodeIdFactory() { return nodeIdFactory; }
public void setNodeIdFactory(NodeIdFactory idFactory) { this.nodeIdFactory = idFactory; }
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); } }
@Override public void setNodeIdFactory(NodeIdFactory factory) { context.setNodeIdFactory(factory); }
@Override public NodeIdFactory getNodeIdFactory() { return context.getNodeIdFactory(); }
/** * Uses a custom node id factory when generating auto assigned ids to the nodes in the route definitions * * @param factory custom factory to use */ void setNodeIdFactory(NodeIdFactory factory);
/** * Gets the node id factory * * @return the node id factory */ NodeIdFactory getNodeIdFactory();