io.reactivex.MaybeSource Java Examples

The following examples show how to use io.reactivex.MaybeSource. 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: SchedulerTransformer.java    From Collection-Android with MIT License 6 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    switch (mSchedulerType) {
        case _main:
            return upstream.observeOn(AndroidSchedulers.mainThread());
        case _io:
            return upstream.observeOn(RxSchedulerUtils.io(mIOExecutor));
        case _io_main:
            return upstream
                    .subscribeOn(RxSchedulerUtils.io(mIOExecutor))
                    .unsubscribeOn(RxSchedulerUtils.io(mIOExecutor))
                    .observeOn(AndroidSchedulers.mainThread());
        case _io_io:
            return upstream
                    .subscribeOn(RxSchedulerUtils.io(mIOExecutor))
                    .unsubscribeOn(RxSchedulerUtils.io(mIOExecutor))
                    .observeOn(RxSchedulerUtils.io(mIOExecutor));
        default:
            break;
    }
    return upstream;
}
 
Example #2
Source File: MaybeUnmarshaller.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
@Override
public MaybeSource<T> apply(@NonNull Maybe<B> upstream) {
  Maybe<Buffer> unwrapped = upstream.map(unwrap::apply);
  Maybe<T> unmarshalled = unwrapped.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;
}
 
Example #3
Source File: RequestObjectServiceImpl.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private Single<JWT> validateSignature(SignedJWT jwt, Client client) {
    return jwkService.getKeys(client)
            .switchIfEmpty(Maybe.error(new InvalidRequestObjectException()))
            .flatMap(new Function<JWKSet, MaybeSource<JWK>>() {
                @Override
                public MaybeSource<JWK> apply(JWKSet jwkSet) throws Exception {
                    return jwkService.getKey(jwkSet, jwt.getHeader().getKeyID());
                }
            })
            .switchIfEmpty(Maybe.error(new InvalidRequestObjectException()))
            .flatMapSingle(new Function<JWK, SingleSource<JWT>>() {
                @Override
                public SingleSource<JWT> apply(JWK jwk) throws Exception {
                    // 6.3.2.  Signed Request Object
                    // To perform Signature Validation, the alg Header Parameter in the
                    // JOSE Header MUST match the value of the request_object_signing_alg
                    // set during Client Registration
                    if (jwt.getHeader().getAlgorithm().getName().equals(client.getRequestObjectSigningAlg()) &&
                            jwsService.isValidSignature(jwt, jwk)) {
                        return Single.just(jwt);
                    } else {
                        return Single.error(new InvalidRequestObjectException("Invalid signature"));
                    }
                }
            });
}
 
Example #4
Source File: RxBleClientImpl.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
/**
 * This {@link Observable} will not emit values by design. It may only emit {@link BleScanException} if
 * bluetooth adapter is turned down.
 */
<T> Observable<T> bluetoothAdapterOffExceptionObservable() {
    return rxBleAdapterStateObservable
            .filter(new Predicate<BleAdapterState>() {
                @Override
                public boolean test(BleAdapterState state) {
                    return state != BleAdapterState.STATE_ON;
                }
            })
            .firstElement()
            .flatMap(new Function<BleAdapterState, MaybeSource<T>>() {
                @Override
                public MaybeSource<T> apply(BleAdapterState bleAdapterState) {
                    return Maybe.error(new BleScanException(BleScanException.BLUETOOTH_DISABLED));
                }
            })
            .toObservable();
}
 
Example #5
Source File: UserProfileApiVerticle.java    From vertx-in-action with MIT License 5 votes vote down vote up
private MaybeSource<? extends JsonObject> deleteIncompleteUser(JsonObject query, Throwable err) {
  if (isIndexViolated(err)) {
    return mongoClient
      .rxRemoveDocument("user", query)
      .flatMap(del -> Maybe.error(err));
  } else {
    return Maybe.error(err);
  }
}
 
