Java Code Examples for reactor.core.publisher.FluxProcessor#sink()
The following examples show how to use
reactor.core.publisher.FluxProcessor#sink() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonMessageProcessor.java From linstor-server with GNU General Public License v3.0 | 4 votes |
@Inject public CommonMessageProcessor( ErrorReporter errorLogRef, Scheduler scheduler, ScopeRunner scopeRunnerRef, CommonSerializer commonSerializerRef, Map<String, BaseApiCall> apiCalls, Map<String, ApiCallDescriptor> apiCallDescriptors ) { errorLog = errorLogRef; scopeRunner = scopeRunnerRef; commonSerializer = commonSerializerRef; int queueSize = MathUtils.bounds( MIN_QUEUE_SIZE, Math.min(LinStor.CPU_COUNT, MAX_THR_COUNT) * THR_QUEUE_FACTOR, MAX_QUEUE_SIZE ); int thrCount = MathUtils.bounds(MIN_THR_COUNT, LinStor.CPU_COUNT, MAX_THR_COUNT); // Limit the number of messages that can be submitted for processing // concurrently by setting the processor's buffer size. // In the absence of any backpressure mechanism in the communications // protocol, we resort to blocking when too many messages are received and // letting the TCP buffer fill up. // Many messages from a single peer will still be queued in an unbounded // fashion as part of the message re-ordering. FluxProcessor<Runnable, Runnable> processor = EmitterProcessor.create(queueSize); workerPool = processor.sink(); processor // minimal prefetch because we control queueing via queueSize .parallel(thrCount, 1) // minimal prefetch for low latency .runOn(scheduler, 1) .doOnNext(Runnable::run) .subscribe( ignored -> { // do nothing }, exc -> errorLog.reportError(exc, null, null, "Uncaught exception in parallel processor") ); apiCallMap = new TreeMap<>(); for (Map.Entry<String, BaseApiCall> entry : apiCalls.entrySet()) { String apiName = entry.getKey(); BaseApiCall apiCall = entry.getValue(); ApiCallDescriptor apiDscr = apiCallDescriptors.get(apiName); if (apiDscr != null) { apiCallMap.put(apiName, new ApiEntry(apiCall, apiDscr, apiDscr.requiresAuth(), apiDscr.transactional())); } else { errorLog.reportError( Level.ERROR, new ImplementationError( ApiCallDescriptor.class.getSimpleName() + " entry is missing for API call object '" + apiName + "'", null ) ); } } }
Example 2
Source File: DefaultEventDispatcher.java From Discord4J with GNU Lesser General Public License v3.0 | 3 votes |
/** * Creates a new event dispatcher using the given {@link FluxProcessor}, backpressure-handling strategy and * threading model. * * @param eventProcessor a {@link FluxProcessor} of {@link Event}, used to bridge gateway events to the dispatcher * subscribers * @param overflowStrategy an overflow strategy, see {@link FluxSink.OverflowStrategy} for the available strategies * @param eventScheduler a {@link Scheduler} to ensure a certain thread model on each published signal */ public DefaultEventDispatcher(FluxProcessor<Event, Event> eventProcessor, FluxSink.OverflowStrategy overflowStrategy, Scheduler eventScheduler) { this.eventProcessor = eventProcessor; this.sink = eventProcessor.sink(overflowStrategy); this.eventScheduler = eventScheduler; }