Java Code Examples for rx.subjects.AsyncSubject#onError()

The following examples show how to use rx.subjects.AsyncSubject#onError() . 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: WampClient.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Publishes an event under the given topic.
 * @param topic The topic that should be used for publishing the event
 * @param flags Additional publish flags if any. This can be null.
 * @param arguments The positional arguments for the published event
 * @param argumentsKw The keyword arguments for the published event.
 * These will only be taken into consideration if arguments is not null.
 * @return An observable that provides a notification whether the event
 * publication was successful. This contains either a single value (the
 * publication ID) and will then be completed or will be completed with
 * an error if the event could not be published.
 */
public Observable<Long> publish(final String topic, final EnumSet<PublishFlags> flags, final ArrayNode arguments,
    final ObjectNode argumentsKw)
{
    final AsyncSubject<Long> resultSubject = AsyncSubject.create();
    
    try {
        UriValidator.validate(topic, clientConfig.useStrictUriValidation());
    }
    catch (WampError e) {
        resultSubject.onError(e);
        return resultSubject;
    }
     
    stateController.scheduler().execute(new Runnable() {
        @Override
        public void run() {
            if (!(stateController.currentState() instanceof SessionEstablishedState)) {
                resultSubject.onError(new ApplicationError(ApplicationError.NOT_CONNECTED));
                return;
            }
            // Forward publish into the session
            SessionEstablishedState curState = (SessionEstablishedState)stateController.currentState();
            curState.performPublish(topic, flags, arguments, argumentsKw, resultSubject);
            
        }
    });
    return resultSubject;
}
 
Example 2
Source File: WampClient.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Performs a remote procedure call through the router.<br>
 * The function will return immediately, as the actual call will happen
 * asynchronously.
 * @param procedure The name of the procedure to call. Must be a valid WAMP
 * Uri.
 * @param flags Additional call flags if any. This can be null.
 * @param arguments A list of all positional arguments for the procedure call
 * @param argumentsKw All named arguments for the procedure call
 * @return An observable that provides a notification whether the call was
 * was successful and the return value. If the call is successful the
 * returned observable will be completed with a single value (the return value).
 * If the remote procedure call yields an error the observable will be completed
 * with an error.
 */
public Observable<Reply> call(final String procedure,
                              final EnumSet<CallFlags> flags,
                              final ArrayNode arguments,
                              final ObjectNode argumentsKw)
{
    final AsyncSubject<Reply> resultSubject = AsyncSubject.create();
    
    try {
        UriValidator.validate(procedure, clientConfig.useStrictUriValidation());
    }
    catch (WampError e) {
        resultSubject.onError(e);
        return resultSubject;
    }
     
    stateController.scheduler().execute(new Runnable() {
        @Override
        public void run() {
            if (!(stateController.currentState() instanceof SessionEstablishedState)) {
                resultSubject.onError(new ApplicationError(ApplicationError.NOT_CONNECTED));
                return;
            }

            // Forward performing actual call into the session
            SessionEstablishedState curState = (SessionEstablishedState)stateController.currentState();
            curState.performCall(procedure, flags, arguments, argumentsKw, resultSubject);
        }
    });
    return resultSubject;
}
 
Example 3
Source File: DefaultConfigurationProviderTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void shouldDelegateLoadingToSecondProviderIfFirstFails() throws Exception {
    ClusterFacade cluster = mock(ClusterFacade.class);
    Loader successLoader = mock(Loader.class);
    Loader errorLoader = mock(Loader.class);
    BucketConfig bucketConfig = mock(BucketConfig.class);
    when(bucketConfig.name()).thenReturn("bucket");
    when(successLoader.loadConfig(any(String.class), anyString(), anyString(), anyString()))
        .thenReturn(Observable.just(Tuple.create(LoaderType.Carrier, bucketConfig)));
    AsyncSubject<BucketConfig> errorSubject = AsyncSubject.create();
    when(errorLoader.loadConfig(any(String.class), anyString(), anyString(), anyString())).thenReturn((Observable) errorSubject);
    errorSubject.onError(new IllegalStateException());

    final Refresher refresher = mock(Refresher.class);
    when(refresher.configs()).thenReturn(Observable.<ProposedBucketConfigContext>empty());
    when(refresher.registerBucket(anyString(), nullable(String.class), nullable(String.class))).thenReturn(Observable.just(true));

    ConfigurationProvider provider = new DefaultConfigurationProvider(
        cluster,
        environment,
        Arrays.asList(errorLoader, successLoader),
        new HashMap<LoaderType, Refresher>() {{
            put(LoaderType.Carrier, refresher);
            put(LoaderType.HTTP, refresher);
        }}
    );

    provider.seedHosts(Sets.newSet("127.0.0.1"), true);
    Observable<ClusterConfig> configObservable = provider.openBucket("bucket", "password");
    ClusterConfig config = configObservable.toBlocking().first();
    assertTrue(config.hasBucket("bucket"));
    assertFalse(config.hasBucket("other"));
}
 
