Add Reactor autoconfiguration

* Make Rector @Autowirable
* Create a ConsumerBeanPostProcessor so users can add
@On and @Reply to bean methods
* Added groovy auto compiler and script sample

[#53955419] [bs-250]
pull/9/head
Dave Syer 11 years ago
parent a365b8c1b6
commit 683ddbf525

@ -22,6 +22,7 @@
<tomcat.version>7.0.42</tomcat.version> <tomcat.version>7.0.42</tomcat.version>
<jetty.version>8.1.9.v20130131</jetty.version> <jetty.version>8.1.9.v20130131</jetty.version>
<aspectj.version>1.7.3</aspectj.version> <aspectj.version>1.7.3</aspectj.version>
<reactor.version>1.0.0.M1</reactor.version>
</properties> </properties>
<scm> <scm>
<url>http://github.com/SpringSource/spring-bootstrap</url> <url>http://github.com/SpringSource/spring-bootstrap</url>
@ -432,6 +433,11 @@
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
<version>2.2.9</version> <version>2.2.9</version>
</dependency> </dependency>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>${reactor.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

@ -110,6 +110,11 @@
<artifactId>thymeleaf-extras-springsecurity3</artifactId> <artifactId>thymeleaf-extras-springsecurity3</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<optional>true</optional>
</dependency>
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>

@ -0,0 +1,57 @@
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.autoconfigure.reactor;
import org.springframework.autoconfigure.AutoConfigureAfter;
import org.springframework.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.bootstrap.context.condition.ConditionalOnClass;
import org.springframework.bootstrap.context.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.spring.context.ConsumerBeanPostProcessor;
/**
* @author Dave Syer
*/
@Configuration
@ConditionalOnClass(Reactor.class)
@ConditionalOnMissingBean(Reactor.class)
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
public class ReactorAutoConfiguration {
@Bean
public Environment reactorEnvironment() {
return new Environment(); // TODO: use Spring Environment to configure?
}
@Bean
public Reactor rootReactor() {
return reactorEnvironment().getRootReactor();
}
@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
protected ConsumerBeanPostProcessor reactorConsumerBeanPostProcessor() {
return new ConsumerBeanPostProcessor();
}
}

@ -7,6 +7,7 @@ org.springframework.autoconfigure.data.JpaRepositoriesAutoConfiguration,\
org.springframework.autoconfigure.jdbc.DataSourceAutoConfiguration,\ org.springframework.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\ org.springframework.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
org.springframework.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.autoconfigure.reactor.ReactorAutoConfiguration,\
org.springframework.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
org.springframework.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\ org.springframework.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\
org.springframework.autoconfigure.web.ServerPropertiesAutoConfiguration,\ org.springframework.autoconfigure.web.ServerPropertiesAutoConfiguration,\

@ -0,0 +1,41 @@
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.autoconfigure.reactor;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import reactor.core.Reactor;
import static org.junit.Assert.assertNotNull;
/**
* @author Dave Syer
*/
public class ReactorAutoConfigurationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
public void reactorIsAvailable() {
this.context.register(ReactorAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(Reactor.class));
this.context.close();
}
}

@ -0,0 +1,21 @@
package org.test
@EnableReactor
@Log
class Runner implements CommandLineRunner {
@Autowired
Reactor reactor
void run(String... args) {
reactor.notify("hello", Event.wrap("Phil"))
log.info "Notified Phil"
}
@On(reactor="reactor", selector="hello")
void receive(Event<String> event) {
log.info "Hello ${event.data}"
}
}

@ -0,0 +1,67 @@
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cli.compiler.autoconfigure;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.cli.compiler.AstUtils;
import org.springframework.cli.compiler.CompilerAutoConfiguration;
import org.springframework.cli.compiler.DependencyCustomizer;
/**
* {@link CompilerAutoConfiguration} for the Recator.
*
* @author Dave Syer
*/
public class ReactorCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableReactor");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
dependencies
.ifAnyMissingClasses("org.reactor.Reactor")
.add("org.projectreactor", "reactor-spring",
dependencies.getProperty("reactor.version"), false)
.add("org.projectreactor", "reactor-core",
dependencies.getProperty("reactor.version"));
}
@Override
public void applyImports(ImportCustomizer imports) {
imports.addImports("reactor.core.Reactor", "reactor.event.Event",
"reactor.spring.context.annotation.On",
"reactor.spring.context.annotation.Reply",
EnableReactor.class.getCanonicalName());
}
@Target(ElementType.TYPE)
@Documented
@Retention(RetentionPolicy.RUNTIME)
public static @interface EnableReactor {
}
}

@ -1,5 +1,6 @@
org.springframework.cli.compiler.autoconfigure.SpringCompilerAutoConfiguration org.springframework.cli.compiler.autoconfigure.SpringCompilerAutoConfiguration
org.springframework.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfiguration org.springframework.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfiguration
org.springframework.cli.compiler.autoconfigure.SpringBatchCompilerAutoConfiguration org.springframework.cli.compiler.autoconfigure.SpringBatchCompilerAutoConfiguration
org.springframework.cli.compiler.autoconfigure.ReactorCompilerAutoConfiguration
org.springframework.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration org.springframework.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration
org.springframework.cli.compiler.autoconfigure.SpringSecurityCompilerAutoConfiguration org.springframework.cli.compiler.autoconfigure.SpringSecurityCompilerAutoConfiguration

@ -6,3 +6,4 @@ spring.integration.version: ${spring.integration.version}
groovy.version: ${groovy.version} groovy.version: ${groovy.version}
jetty.version: ${jetty.version} jetty.version: ${jetty.version}
tomcat.version: ${tomcat.version} tomcat.version: ${tomcat.version}
reactor.version: ${reactor.version}

@ -117,6 +117,18 @@ public class SampleIntegrationTests {
output.contains("completed with the following parameters")); output.contains("completed with the following parameters"));
} }
@Test
public void reactorSample() throws Exception {
start("samples/reactor.groovy", "Phil");
String output = getOutput();
int count = 0;
while (!output.contains("Hello Phil") && count++ < 5) {
Thread.sleep(200);
output = getOutput();
}
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
}
@Test @Test
public void jobWebSample() throws Exception { public void jobWebSample() throws Exception {
start("samples/job.groovy", "samples/web.groovy", "foo=bar"); start("samples/job.groovy", "samples/web.groovy", "foo=bar");

@ -14,6 +14,6 @@
<appender-ref ref="CONSOLE" /> <appender-ref ref="CONSOLE" />
</root> </root>
<!-- logger name="org.springframework" level="DEBUG"/ --> <logger name="org.springframework" level="DEBUG"/>
</configuration> </configuration>

@ -26,6 +26,10 @@
<groupId>nz.net.ultraq.thymeleaf</groupId> <groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId> <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency> </dependency>
<!-- dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
</dependency-->
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

Loading…
Cancel
Save