@Override public void processModule(Module module, String group, int index) { String type = module.getType(); if (("source".equals(type) || "processor".equals(type) || "sink".equals(type)) && group != null) { this.registerChannels(module.getComponents(MessageChannel.class), group, index); this.configureProperties(module, group); } }
@Override public void preProcessModule(Module module) { assertEquals( "module commonContext should not contain any Plugins", 0, moduleCommonContext.getBeansOfType(Plugin.class).size()); Properties properties = new Properties(); properties.setProperty("xd.stream.name", module.getDeploymentMetadata().getGroup()); module.addProperties(properties); }
@Test public final void testRoutingWithSpel() throws InterruptedException { assertEquals(0, streamRepository.count()); final StreamDefinition routerDefinition = new StreamDefinition( "routerDefinition", "queue:routeit > router --expression=payload.contains('a')?'queue:foo':'queue:bar'"); streamDefinitionRepository.save(routerDefinition); streamDeployer.deploy("routerDefinition"); assertEquals(1, streamRepository.count()); assertModuleRequest("router", false); final Module module = getModule("router", 0, moduleDeployer); final MessageChannel inputChannel = module.getComponent("routeit", MessageChannel.class); assertNotNull(inputChannel); final MessageChannel outputChannelFoo = module.getComponent("queue:foo", MessageChannel.class); final MessageChannel outputChannelBar = module.getComponent("queue:bar", MessageChannel.class); assertNull(outputChannelFoo); assertNull(outputChannelBar); inputChannel.send(MessageBuilder.withPayload("a").build()); Thread.sleep(1000); final MessageChannel outputChannelFoo2 = module.getComponent("queue:foo", MessageChannel.class); final MessageChannel outputChannelBar2 = module.getComponent("queue:bar", MessageChannel.class); assertNotNull(outputChannelFoo2); assertNull(outputChannelBar2); inputChannel.send(MessageBuilder.withPayload("b").build()); Thread.sleep(1000); final QueueChannel outputChannelFoo3 = module.getComponent("queue:foo", QueueChannel.class); final QueueChannel outputChannelBar3 = module.getComponent("queue:bar", QueueChannel.class); assertNotNull(outputChannelFoo3); assertNotNull(outputChannelBar3); assertTrue(outputChannelFoo3.getQueueSize() == 1); assertTrue(outputChannelBar3.getQueueSize() == 1); final Message<?> fooMessage = outputChannelFoo3.receive(2000); final Message<?> barMessage = outputChannelBar3.receive(2000); assertEquals("a", fooMessage.getPayload()); assertEquals("b", barMessage.getPayload()); }
/* (non-Javadoc) * @see org.springframework.xd.module.Plugin#processModule(org.springframework.xd.module.Module) */ @Override public void processModule(Module module, String group, int index) { // TODO: Check if module started? Assert.notNull(module, "module cannot be null"); Assert.isAssignable(IntegrationModule.class, module.getClass()); String resourcePath = this.integrationModuleBasePath + "/" + module.getName() + ".xml"; module.addComponents(new ClassPathResource(resourcePath)); IntegrationModule integrationModule = (IntegrationModule) module; integrationModule.initializeModule(); channelRegistry.inbound( integrationModule.getName() + ".input", integrationModule.getInputChannel()); for (Entry<String, SubscribableChannel> entry : integrationModule.getOutputChannels().entrySet()) { channelRegistry.outbound( integrationModule.getName() + "." + entry.getKey(), entry.getValue()); } }
/** * Processes a new {@link Trigger} being added. Currently, it supports adding {@link * CronTrigger}s. The {@link Trigger} is added to the common {@link * ConfigurableApplicationContext}. */ @Override public void preProcessModule(Module module) { if (!TRIGGER.equals(module.getType())) { return; } Assert.notNull( commonApplicationContext, "The 'commonApplicationContext' property must not be null."); Map<String, Trigger> triggers = new HashMap<String, Trigger>(); if (module.getProperties().containsKey(TriggerType.cron.name())) { Trigger trigger = new CronTrigger(module.getProperties().getProperty(TriggerType.cron.name())); triggers.put(TriggerType.cron.name(), trigger); } if (module.getProperties().containsKey(TriggerType.fixedDelay.name())) { Trigger trigger = new PeriodicTrigger( Long.parseLong(module.getProperties().getProperty(TriggerType.fixedDelay.name()))); triggers.put(TriggerType.fixedDelay.name(), trigger); } if (module.getProperties().containsKey(TriggerType.fixedRate.name())) { PeriodicTrigger trigger = new PeriodicTrigger( Long.parseLong(module.getProperties().getProperty(TriggerType.fixedRate.name()))); trigger.setFixedRate(true); triggers.put(TriggerType.fixedRate.name(), trigger); } if (triggers.size() == 0) { throw new ResourceDefinitionException( "No valid trigger property. Expected one of: cron, fixedDelay or fixedRate"); } else if (triggers.size() > 1) { throw new ResourceDefinitionException( "Only one trigger property allowed, but received: " + StringUtils.collectionToCommaDelimitedString(triggers.keySet())); } commonApplicationContext .getBeanFactory() .registerSingleton(makeTriggerBeanName(module), triggers.values().iterator().next()); configureProperties(module); }
private void configureProperties(Module module) { Properties properties = new Properties(); properties.setProperty("xd.stream.name", module.getDeploymentMetadata().getGroup()); module.addProperties(properties); }
private String makeTriggerBeanName(Module module) { return BEAN_NAME_PREFIX + module.getDeploymentMetadata().getGroup(); }
private void configureProperties(Module module, String group) { Properties properties = new Properties(); properties.setProperty("xd.stream.name", group); module.addProperties(properties); }
@Override public void removeModule(Module module, String group, int index) { Assert.notNull(module, "module cannot be null"); Assert.isAssignable(IntegrationModule.class, module.getClass()); // TODO: }