Skip to content

Instantly share code, notes, and snippets.

View jbrisbin's full-sized avatar

Jon Brisbin jbrisbin

View GitHub Profile
@jbrisbin
jbrisbin / StateMachineSample.groovy
Last active December 18, 2015 18:19
Sample StateMachine usage for Reactor
// reactor-fsm: github.com/jbrisbin/reactor-fsm
// reactor: github.com/reactor/reactor
StateMachine ioMachine = new StateMachine.Spec().
sync().
using('idle', 'wait', 'send-request', 'response-ready').
when('send-request') { prev ->
def msg = requests.peek()
send(msg)
'wait'
@jbrisbin
jbrisbin / PromiseHandlerMethodReturnValueHandler.java
Last active December 21, 2015 11:29
PromiseReturnValueHandlerTests
package reactor.spring.webmvc;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
import reactor.core.composable.Promise;
import reactor.function.Consumer;
@jbrisbin
jbrisbin / ProcessorToReactor.java
Last active December 22, 2015 00:29
Pass data from a Processor to an IO-intensive task in a Reactor backed by a ThreadPoolExecutorDispatcher
// Create a Reactor Environment (1 per JVM).
static final Environment env = new Environment();
// Create a Reactor to handle IO events that's backed by a ThreadPoolExecutorDispatcher.
// To increase concurrent thread count, copy META-INF/reactor/default.properties from
// GitHub repo and put it into your own project, adjusting number of threads from 0 (1 per CPU)
// to whatever you want.
Reactor ioReactor = Reactors.reactor()
.env(env)
.dispatcher(Environment.THREAD_POOL)
@jbrisbin
jbrisbin / ReactorTest.java
Created September 6, 2013 01:20
Reactor Test file
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.core.spec.Reactors;
@jbrisbin
jbrisbin / gradle_errors.txt
Created September 16, 2013 19:30
Gradle build errors using JDK 8
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':data-spring:test'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.j
@jbrisbin
jbrisbin / TradeController.java
Last active December 23, 2015 15:19
Example usage of reactor-data with Spring Boot
@Controller
public class TradeController {
@Autowired
private ClientComposableRepository clients;
@RequestMapping(value = "/{clientId}", method = RequestMethod.POST)
@ResponseBody
public DeferredResult<String> trade(@PathVariable Long clientId) {
final DeferredResult<String> d = new DeferredResult<String>();
@jbrisbin
jbrisbin / AggregateOrders.java
Last active December 23, 2015 18:39
Example of aggregating data using Streams.
import reactor.core.Environment;
import reactor.core.composable.Deferred;
import reactor.core.composable.Stream;
import reactor.core.composable.spec.Streams;
import reactor.function.Consumer;
import reactor.function.Function;
import reactor.tuple.Tuple2;
/**
* @author Jon Brisbin
@jbrisbin
jbrisbin / ComposableEventRepository.java
Last active December 24, 2015 16:49
Psuedo-code around a ComposableEventRepository
public interface ComposableEventRepository<V, K extends Serializable> extends ComposableMessagingRepository<Event<V>, K> {
Stream<Event<V>> receive(Selector sel);
}
@jbrisbin
jbrisbin / NettyHttpServerSocketOptions.java
Last active December 25, 2015 21:39
Example of using Reactor to serve HTTP requests using Netty's built-in HTTP codec.
public class NettyHttpServerSocketOptions extends NettyServerSocketOptions {
@Override
public final Consumer<ChannelPipeline> pipelineConfigurer() {
return new Consumer<ChannelPipeline>() {
@Override
public void accept(ChannelPipeline pipeline) {
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
pipeline.addLast(new HttpResponseEncoder());
}
@jbrisbin
jbrisbin / ReactorSample.java
Created January 3, 2014 19:11
Example usage of a Reactor with JDK 8 Lambdas.
import static reactor.event.selector.Selectors.*;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.core.spec.Reactors;
import reactor.event.Event;
import reactor.function.Function;
/**
* Example of Reactor usage with JDK 8 Lambdas.