-
Notifications
You must be signed in to change notification settings - Fork 212
Reactive Microserver
johnmcclean-aol edited this page Nov 14, 2015
·
4 revisions
since v0.60 offers more integration points
- Offers fully non-blocking / event driven execution via Reactive interface / mixin
- Communicate across threads using simple-react adapters (Queues / Topics / Signals)
The Reactive mixin offers options such as
- ioStreamBuilder() : returns a performance optimised builder for executing IO Bound Streams
- cpuStreamBuilder() : returns a performance optimised builder for executing CPU Bound Streams
- The ability to switch a Stream between being optimised for IO & CPU bound operations
- enqueue facility to push data onto an asyncrhonous Queue to be picked up by a connected Stream
From the built-in manifest resouce
@GET
@Produces("application/json")
public void mainfest(@Suspended AsyncResponse asyncResponse, @Context ServletContext context) {
this.ioStreamBuilder().of("/META-INF/MANIFEST.MF")
.map(url->context.getResourceAsStream(url))
.map(this::getManifest)
.peek(result->asyncResponse.resume(result))
.run();
}
simple-react Stream listening for & reacting to events
public static void main(String[] args){
LazyFutureStream<String> stream = Pipes.register("test", QueueFactories.
<String>boundedNonBlockingQueue(100)
.build());
stream.filter(it->it!=null).peek(System.out::println).run();
new MicroserverApp(()-> "simple-app").run();
}
Rest Resources can pass events onwards
@GET
@Produces("text/plain")
@Path("/ping")
public String ping() {
this.enqueue("test","ping : " + next++);
return "ok";
}
Every Rest call to ping will result in our Lazy infinite stream printing out the ping counter to the console.