Java Code Examples for io.reactivex.Flowable#map()
The following examples show how to use
io.reactivex.Flowable#map() .
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: FlowableUnmarshaller.java From vertx-rx with Apache License 2.0 | 6 votes |
@Override public Publisher<T> apply(@NonNull Flowable<B> upstream) { Flowable<Buffer> unwrapped = upstream.map(unwrap::apply); Single<Buffer> aggregated = unwrapped.collect(Buffer::buffer, Buffer::appendBuffer); Maybe<T> unmarshalled = aggregated.toMaybe().concatMap(buffer -> { if (buffer.length() > 0) { try { T obj; if (mapper != null) { JsonParser parser = mapper.getFactory().createParser(buffer.getBytes()); obj = nonNull(mappedType) ? mapper.readValue(parser, mappedType) : mapper.readValue(parser, mappedTypeRef); } else { obj = getT(buffer, mappedType, mappedTypeRef); } return Maybe.just(obj); } catch (Exception e) { return Maybe.error(e); } } else { return Maybe.empty(); } }); return unmarshalled.toFlowable(); }
Example 2
Source File: WriteReactiveApiImpl.java From influxdb-client-java with MIT License | 6 votes |
@Override public <M> void writeMeasurements(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final WritePrecision precision, @Nonnull final Flowable<M> measurements) { Arguments.checkNonEmpty(bucket, "bucket"); Arguments.checkNonEmpty(org, "organization"); Arguments.checkNotNull(precision, "precision"); Arguments.checkNotNull(measurements, "measurements"); Flowable<BatchWriteData> stream = measurements .map(it -> new BatchWriteDataMeasurement(it, precision, options, measurementMapper)); write(bucket, org, precision, stream); }
Example 3
Source File: BackpressureController.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Quickly produce numbers */ @Override public Flowable<NumbersProto.Number> sendNumbers(Single<NumbersProto.HowMany> request) { // Fork the response flowable using share() Flowable<Integer> numbers = request // Extract request .map(NumbersProto.HowMany::getNumber) // Process request .flatMapPublisher(i -> Flowable.range(0, i)) .share(); // One fork updates the UI numbers.observeOn(JavaFxScheduler.platform()) .subscribe(i -> { producedLabel.setText(i.toString()); producedSeries.getData().add(new XYChart.Data<>(System.currentTimeMillis(), i)); }); // Other fork returns the number stream return numbers.map(BackpressureController::protoNum); }
Example 4
Source File: ObserveQuery.java From contentful.java with Apache License 2.0 | 5 votes |
/** * Observe a resource matching the given {@code id}. * * @param id resource id. * @return {@link Flowable} instance. * @throws CDAResourceNotFoundException if resource was not found. */ @SuppressWarnings("unchecked") public Flowable<T> one(final String id) { Flowable<T> flowable = where("sys.id", id).all() .map(array -> { if (array.items().size() == 0) { throw new CDAResourceNotFoundException(type, id); } CDAType resourceType = typeForClass(type); if (ASSET.equals(resourceType)) { return (T) array.assets().get(id); } else if (ENTRY.equals(resourceType)) { return (T) array.entries().get(id); } else if (CONTENTTYPE.equals(resourceType)) { return (T) array.items().get(0); } else if (LOCALE.equals(resourceType)) { T found = findById(array, id); if (found == null) { throw new CDAResourceNotFoundException(type, id); } return found; } else { throw new IllegalArgumentException("Cannot invoke query for type: " + type.getName()); } } ); if (CONTENTTYPE.equals(typeForClass(type))) { flowable = flowable.map(t -> { if (t != null) { client.cache.types().put(t.id(), (CDAContentType) t); } return t; }); } return flowable; }
Example 5
Source File: NoneStrategy.java From RxCache with Apache License 2.0 | 5 votes |
@Override public <T> Publisher<CacheResult<T>> flow(RxCache rxCache, final String key, Flowable<T> source, Type type) { return source.map(new Function<T, CacheResult<T>>() { @Override public CacheResult<T> apply(@NonNull T t) throws Exception { return new CacheResult<>(ResultFrom.Remote, key, t); } }); }
Example 6
Source File: FlowableRepeatingTransformTest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@Override public Flowable<Integer> apply(Flowable<Integer> f) throws Exception { return f.map(new Function<Integer, Integer>() { @Override public Integer apply(Integer t) throws Exception { return t + 1; } }); }
Example 7
Source File: Strings.java From rxjava2-extras with Apache License 2.0 | 5 votes |
public static Flowable<String> strings(Flowable<?> source) { return source.map(new Function<Object, String>() { @Override public String apply(Object t) throws Exception { return String.valueOf(t); } }); }
Example 8
Source File: DockerLogManager.java From carnotzet with Apache License 2.0 | 5 votes |
/** * Ensures that a listener is listening to the logs of a container, from a given time **/ @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") private void ensureCapturingContainerLogs(Container container, Instant since, LogListener listener) { ContainerListener key = new ContainerListener(container, listener); Flowable stream = captureStreams.get(key); if (stream != null) { return; } List<String> command = getLogCommand(since, listener, container); log.debug("Scheduling new log capture flowable for container [{}] and listener [{}], command is [{}]", container, listener, Joiner.on(' ').join(command)); try { Process dockerCliProcess = new ProcessBuilder(command.toArray(new String[command.size()])).start(); Flowable<String> stdOutLines = flowableInputStreamScanner(dockerCliProcess.getInputStream()).subscribeOn(Schedulers.newThread()); Flowable<String> stdErrLines = flowableInputStreamScanner(dockerCliProcess.getErrorStream()).subscribeOn(Schedulers.newThread()); Flowable<String> allLines = stdOutLines.mergeWith(stdErrLines); Flowable<LogEvent> allEvents = allLines.map(s -> new LogEvent(container.getServiceName(), container.getReplicaNumber(), s)); allEvents.subscribe(listener::accept, Throwable::printStackTrace, () -> captureStreams.remove(key)); captureStreams.put(key, allEvents); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example 9
Source File: InitWalletManager.java From dapp-wallet-demo with Apache License 2.0 | 5 votes |
/** * @param context app context 上下文 * @param password the wallet password(not the bip39 password) 钱包密码(而不是BIP39的密码) * @param mnemonics 助记词 * @return wallet 钱包 */ public Flowable<HLWallet> generateWallet(Context context, String password, String mnemonics) { Flowable<String> flowable = Flowable.just(mnemonics); return flowable .map(s -> { ECKeyPair keyPair = generateKeyPair(s); WalletFile walletFile = Wallet.createLight(password, keyPair); HLWallet hlWallet = new HLWallet(walletFile); WalletManager.shared().saveWallet(context, hlWallet); return hlWallet; }); }
Example 10
Source File: WriteReactiveApiImpl.java From influxdb-client-java with MIT License | 5 votes |
@Override public void writeRecords(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final WritePrecision precision, @Nonnull final Flowable<String> records) { Arguments.checkNonEmpty(bucket, "bucket"); Arguments.checkNonEmpty(org, "organization"); Arguments.checkNotNull(precision, "precision"); Arguments.checkNotNull(records, "records"); Flowable<BatchWriteData> stream = records.map(BatchWriteDataRecord::new); write(bucket, org, precision, stream); }
Example 11
Source File: JsonToTransactionTransformer.java From eda-tutorial with Apache License 2.0 | 4 votes |
@Incoming("transactions") @Outgoing("internal") public Flowable<Transaction> process(Flowable<String> value) { return value.map(s -> jsonb.fromJson(s, Transaction.class)); }
Example 12
Source File: ServerErrorUpstreamCancellationIntegrationTest.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Flowable<NumberProto.Number> twoWayPressure(Flowable<NumberProto.Number> request) { return request.map(x -> kaboom()); }
Example 13
Source File: FusedTckService.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Flowable<Message> manyToMany(Flowable<Message> request) { return request.map(this::maybeExplode); }
Example 14
Source File: BeanUsingMerge.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
@Outgoing("X") @Incoming("Z2") public Flowable<String> y(Flowable<String> z) { return z.map(String::toUpperCase); }
Example 15
Source File: BeanUsingOne.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
@Outgoing("X") @Incoming("Z2") public Flowable<String> y(Flowable<String> z) { return z.map(String::toUpperCase); }
Example 16
Source File: BeanUsingConcat.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
@Outgoing("X") @Incoming("Z2") public Flowable<String> y(Flowable<String> z) { return z.map(String::toUpperCase); }
Example 17
Source File: StreamingTest.java From state-machine with Apache License 2.0 | 4 votes |
@Test public void testJsonInputToStateMachineIssue1() throws InterruptedException { // JSON source stream (could contain other messages about other // Microwaves with different ids which will be processed concurrently by // the Processor) Flowable<String> messages = Flowable.just( "{\"cls\": \"Microwave\", \"id\": \"1\",\"event\": \"ButtonPressed\"}", "{\"cls\": \"Microwave\", \"id\": \"1\",\"event\": \"DoorOpened\"}", "{\"cls\": \"Microwave\", \"id\": \"1\",\"event\": \"ButtonPressed\"}"); Flowable<Signal<?, String>> signals = messages // .map(msg -> toSignal(msg)); // special scheduler that we will use to schedule signals and to process // events Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(3)); // create the signal processor Processor<String> processor = createProcessor(scheduler, signals); // using a test subscriber because has easy assert methods on it TestSubscriber<Object> ts = TestSubscriber.create(); // subscribe to the stream of entity states that is produced from the // signals stream processor // .flowable() // // just output the states .map(esm -> esm.state()) // .subscribe(ts); // wait for processing to finish (is running asynchronously using the // scheduler) Thread.sleep(1000); // assert that things happened as we expected ts.assertValues( // MicrowaveStateMachine.State.COOKING, MicrowaveStateMachine.State.COOKING_INTERRUPTED, MicrowaveStateMachine.State.COOKING_INTERRUPTED); }
Example 18
Source File: RequestMappingMessageConversionIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
@PostMapping("/flowable") public Flowable<Person> transformFlowable(@RequestBody Flowable<Person> persons) { return persons.map(person -> new Person(person.getName().toUpperCase())); }
Example 19
Source File: RequestMappingMessageConversionIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
@PostMapping("/flowable") public Flowable<Person> transformFlowable(@RequestBody Flowable<Person> persons) { return persons.map(person -> new Person(person.getName().toUpperCase())); }