R
R
relgames2015-04-01 11:46:41
Java
relgames, 2015-04-01 11:46:41

What framework to use to handle events and wait for a response?

The application processes certain events coming from outside via AMQP (RabbitMQ).
Inside the application, I want to make it so that the handlers can be combined and built in an arbitrary order, but so that the handlers do not depend on each other. In its simplest form, it's just a set of classes that implement Function<T, R> - something comes in and something comes out the other side.
The processing graph must be defined externally (for example, in a special separate class).
Example: there is a class Transformer implements Function<OriginalEvent, TransformedEvent>, there is a class Calculate<TransformedEvent, Double>, UpdateCounter<Double,Void> and there is a class WriteDoDatabase<TransformedEvent, Void>
I want to write it like in Java 8:
Stream<OriginalEvent,TransformedEvent> s = SomeFramework.map(new Transformer());
s.map(new Calculate()).onEvent(new UpdateCounter());
s.onEvent(new WriteDoDatabase());
And then when a new event arrives: s.process(originalEvent) - and this method can't return until all handlers are executed (while some can be executed in parallel, for example, WriteDoDatabase and Calculate+UpdateCounter
What have I already thought/tried?

  • Java 8 Streams - not suitable because need push
  • rxjava, reactor - it is not clear how to wait for all handlers. frameworks are inherently asynchronous
  • Guava EventBus - everything is synchronous, but I did not like the lack of the ability to explicitly link handlers, there is only implicitly by the event class

The task looks like a fairly standard one, but here's something I can't think of a nice way. Tell!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question