Skip to content

Instantly share code, notes, and snippets.

View jbrisbin's full-sized avatar

Jon Brisbin jbrisbin

View GitHub Profile
@jbrisbin
jbrisbin / ReactorDispatchingExample.java
Created February 19, 2015 21:55
Demo class for calculating Pi using Reactor
import org.apache.commons.lang.time.StopWatch;
import reactor.Environment;
import reactor.fn.BiFunction;
import reactor.rx.Streams;
import java.util.concurrent.TimeUnit;
/**
* Demo class for calculating Pi using Reactor.
*/
@jbrisbin
jbrisbin / pom.xml
Last active August 29, 2015 14:13
Example of using Reactor in a Maven project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>my-project</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
@jbrisbin
jbrisbin / BroadcastStream.java
Last active October 2, 2015 21:10
Simple Broadcast Stream example using #ProjectReactor
static {
// Only done once, statically, and shared across this classloader
Environment.initialize();
}
// Create a Stream subclass we can sink values into
Broadcaster<String> b = Broadcaster.create();
b
// dispatch onto a Thread other than 'main'
@jbrisbin
jbrisbin / ReactiveStreamApi.java
Created December 31, 2014 15:05
Sketch of ReactiveStream interface-based API
public interface PersonStream extends ReactiveStream<Person> {
@MapAction("@personRepo.merge($1, $2)")
ReactivePromise<Person> merge(String id, Person p);
}
@ReactiveRestController
public class MyController {
@Bean
public Action<Chain> handlers(PersonRepository persons,
HotStream<Person> personStream,
ObjectMapper jsonMapper,
ModelMapper beanMapper) {
return (chain) -> {
chain.handler("person", ctx ->
ctx.byMethod(spec ->
spec
.get(c -> {
@jbrisbin
jbrisbin / StreamRenderer.java
Created November 6, 2014 08:55
Ratpack Renderer for Reactor Streams
@Bean
public Renderer<Stream> personRenderer() {
return new RendererSupport<Stream>() {
@Override
public void render(Context ctx, Stream s) throws Exception {
ctx.promise(f -> s.consume(f::success))
.then(o -> ctx.render(json(o)));
}
};
}
@jbrisbin
jbrisbin / amqpstreams.groovy
Created October 7, 2014 17:44
Teaser of AmqpStreams
def stream1 = AmqpStreams.fromQueue(Queue.lookup('test')
.durable(true)
.bind('test'))
def stream2 = AmqpStreams.fromQueue('test')
Streams.merge(stream1, stream2)
.dispatchOn(environment)
@Test
public void workerOrchestrator() throws InterruptedException {
Environment env = new Environment();
Reactor reactor = Reactors.reactor(env, Environment.THREAD_POOL);
CountDownLatch latch = new CountDownLatch(2);
reactor.on(Selectors.$("worker"), new Consumer() {
@Override
@jbrisbin
jbrisbin / sample.groovy
Last active August 29, 2015 14:03
Sample Reactive Resource Framework Code
routing {
include SpringConfig
http {
route("/path/to/{resourceId}") to CustomResource
}
}
interface Context extends AbstractMutableMap<String, Object> {
@jbrisbin
jbrisbin / rest-shell-output.txt
Created June 18, 2014 22:27
rest-shell 2.0 sample output
_ _ _____ _____ ___ ___ _____ _ ____
| || |_ _|_ _| _ \ \ \ / / __(_) / / /
| __ | | | | | | _/ |\ \/\/ /\__ \_ / / /
|_||_| |_| |_| |_| | | \_/\_/ |___(_)_/_/
=====================|_|=====================
HTTP and WebSocket interactive shell - version 1.0
(http://localhost:8080/):> get --headers "X-Custom: custom header value"
> GET http://localhost:8080/ HTTP/1.1
>