Example #6
Source File: Wrappers.java    From brave with Apache License 2.0 5 votes vote down vote up
public static <T> Maybe<T> wrap(
  MaybeSource<T> source, CurrentTraceContext contextScoper, TraceContext assembled) {
  if (source instanceof Callable) {
    return new TraceContextCallableMaybe<>(source, contextScoper, assembled);
  }
  return new TraceContextMaybe<>(source, contextScoper, assembled);
}
 
Example #7
Source File: InTransactionMaybe.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
  return sqlConnection.rxSetAutoCommit(false)
    .andThen(upstream)
    .flatMap(item -> sqlConnection.rxCommit().andThen(Maybe.just(item)), Maybe::error, () -> sqlConnection.rxCommit().andThen(Maybe.empty()))
    .onErrorResumeNext(throwable -> {
      return sqlConnection.rxRollback().onErrorComplete()
        .andThen(sqlConnection.rxSetAutoCommit(true).onErrorComplete())
        .andThen(Maybe.error(throwable));
    }).flatMap(item -> sqlConnection.rxSetAutoCommit(true).andThen(Maybe.just(item)), Maybe::error, () -> sqlConnection.rxSetAutoCommit(true).andThen(Maybe.empty()));
}
 
Example #8
Source File: ClientAssertionServiceImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public Maybe<Client> assertClient(String assertionType, String assertion, String basePath) {

    InvalidClientException unsupportedAssertionType = new InvalidClientException("Unknown or unsupported assertion_type");

    if (assertionType == null || assertionType.isEmpty()) {
        return Maybe.error(unsupportedAssertionType);
    }

    if (JWT_BEARER.equals(assertionType)) {
        return this.validateJWT(assertion, basePath)
                .flatMap(new Function<JWT, MaybeSource<Client>>() {
                    @Override
                    public MaybeSource<Client> apply(JWT jwt) throws Exception {
                        // Handle client_secret_key client authentication
                        if (JWSAlgorithm.Family.HMAC_SHA.contains(jwt.getHeader().getAlgorithm())) {
                            return validateSignatureWithHMAC(jwt);
                        } else {
                            // Handle private_key_jwt client authentication
                            return validateSignatureWithPublicKey(jwt);
                        }
                    }
                });
    }

    return Maybe.error(unsupportedAssertionType);
}
 
Example #9
Source File: UserServiceImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private MaybeSource<Optional<Client>> clientSource(String audience) {
    if (audience == null) {
        return Maybe.just(Optional.empty());
    }

    return clientSyncService.findById(audience)
            .map(client -> Optional.of(client))
            .defaultIfEmpty(Optional.empty());
}
 
Example #10
Source File: RecorderControllerImpl.java    From science-journal with Apache License 2.0 5 votes vote down vote up
private MaybeSource<SensorSnapshot> makeSnapshot(String sensorId, SensorRegistry sensorRegistry)
    throws Exception {
  BehaviorSubject<ScalarReading> subject = latestValues.get(sensorId);
  if (subject == null) {
    return Maybe.empty();
  }
  final GoosciSensorSpec.SensorSpec spec = getSensorSpec(sensorId, sensorRegistry);
  return subject.firstElement().map(value -> generateSnapshot(spec, value));
}
 
Example #11
Source File: MainObserverTransformer.java    From pandroid with Apache License 2.0 5 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    Maybe<T> tObservable = upstream
            .observeOn(AndroidSchedulers.mainThread());
    if (provider == null) {
        return tObservable;
    }
    return tObservable.compose(RxLifecycleDelegate.<T>bindLifecycle(provider));
}
 
Example #12
Source File: MainActivity.java    From Reactive-Android-Programming with MIT License 5 votes vote down vote up
@NonNull
private Function<StockUpdate, MaybeSource<? extends StockUpdate>> skipTweetsThatDoNotContainKeywords(String[] trackingKeywords) {
    return update -> Observable.fromArray(trackingKeywords)
            .filter(keyword -> update.getTwitterStatus().toLowerCase().contains(keyword.toLowerCase()))
            .map(keyword -> update)
            .firstElement();
}
 