Example 4
Source File: WampClient.java    From jawampa with Apache License 2.0 5 votes vote down vote up
/**
 * Publishes an event under the given topic.
 * @param topic The topic that should be used for publishing the event
 * @param flags Additional publish flags if any. This can be null.
 * @param arguments The positional arguments for the published event
 * @param argumentsKw The keyword arguments for the published event.
 * These will only be taken into consideration if arguments is not null.
 * @return An observable that provides a notification whether the event
 * publication was successful. This contains either a single value (the
 * publication ID) and will then be completed or will be completed with
 * an error if the event could not be published.
 */
public Observable<Long> publish(final String topic, final EnumSet<PublishFlags> flags, final ArrayNode arguments,
    final ObjectNode argumentsKw)
{
    final AsyncSubject<Long> resultSubject = AsyncSubject.create();
    
    try {
        UriValidator.validate(topic, clientConfig.useStrictUriValidation());
    }
    catch (WampError e) {
        resultSubject.onError(e);
        return resultSubject;
    }
     
    boolean wasScheduled = stateController.tryScheduleAction(new Runnable() {
        @Override
        public void run() {
            if (!(stateController.currentState() instanceof SessionEstablishedState)) {
                resultSubject.onError(new ApplicationError(ApplicationError.NOT_CONNECTED));
                return;
            }
            // Forward publish into the session
            SessionEstablishedState curState = (SessionEstablishedState)stateController.currentState();
            curState.performPublish(topic, flags, arguments, argumentsKw, resultSubject);
            
        }
    });

    if (!wasScheduled) {
        resultSubject.onError(
            new ApplicationError(ApplicationError.CLIENT_CLOSED));
    }
    return resultSubject;
}
 
Example 5
Source File: WampClient.java    From jawampa with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a remote procedure call through the router.<br>
 * The function will return immediately, as the actual call will happen
 * asynchronously.
 * @param procedure The name of the procedure to call. Must be a valid WAMP
 * Uri.
 * @param flags Additional call flags if any. This can be null.
 * @param arguments A list of all positional arguments for the procedure call
 * @param argumentsKw All named arguments for the procedure call
 * @return An observable that provides a notification whether the call was
 * was successful and the return value. If the call is successful the
 * returned observable will be completed with a single value (the return value).
 * If the remote procedure call yields an error the observable will be completed
 * with an error.
 */
public Observable<Reply> call(final String procedure,
                              final EnumSet<CallFlags> flags,
                              final ArrayNode arguments,
                              final ObjectNode argumentsKw)
{
    final AsyncSubject<Reply> resultSubject = AsyncSubject.create();
    
    try {
        UriValidator.validate(procedure, clientConfig.useStrictUriValidation());
    }
    catch (WampError e) {
        resultSubject.onError(e);
        return resultSubject;
    }
     
    boolean wasScheduled = stateController.tryScheduleAction(new Runnable() {
        @Override
        public void run() {
            if (!(stateController.currentState() instanceof SessionEstablishedState)) {
                resultSubject.onError(new ApplicationError(ApplicationError.NOT_CONNECTED));
                return;
            }

            // Forward performing actual call into the session
            SessionEstablishedState curState = (SessionEstablishedState)stateController.currentState();
            curState.performCall(procedure, flags, arguments, argumentsKw, resultSubject);
        }
    });

    if (!wasScheduled) {
        resultSubject.onError(
            new ApplicationError(ApplicationError.CLIENT_CLOSED));
    }
    
    return resultSubject;
}