reactor.core.publisher.FluxProcessor Java Examples
The following examples show how to use
reactor.core.publisher.FluxProcessor.
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: ReactiveAdapterRegistryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void getAdapterForReactiveSubType() { ReactiveAdapter adapter1 = getAdapter(Flux.class); ReactiveAdapter adapter2 = getAdapter(FluxProcessor.class); assertSame(adapter1, adapter2); this.registry.registerReactiveType( ReactiveTypeDescriptor.multiValue(FluxProcessor.class, FluxProcessor::empty), o -> (FluxProcessor<?, ?>) o, FluxProcessor::from); ReactiveAdapter adapter3 = getAdapter(FluxProcessor.class); assertNotNull(adapter3); assertNotSame(adapter1, adapter3); }
Example #2
Source File: ReactiveAdapterRegistryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void getAdapterForReactiveSubType() { ReactiveAdapter adapter1 = getAdapter(Flux.class); ReactiveAdapter adapter2 = getAdapter(FluxProcessor.class); assertSame(adapter1, adapter2); this.registry.registerReactiveType( ReactiveTypeDescriptor.multiValue(FluxProcessor.class, FluxProcessor::empty), o -> (FluxProcessor<?, ?>) o, FluxProcessor::from); ReactiveAdapter adapter3 = getAdapter(FluxProcessor.class); assertNotNull(adapter3); assertNotSame(adapter1, adapter3); }
Example #3
Source File: ProcessorRequestQueueFactory.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Override public <T> RequestQueue<T> create() { return new RequestQueue<T>() { private final FluxProcessor<Object, Object> processor = processorSupplier.get(); private final FluxSink<Object> sink = processor.sink(FluxSink.OverflowStrategy.BUFFER); @Override public void push(T request) { sink.next(request); } @SuppressWarnings("unchecked") @Override public Flux<T> requests() { return (Flux<T>) Flux.create(sink -> processor.subscribe(sink::next), overflowStrategy); } }; }
Example #4
Source File: AppServer.java From reactor-guice with Apache License 2.0 | 5 votes |
private static void testWebsocketClient() throws IOException { Properties properties = new Properties(); // properties.load(new FileInputStream("D:\\project\\reactor-guice\\application.properties")); properties.load(new FileInputStream("/Users/develop/Project/reactor-guice/application.properties")); int port = Integer.valueOf(properties.getProperty("server.port", "8081")); FluxProcessor<String, String> client = ReplayProcessor.<String>create().serialize(); Flux.interval(Duration.ofMillis(1000)) .map(Object::toString) .subscribe(client::onNext); HttpClient.create() // .port(port) // .wiretap(true) .websocket() .uri("ws://127.0.0.1:8083/kreactor/ws") .handle((in, out) -> out.withConnection(conn -> { in.aggregateFrames().receiveFrames().map(frames -> { if (frames instanceof TextWebSocketFrame) { System.out.println("Receive text message " + ((TextWebSocketFrame) frames).text()); } else if (frames instanceof BinaryWebSocketFrame) { System.out.println("Receive binary message " + frames.content()); } else { System.out.println("Receive normal message " + frames.content()); } return Mono.empty(); }) .subscribe(); }) // .options(NettyPipeline.SendOptions::flushOnEach) .sendString(client) ) .blockLast(); }
Example #5
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 #6
Source File: ReactorDemo.java From reactive-streams-in-java with Apache License 2.0 | 4 votes |
public static void useProcessor() { // Processor implements both Publisher and Subscriber // DirectProcessor is the simplest Processor from Reactor final FluxProcessor<String, String> processor = DirectProcessor.create(); //TODO }
Example #7
Source File: ReactorProcProxy.java From RHub with Apache License 2.0 | 4 votes |
public ReactorProcProxy(FluxProcessor proc, TePolicy tePolicy) { super(proc, tePolicy); }
Example #8
Source File: WebsocketTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void duplexEcho() throws Exception { int c = 10; CountDownLatch clientLatch = new CountDownLatch(c); CountDownLatch serverLatch = new CountDownLatch(c); FluxProcessor<String, String> server = Processors.<String>replayAll().serialize(); FluxProcessor<String, String> client = Processors.<String>replayAll().serialize(); server.log("server") .subscribe(v -> serverLatch.countDown()); client.log("client") .subscribe(v -> clientLatch.countDown()); httpServer = HttpServer.create() .port(0) .handle((in, out) -> out.sendWebsocket((i, o) -> o.sendString( i.receive() .asString() .take(c) .subscribeWith(server)))) .wiretap(true) .bindNow(); Flux.interval(Duration.ofMillis(200)) .map(Object::toString) .subscribe(client::onNext); HttpClient.create() .port(httpServer.port()) .wiretap(true) .websocket() .uri("/test") .handle((i, o) -> o.sendString(i.receive() .asString() .subscribeWith(client))) .log() .subscribe(); Assert.assertTrue(serverLatch.await(10, TimeUnit.SECONDS)); Assert.assertTrue(clientLatch.await(10, TimeUnit.SECONDS)); }
Example #9
Source File: ProcessorRequestQueueFactory.java From Discord4J with GNU Lesser General Public License v3.0 | 4 votes |
ProcessorRequestQueueFactory(Supplier<FluxProcessor<Object, Object>> processorSupplier, FluxSink.OverflowStrategy overflowStrategy) { this.processorSupplier = processorSupplier; this.overflowStrategy = overflowStrategy; }
Example #10
Source File: EmitterProcessorVerification.java From reactor-core with Apache License 2.0 | 4 votes |
@Override public Processor<Long, Long> createIdentityProcessor(int bufferSize) { @SuppressWarnings("deprecation") FluxIdentityProcessor<Long> p = reactor.core.publisher.EmitterProcessor.create(bufferSize); return FluxProcessor.wrap(p, p.log("EmitterProcessorVerification", Level.FINE)); }
Example #11
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; }
Example #12
Source File: RequestQueueFactory.java From Discord4J with GNU Lesser General Public License v3.0 | 2 votes |
/** * Returns a factory of {@link RequestQueue} backed by a {@link FluxProcessor}. * * @param processorSupplier a Supplier that provides a processor. The Supplier <b>must</b> provide a new instance * every time it is called, and the processor must not be pre-filled with any elements, otherwise it may lead to * non-deterministic behavior. * @param overflowStrategy the overflow strategy to apply on the processor * @return a {@link RequestQueueFactory} backed by a {@link FluxProcessor} */ static RequestQueueFactory backedByProcessor(Supplier<FluxProcessor<Object, Object>> processorSupplier, FluxSink.OverflowStrategy overflowStrategy) { return new ProcessorRequestQueueFactory(processorSupplier, overflowStrategy); }