Skip to content

Commit 7ef34c7

Browse files
committed
Merge pull request aol#170 from aol/cyclops-react
Cyclops react
2 parents a56c243 + 4bfc4e4 commit 7ef34c7

File tree

52 files changed

+975
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+975
-681
lines changed

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
version=0.81
1+
version=0.82
22
springVersion=4.2.5.RELEASE
33
springBootVersion=1.3.3.RELEASE
44
jerseyVersion=2.22.2
55
grizzlyVersion=2.3.24
6-
cyclopsReactVersion=1.0.0-RC1
6+
cyclopsReactVersion=1.0.0-RC2.2
77
hamcrestVersion=1.3
88
jacksonVersion=2.6.3
99
hibernateVersion=5.0.5.Final

micro-application-register/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ dependencies {
33

44
compile 'org.apache.commons:commons-io:1.3.2'
55
compile project(':micro-core')
6-
compile project(':micro-reactive')
76
compile project(':micro-client')
87
compile project(':micro-ip-tracker')
98
testCompile project(':micro-grizzly-with-jersey')

micro-application-register/src/main/java/com/aol/micro/server/application/registry/ServiceRegistryResource.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.aol.micro.server.application.registry;
22

33
import java.util.Arrays;
4-
import java.util.Map;
54

65
import javax.ws.rs.Consumes;
76
import javax.ws.rs.GET;
@@ -15,14 +14,15 @@
1514
import org.slf4j.LoggerFactory;
1615
import org.springframework.beans.factory.annotation.Autowired;
1716

17+
import com.aol.cyclops.control.ReactiveSeq;
18+
import com.aol.micro.server.WorkerThreads;
1819
import com.aol.micro.server.auto.discovery.Rest;
19-
import com.aol.micro.server.reactive.Reactive;
2020
import com.aol.micro.server.utility.HashMapBuilder;
2121

2222

2323
@Rest
2424
@Path("/service-registry")
25-
public class ServiceRegistryResource implements Reactive{
25+
public class ServiceRegistryResource{
2626
private final Logger logger = LoggerFactory.getLogger(getClass());
2727
private final Cleaner cleaner;
2828
private final Finder finder;
@@ -42,7 +42,9 @@ public ServiceRegistryResource(Cleaner cleaner, Finder finder, Register register
4242
@Path("/list")
4343
@Produces("application/json")
4444
public void list(@Suspended AsyncResponse response) {
45-
this.ioStreamBuilder().of(this).forEach(next -> {
45+
ReactiveSeq.of(this)
46+
.futureOperations(WorkerThreads.ioExecutor.get())
47+
.forEach(next -> {
4648
try{
4749
cleaner.clean();
4850
response.resume(finder.find());
@@ -59,7 +61,9 @@ public void list(@Suspended AsyncResponse response) {
5961
@Consumes("application/json")
6062
@Produces("application/json")
6163
public void schedule(@Suspended AsyncResponse response) {
62-
this.ioStreamBuilder().of(this).forEach(next -> {
64+
ReactiveSeq.of(this)
65+
.futureOperations(WorkerThreads.ioExecutor.get())
66+
.forEach(next -> {
6367
try{
6468
job.schedule();
6569
response.resume(HashMapBuilder.of("status", "success"));
@@ -76,7 +80,9 @@ public void schedule(@Suspended AsyncResponse response) {
7680
@Consumes("application/json")
7781
@Produces("application/json")
7882
public void register(@Suspended AsyncResponse response,RegisterEntry entry) {
79-
this.ioStreamBuilder().of(this).forEach(next -> {
83+
ReactiveSeq.of(this)
84+
.futureOperations(WorkerThreads.ioExecutor.get())
85+
.forEach(next -> {
8086
try{
8187
register.register(entry);
8288
response.resume(HashMapBuilder.of("status", "complete"));

micro-boot/src/test/java/app/boot/com/aol/micro/server/AsyncResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void expensive(@Suspended AsyncResponse asyncResponse){
3838
.onFail(it -> "")
3939
.peek(it ->
4040
System.out.println(it))
41-
.<String,Boolean>allOf(data -> {
41+
.allOf(data -> {
4242
System.out.println(data);
4343
return asyncResponse.resume(String.join(";", (List<String>)data)); });
4444

micro-boot/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class GuavaAppTest {
4040

4141
@Before
4242
public void startServer() {
43-
stream = simpleReact.react(
43+
stream = simpleReact.ofAsync(
4444
() -> server = new MicroserverApp(GuavaAppTest.class,
4545
() -> "guava-app")).then(server -> server.start());
4646

micro-client/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies {
1010
compile project(':micro-jackson-configuration')
1111
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:hamcrestVersion
1212
testCompile group: 'com.google.guava', name: 'guava', version:guavaVersion
13-
testCompile project(':micro-reactive')
1413
testCompile project(':micro-grizzly')
1514
testCompile project(':micro-jersey')
1615
testCompile project(':micro-events')

micro-client/src/test/java/app/async/com/aol/micro/server/AsyncResource.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
import org.springframework.stereotype.Component;
1414

15+
import com.aol.cyclops.control.LazyReact;
1516
import com.aol.micro.server.auto.discovery.RestResource;
16-
import com.aol.micro.server.reactive.Reactive;
1717
import com.aol.micro.server.rest.client.nio.AsyncRestClient;
1818

1919
@Path("/async")
2020
@Component
21-
public class AsyncResource implements RestResource,Reactive{
21+
public class AsyncResource implements RestResource{
2222

2323

2424
private final List<String> urls =Arrays.asList("http://localhost:8080/async-app/async/ping2",
@@ -33,13 +33,13 @@ public class AsyncResource implements RestResource,Reactive{
3333
@Produces("text/plain")
3434
public void expensive(@Suspended AsyncResponse asyncResponse){
3535

36-
this.ioStreamBuilder().fromStream(urls.stream()
36+
new LazyReact().fromStreamFutures(urls.stream()
3737
.<CompletableFuture<String>>map(it -> client.get(it)))
3838
.onFail(it -> "")
3939
.peek(it ->
4040
System.out.println(it))
4141
.convertToSimpleReact()
42-
.<String,Boolean>allOf(data -> {
42+
.allOf(data -> {
4343
System.out.println(data);
4444
return asyncResponse.resume(String.join(";", (List<String>)data)); })
4545
.convertToLazyStream().run();

micro-core/src/main/java/com/aol/micro/server/MicroserverApp.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ private ServerApplication createServer(Module module) {
137137
.flatMap(StreamUtils::optionalToStream)
138138
.toList();
139139
if(applications.size()>1){
140-
logger.error("ERROR! Multiple server application factories found ",applications);
141-
System.err.println("ERROR! Multiple server application factories found "+applications);
142-
throw new IncorrectNumberOfServersConfiguredException("Multiple server application factories found "+applications);
140+
logger.error("ERROR! Multiple server application factories found : The solution is remove one these plugins from your classpath ",applications);
141+
System.err.println("ERROR! Multiple server application factories found : The solution is remove one these plugins from your classpath "+applications);
142+
throw new IncorrectNumberOfServersConfiguredException("Multiple server application factories found : The solution is remove one these plugins from your classpath "+applications);
143143
}else if(applications.size()==0){
144-
logger.error("ERROR! No server application factories found.");
145-
System.err.println("ERROR! No server application factories found.");
146-
throw new IncorrectNumberOfServersConfiguredException("No server application factories found. ");
144+
logger.error("ERROR! No server application factories found. A possible solution is add one of micro-grizzly or micro-tomcat to the classpath.");
145+
System.err.println("ERROR! No server application factories found. A possible solution is add one of micro-grizzly or micro-tomcat to the classpath.");
146+
throw new IncorrectNumberOfServersConfiguredException("No server application factories found. A possible solution is add one of micro-grizzly or micro-tomcat to the classpath. ");
147147

148148
}
149149

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.aol.micro.server;
2+
3+
import java.util.concurrent.Executor;
4+
import java.util.concurrent.Executors;
5+
import java.util.function.Supplier;
6+
7+
import com.aol.cyclops.control.FluentFunctions;
8+
9+
public class WorkerThreads {
10+
11+
public final static Supplier<Executor> ioExecutor = FluentFunctions.of(WorkerThreads::ioWorkers)
12+
.memoize();
13+
private static Executor ioWorkers(){
14+
return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2);
15+
}
16+
}

micro-core/src/main/java/com/aol/micro/server/module/Module.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ default String getJaxWsRsApplication(){
136136
.flatMap(StreamUtils::optionalToStream)
137137
.toList();
138138
if(jaxRsApplications.size()>1) {
139-
throw new IncorrectJaxRsPluginsException("ERROR! Multiple jax-rs application plugins found " + jaxRsApplications);
139+
throw new IncorrectJaxRsPluginsException("ERROR! Multiple jax-rs application plugins found, a possible solution is to remove micro-jackson or other jax-rs application provider from your classpath. " + jaxRsApplications);
140140

141141

142142
}else if(jaxRsApplications.size()==0){
143-
throw new IncorrectJaxRsPluginsException("ERROR! No jax-rs application plugins found ");
143+
throw new IncorrectJaxRsPluginsException("ERROR! No jax-rs application plugins found, a possible solution is to add micro-jackson to your classpath. ");
144144

145145

146146
}

micro-events/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
description = 'micro-events'
22
dependencies {
33
compile project(':micro-core')
4-
compile project(':micro-reactive')
54
compile project(':micro-guava')
65
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:hamcrestVersion
76
testCompile project(':micro-grizzly')

micro-events/src/main/java/com/aol/micro/server/rest/resources/ActiveResource.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212

1313
import org.springframework.beans.factory.annotation.Autowired;
1414

15+
import com.aol.cyclops.control.ReactiveSeq;
16+
import com.aol.micro.server.WorkerThreads;
1517
import com.aol.micro.server.auto.discovery.CommonRestResource;
1618
import com.aol.micro.server.auto.discovery.SingletonRestResource;
1719
import com.aol.micro.server.events.JobsBeingExecuted;
1820
import com.aol.micro.server.events.RequestsBeingExecuted;
19-
import com.aol.micro.server.reactive.Reactive;
2021
import com.google.common.collect.Maps;
2122

2223

2324

2425
@Path("/active")
25-
public class ActiveResource implements CommonRestResource, SingletonRestResource, Reactive {
26+
public class ActiveResource implements CommonRestResource, SingletonRestResource {
2627

2728
private static final Object LOG_LEVEL = null;
2829
private final Map<String,RequestsBeingExecuted> activeQueries;
@@ -45,10 +46,11 @@ public ActiveResource(List<RequestsBeingExecuted> activeQueries,JobsBeingExecute
4546
@Path("/requests")
4647
public void activeRequests(@Suspended AsyncResponse asyncResponse,@QueryParam("type") final String type) {
4748

48-
this.cpuStreamBuilder().of((type == null ? "default" : type))
49+
ReactiveSeq.of((type == null ? "default" : type))
4950
.map(typeToUse->activeQueries.get(typeToUse).toString())
50-
.peek(result->asyncResponse.resume(result))
51-
.run();
51+
.futureOperations(WorkerThreads.ioExecutor.get())
52+
.forEach(result->asyncResponse.resume(result));
53+
5254
}
5355

5456

@@ -58,10 +60,11 @@ public void activeRequests(@Suspended AsyncResponse asyncResponse,@QueryParam("t
5860
@Path("/jobs")
5961
public void activeJobs(@Suspended AsyncResponse asyncResponse) {
6062

61-
this.cpuStreamBuilder().of(this.activeJobs)
62-
.then(JobsBeingExecuted::toString)
63-
.then(str->asyncResponse.resume(str))
64-
.run();
63+
ReactiveSeq.of(this.activeJobs)
64+
.map(JobsBeingExecuted::toString)
65+
.futureOperations(WorkerThreads.ioExecutor.get())
66+
.forEach(str->asyncResponse.resume(str));
67+
6568

6669
}
6770

micro-events/src/main/java/com/aol/micro/server/rest/resources/ManifestResource.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
import org.slf4j.LoggerFactory;
1919
import org.springframework.stereotype.Component;
2020

21+
import com.aol.cyclops.control.ReactiveSeq;
22+
import com.aol.micro.server.WorkerThreads;
2123
import com.aol.micro.server.auto.discovery.CommonRestResource;
2224
import com.aol.micro.server.auto.discovery.SingletonRestResource;
23-
import com.aol.micro.server.reactive.Reactive;
2425

2526
@Path("/manifest")
2627
@Component
27-
public class ManifestResource implements CommonRestResource, SingletonRestResource, Reactive{
28+
public class ManifestResource implements CommonRestResource, SingletonRestResource{
2829

2930

3031
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -35,11 +36,12 @@ public class ManifestResource implements CommonRestResource, SingletonRestResour
3536
@Produces("application/json")
3637
public void mainfest(@Suspended AsyncResponse asyncResponse, @Context ServletContext context) {
3738

38-
this.ioStreamBuilder().of("/META-INF/MANIFEST.MF")
39+
ReactiveSeq.of("/META-INF/MANIFEST.MF")
3940
.map(url->context.getResourceAsStream(url))
4041
.map(this::getManifest)
41-
.peek(result->asyncResponse.resume(result))
42-
.run();
42+
.futureOperations(WorkerThreads.ioExecutor.get())
43+
.forEach(result->asyncResponse.resume(result));
44+
4345

4446
}
4547

micro-grizzly-with-jersey/src/test/java/app/async/com/aol/micro/server/AsyncResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void expensive(@Suspended AsyncResponse asyncResponse){
4040
.peek(it ->
4141
System.out.println(it))
4242
.convertToSimpleReact()
43-
.<String,Boolean>allOf(data -> {
43+
.allOf(data -> {
4444
System.out.println(data);
4545
return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); });
4646
}

micro-grizzly-with-jersey/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ValidationAppTest {
2828

2929
@Before
3030
public void startServer() {
31-
stream = simpleReact.react(
31+
stream = simpleReact.ofAsync(
3232
() -> server = new MicroserverApp(() -> "guava-app")).then(server -> server.start());
3333

3434
entity = ImmutableEntity.builder().value("value").build();

micro-grizzly/src/test/java/app/async/com/aol/micro/server/AsyncResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void expensive(@Suspended AsyncResponse asyncResponse){
4040
.peek(it ->
4141
System.out.println(it))
4242
.convertToSimpleReact()
43-
.<String,Boolean>allOf(data -> {
43+
.allOf(data -> {
4444
System.out.println(data);
4545
return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); });
4646
}

micro-grizzly/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ValidationAppTest {
2828

2929
@Before
3030
public void startServer() {
31-
stream = simpleReact.react(
31+
stream = simpleReact.ofAsync(
3232
() -> server = new MicroserverApp(() -> "guava-app")).then(server -> server.start());
3333

3434
entity = ImmutableEntity.builder().value("value").build();

micro-guava/src/test/java/app/guava/com/aol/micro/server/GuavaAppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class GuavaAppTest {
3939

4040
@Before
4141
public void startServer() {
42-
stream = simpleReact.react(
42+
stream = simpleReact.ofAsync(
4343
() -> server = new MicroserverApp(GuavaAppTest.class,
4444
() -> "guava-app")).then(server -> server.start());
4545

micro-guava/src/test/java/app/validation/com/aol/micro/server/ValidationAppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ValidationAppTest {
3636

3737
@Before
3838
public void startServer() {
39-
stream = simpleReact.react(
39+
stream = simpleReact.ofAsync(
4040
() -> server = new MicroserverApp(ValidationAppTest.class,
4141
() -> "guava-app")).then(server -> server.start());
4242

micro-jersey/src/main/java/com/aol/micro/server/rest/jersey/JerseyPlugin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import org.glassfish.jersey.CommonProperties;
1010

11-
import com.aol.cyclops.data.collections.HashMaps;
1211
import com.aol.cyclops.data.collections.extensions.persistent.PMapX;
1312
import com.aol.cyclops.data.collections.extensions.persistent.PSetX;
13+
import com.aol.cyclops.data.collections.extensions.standard.MapXs;
1414
import com.aol.micro.server.Plugin;
1515
import com.aol.micro.server.rest.RestConfiguration;
1616
import com.aol.micro.server.servers.model.ServerData;
@@ -24,7 +24,7 @@ public Optional<RestConfiguration> restServletConfiguration(){
2424
}
2525
@Override
2626
public Function<FeatureContext,PMapX<String,Object>> jacksonFeatureProperties(){
27-
return context->PMapX.fromMap(HashMaps.of( CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
27+
return context->PMapX.fromMap(MapXs.of( CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.'
2828
+ context.getConfiguration().getRuntimeType().name().toLowerCase(),true));
2929
}
3030

micro-reactive/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ description = 'micro-reactive'
22
dependencies {
33

44

5-
5+
compile 'io.projectreactor:reactor-core:2.5.0.M2'
66
compile project(':micro-core')
7+
compile project(':micro-events')
78
testCompile project(':micro-grizzly')
89
testCompile project(':micro-jersey')
910
testCompile project(':micro-jackson-configuration')

0 commit comments

Comments
 (0)