use of org.nustaq.kontraktor.reactivestreams.impl.KxPublisherActor in project kontraktor by RuedigerMoeller.
the class KxReactiveStreams method newAsyncProcessor.
/**
* create async processor. Usually not called directly (see EventSink+RxPublisher)
* The resulting processor is Publisher allowing for multiple subscribers, having a
* slowest-subscriber-dominates policy.
*
* @param processingFunction
* @param sched
* @param batchSize
* @param <IN>
* @param <OUT>
* @return
*/
public <IN, OUT> Processor<IN, OUT> newAsyncProcessor(Function<IN, OUT> processingFunction, Scheduler sched, int batchSize) {
if (batchSize > KxReactiveStreams.MAX_BATCH_SIZE) {
throw new RuntimeException("batch size exceeds max of " + KxReactiveStreams.MAX_BATCH_SIZE);
}
KxPublisherActor pub = Actors.AsActor(KxPublisherActor.class, sched);
// actually init should provide a promise as return value to ensure streams instance is initialized.
// do sync shortcut instead here
pub._streams = this;
((KxPublisherActor) pub.getActor())._streams = this;
pub.setBatchSize(batchSize);
pub.init(processingFunction);
return pub;
}
use of org.nustaq.kontraktor.reactivestreams.impl.KxPublisherActor in project kontraktor by RuedigerMoeller.
the class KxReactiveStreams method connect.
/**
* @param eventType
* @param connectable
* @param disconHandler - can be null
* @param <T>
* @return
*/
public <T> IPromise<KxPublisher<T>> connect(Class<T> eventType, ConnectableActor connectable, Callback<ActorClientConnector> disconHandler) {
Callback<ActorClientConnector> discon = (acc, err) -> {
Log.Info(this, "Client disconnected");
acc.closeClient();
if (disconHandler != null) {
disconHandler.complete(acc, err);
}
};
IPromise connect = connectable.actorClass(KxPublisherActor.class).inboundQueueSize(scheduler.getDefaultQSize()).connect(discon, r -> {
Object remoteref = r;
if (((KxPublisherActor) remoteref)._callerSideSubscribers != null) {
((KxPublisherActor) remoteref)._callerSideSubscribers.forEach(subs -> {
((Subscriber) subs).onError(new IOException("connection lost"));
});
((KxPublisherActor) remoteref)._callerSideSubscribers = null;
}
});
Promise<KxPublisher<T>> res = new Promise<>();
connect.then((publisher, err) -> {
if (publisher != null) {
((KxPublisherActor) publisher)._streams = this;
res.resolve((KxPublisher<T>) publisher);
} else {
res.reject(err);
}
});
return res;
}
use of org.nustaq.kontraktor.reactivestreams.impl.KxPublisherActor in project kontraktor by RuedigerMoeller.
the class KxReactiveStreams method produce.
public <T> KxPublisher<T> produce(int batchSize, Iterator<T> iter) {
if (batchSize > KxReactiveStreams.MAX_BATCH_SIZE) {
throw new RuntimeException("batch size exceeds max of " + KxReactiveStreams.MAX_BATCH_SIZE);
}
KxPublisherActor pub = Actors.AsActor(KxPublisherActor.class, scheduler);
// actually init should provide a promise as return value to ensure streams instance is initialized.
// do sync shortcut instead here
pub._streams = this;
((KxPublisherActor) pub.getActor())._streams = this;
pub.setBatchSize(batchSize);
pub.initFromIterator(iter);
return pub;
}
use of org.nustaq.kontraktor.reactivestreams.impl.KxPublisherActor in project kontraktor by RuedigerMoeller.
the class KxReactiveStreams method newLossyProcessor.
public <T, OUT> Processor<T, OUT> newLossyProcessor(Function<T, OUT> processingFunction, int batchSize) {
if (batchSize > KxReactiveStreams.MAX_BATCH_SIZE) {
throw new RuntimeException("batch size exceeds max of " + KxReactiveStreams.MAX_BATCH_SIZE);
}
KxPublisherActor pub = Actors.AsActor(KxPublisherActor.class, scheduler);
// actually init should provide a promise as return value to ensure streams instance is initialized.
// do sync shortcut instead here
pub._streams = this;
((KxPublisherActor) pub.getActor())._streams = this;
pub.setBatchSize(batchSize);
pub.setLossy(true);
pub.init(processingFunction);
return pub;
}
Aggregations