reactor.rx.Stream Java Examples
The following examples show how to use
reactor.rx.Stream.
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: Reactor2TcpClient.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy) { Assert.notNull(connectionHandler, "TcpConnectionHandler must not be null"); Assert.notNull(strategy, "ReconnectStrategy must not be null"); TcpClient<Message<P>, Message<P>> tcpClient; synchronized (this.tcpClients) { if (this.stopping) { IllegalStateException ex = new IllegalStateException("Shutting down."); connectionHandler.afterConnectFailure(ex); return new PassThroughPromiseToListenableFutureAdapter<Void>(Promises.<Void>error(ex)); } tcpClient = NetStreams.tcpClient(REACTOR_TCP_CLIENT_TYPE, this.tcpClientSpecFactory); this.tcpClients.add(tcpClient); } Stream<Tuple2<InetSocketAddress, Integer>> stream = tcpClient.start( new MessageChannelStreamHandler<P>(connectionHandler), new ReactorReconnectAdapter(strategy)); return new PassThroughPromiseToListenableFutureAdapter<Void>(stream.next().after()); }
Example #2
Source File: RepositoryStatisticsUpdatedReactor.java From mojito with Apache License 2.0 | 5 votes |
@PostConstruct private void createProcessor() { processor = RingBufferProcessor.create(); Stream stream = Streams.wrap(processor); stream.buffer(1, TimeUnit.SECONDS).consume(new Consumer<List<Long>>() { @Override public void accept(List<Long> repositoryIds) { for (Long repositoryId : Sets.newHashSet(repositoryIds)) { repositoryStatisticsJobScheduler.schedule(repositoryId); } } }); }
Example #3
Source File: PassportRestController.java From building-microservices with Apache License 2.0 | 5 votes |
@RequestMapping("/{userId}/passport") public DeferredResult<Passport> passport(@PathVariable String userId) { DeferredResult<Passport> passportDeferredResult = new DeferredResult<>(); Stream<Bookmark> bookmarkStream = this.passportService.getBookmarks(userId); Stream<Contact> contactStream = this.passportService.getContacts(userId); this.passportService.getPassport(userId, contactStream, bookmarkStream) .consume(passportDeferredResult::setResult); return passportDeferredResult; }
Example #4
Source File: GpfdistServer.java From spring-cloud-stream-app-starters with Apache License 2.0 | 4 votes |
private HttpServer<Buffer, Buffer> createProtocolListener() throws Exception { final Stream<Buffer> stream = Streams .wrap(processor) .window(flushCount, flushTime, TimeUnit.SECONDS) .flatMap(new Function<Stream<Buffer>, Publisher<Buffer>>() { @Override public Publisher<Buffer> apply(Stream<Buffer> t) { return t.reduce(new Buffer(), new BiFunction<Buffer, Buffer, Buffer>() { @Override public Buffer apply(Buffer prev, Buffer next) { return prev.append(next); } }); } }) .process(RingBufferWorkProcessor.<Buffer>create("gpfdist-sink-worker", 8192, false)); HttpServer<Buffer, Buffer> httpServer = NetStreams .httpServer(new Function<HttpServerSpec<Buffer, Buffer>, HttpServerSpec<Buffer, Buffer>>() { @Override public HttpServerSpec<Buffer, Buffer> apply(HttpServerSpec<Buffer, Buffer> server) { return server .codec(new GpfdistCodec()) .listen(port); } }); httpServer.get("/data", new ReactorChannelHandler<Buffer, Buffer, HttpChannel<Buffer,Buffer>>() { @Override public Publisher<Void> apply(HttpChannel<Buffer, Buffer> request) { request.responseHeaders().removeTransferEncodingChunked(); request.addResponseHeader("Content-type", "text/plain"); request.addResponseHeader("Expires", "0"); request.addResponseHeader("X-GPFDIST-VERSION", "Spring Dataflow"); request.addResponseHeader("X-GP-PROTO", "1"); request.addResponseHeader("Cache-Control", "no-cache"); request.addResponseHeader("Connection", "close"); return request.writeWith(stream .take(batchCount) .timeout(batchTimeout, TimeUnit.SECONDS, Streams.<Buffer>empty()) .concatWith(Streams.just(Buffer.wrap(new byte[0])))) .capacity(1l); } }); httpServer.start().awaitSuccess(); log.info("Server running using address=[" + httpServer.getListenAddress() + "]"); localPort = httpServer.getListenAddress().getPort(); return httpServer; }
Example #5
Source File: PassportService.java From building-microservices with Apache License 2.0 | 4 votes |
public Stream<Bookmark> getBookmarks(String userId) { return Streams.<Bookmark>create(subscriber -> { this.bookmarkClient.getBookmarks(userId).forEach(subscriber::onNext); subscriber.onComplete(); }).dispatchOn(this.environment, Environment.cachedDispatcher()).log("bookmarks"); }
Example #6
Source File: PassportService.java From building-microservices with Apache License 2.0 | 4 votes |
public Stream<Contact> getContacts(String userId) { return Streams.<Contact>create(subscriber -> { this.contactClient.getContacts(userId).forEach(subscriber::onNext); subscriber.onComplete(); }).dispatchOn(this.environment, Environment.cachedDispatcher()).log("contacts"); }
Example #7
Source File: PassportService.java From building-microservices with Apache License 2.0 | 4 votes |
public Stream<Passport> getPassport(String userId, Stream<Contact> contacts, Stream<Bookmark> bookmarks) { return Streams.zip(contacts.buffer(), bookmarks.buffer(), tuple -> new Passport(userId, tuple.getT1(), tuple.getT2())); }