com.github.thorbenkuck.network.stream.EventStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easy-net Show documentation
Show all versions of easy-net Show documentation
An EventStream driven, simple to use Client/Server framework
The newest version!
package com.github.thorbenkuck.network.stream;
import java.util.function.Function;
import java.util.function.Supplier;
public interface EventStream {
static EventStream wrap(EventStream eventStream) {
if (!(eventStream instanceof ManagedEventStream)) {
throw new IllegalArgumentException("A ManagedEventStream is required!");
}
return new DelegatingEventStream((ManagedEventStream) eventStream);
}
static EventStream readFrom(DataStream dataStream) {
ManagedEventStream managedEventStream = ManagedEventStream.sequential();
dataStream.subscribe(managedEventStream::push);
return managedEventStream;
}
Subscription subscribe(Subscriber subscriber);
EventStream pipe(Transformation transformation, Supplier> eventStreamFunction);
default EventStream pipe(Transformation transformation) {
return pipe(transformation, DataStream::sequential);
}
default Subscription endIn(Sink super T> sink) {
return subscribe(sink::push);
}
default Subscription branchTo(DataStream super T> eventStream) {
return subscribe(eventStream::push);
}
default Subscription connectTo(DataStream super S> eventStream, Function function) {
return subscribe(t -> eventStream.push(function.apply(t)));
}
}