Example #13
Source File: MainActivity.java    From Reactive-Android-Programming with MIT License 5 votes vote down vote up
@NonNull
private Function<StockUpdate, MaybeSource<? extends StockUpdate>> skipTweetsThatDoNotContainKeywords(String[] trackingKeywords) {
    return update -> Observable.fromArray(trackingKeywords)
            .filter(keyword -> update.getTwitterStatus().toLowerCase().contains(keyword.toLowerCase()))
            .map(keyword -> update)
            .firstElement();
}
 
Example #14
Source File: UserProfileApiVerticle.java    From vertx-in-action with MIT License 5 votes vote down vote up
private MaybeSource<? extends JsonObject> insertExtraInfo(JsonObject extraInfo, String docId) {
  JsonObject query = new JsonObject().put("_id", docId);
  return mongoClient
    .rxFindOneAndUpdate("user", query, extraInfo)
    .onErrorResumeNext(err -> {
      return deleteIncompleteUser(query, err);
    });
}
 
Example #15
Source File: RxLifecycleTransformerEmpty.java    From pandroid with Apache License 2.0 4 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream;
}
 
Example #16
Source File: LifecycleTransformer.java    From Tangram-Android with MIT License 4 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(mObservable.firstElement());
}
 
Example #17
Source File: RxLifecycleTransformer.java    From pandroid with Apache License 2.0 4 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(mObservable.firstElement());
}
 
Example #18
Source File: LifecycleTransformer.java    From Tangram-Android with MIT License 4 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(mObservable.firstElement());
}
 
Example #19
Source File: LifecycleTransformer.java    From Tangram-Android with MIT License 4 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(mObservable.firstElement());
}
 
Example #20
Source File: DownloaderDelayTransformer.java    From NetDiscovery with Apache License 2.0 4 votes vote down vote up
@Override
public MaybeSource apply(Maybe upstream) {

    return request.getDownloadDelay() > 0 ? upstream.delay(request.getDownloadDelay(), TimeUnit.MILLISECONDS) : upstream;
}
 
Example #21
Source File: SpiderRunTransformer.java    From NetDiscovery with Apache License 2.0 4 votes vote down vote up
@Override
public MaybeSource apply(Maybe upstream) {

    return executor != null ? upstream.observeOn(Schedulers.from(executor)) : upstream;
}
 
Example #22
Source File: LifecycleTransformer.java    From recyclerview-binder with Apache License 2.0 4 votes vote down vote up
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(observable.firstElement());
}
 
Example #23
Source File: RequestContextCallableMaybe.java    From armeria with Apache License 2.0 4 votes vote down vote up
RequestContextCallableMaybe(MaybeSource<T> source, RequestContext assemblyContext) {
    this.source = source;
    this.assemblyContext = assemblyContext;
}
 
Example #24
Source File: RequestContextScalarCallableMaybe.java    From armeria with Apache License 2.0 4 votes vote down vote up
RequestContextScalarCallableMaybe(MaybeSource<T> source, RequestContext assemblyContext) {
    this.source = source;
    this.assemblyContext = assemblyContext;
}
 
Example #25
Source File: RequestContextMaybe.java    From armeria with Apache License 2.0 4 votes vote down vote up
RequestContextMaybe(MaybeSource<T> source, RequestContext assemblyContext) {
    this.source = source;
    this.assemblyContext = assemblyContext;
}
 
Example #26
Source File: TraceContextCallableMaybe.java    From brave with Apache License 2.0 4 votes vote down vote up
TraceContextCallableMaybe(
  MaybeSource<T> source, CurrentTraceContext contextScoper, TraceContext assembled) {
  this.source = source;
  this.contextScoper = contextScoper;
  this.assembled = assembled;
}
 
Example #27
Source File: TraceContextMaybe.java    From brave with Apache License 2.0 4 votes vote down vote up
TraceContextMaybe(
  MaybeSource<T> source, CurrentTraceContext contextScoper, TraceContext assembled) {
  this.source = source;
  this.contextScoper = contextScoper;
  this.assembled = assembled;
}