Package rx.functions

Examples of rx.functions.Action0


                     }, new Action1<Throwable>() {
                         @Override
                         public void call(Throwable e) {
                             System.out.println("failed to subscribe 'onhello': " + e);
                         }
                     }, new Action0() {
                         @Override
                         public void call() {
                             System.out.println("'onhello' subscription ended");
                         }
                     });
                   
                    // REGISTER a procedure for remote calling
                    addProcSubscription = client.registerProcedure("com.example.add2")
                                                .observeOn(rxScheduler)
                                                .subscribe(new Action1<Request>() {
                        @Override
                        public void call(Request request) {
                            if (request.arguments() == null || request.arguments().size() != 2
                             || !request.arguments().get(0).canConvertToLong()
                             || !request.arguments().get(1).canConvertToLong())
                            {
                                try {
                                    request.replyError(new ApplicationError(ApplicationError.INVALID_PARAMETER));
                                } catch (ApplicationError e) { }
                            }
                            else {
                                long a = request.arguments().get(0).asLong();
                                long b = request.arguments().get(1).asLong();
                                request.reply(a + b);
                            }
                        }
                    }, new Action1<Throwable>() {
                        @Override
                        public void call(Throwable e) {
                            System.out.println("failed to register procedure: " + e);
                        }
                    }, new Action0() {
                        @Override
                        public void call() {
                            System.out.println("procedure subscription ended");
                        }
                    });
                   
                    // PUBLISH and CALL every second .. forever
                    counter = 0;
                    counterPublication = rxScheduler.createWorker().schedulePeriodically(new Action0() {
                        @Override
                        public void call() {
                            // PUBLISH an event
                            final int published = counter;
                            client.publish("com.example.oncounter", published)
                                  .observeOn(rxScheduler)
                                  .subscribe(new Action1<Long>() {
                                    @Override
                                    public void call(Long t1) {
                                        System.out.println("published to 'oncounter' with counter " + published);
                                    }
                                }, new Action1<Throwable>() {
                                    @Override
                                    public void call(Throwable e) {
                                        System.out.println("Error during publishing to 'oncounter': " + e);
                                    }
                                });
                           
                            // CALL a remote procedure
                            client.call("com.example.mul2", Long.class, counter, 3)
                                  .observeOn(rxScheduler)
                                  .subscribe(new Action1<Long>() {
                                    @Override
                                    public void call(Long result) {
                                        System.out.println("mul2() called with result: " + result);
                                    }
                                }, new Action1<Throwable>() {
                                    @Override
                                    public void call(Throwable e) {
                                        boolean isProcMissingError = false;
                                        if (e instanceof ApplicationError) {
                                            if (((ApplicationError) e).uri().equals("wamp.error.no_such_procedure"))
                                                isProcMissingError = true;
                                        }
                                        if (!isProcMissingError) {
                                            System.out.println("call of mul2() failed: " + e);
                                        }
                                    }
                                });
                           
                            counter++;
                        }
                    }, TIMER_INTERVAL, TIMER_INTERVAL, TimeUnit.MILLISECONDS);
                }
                else if (t1 == WampClient.Status.Disconnected) {
                    closeSubscriptions();
                }
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable t) {
                System.out.println("Session ended with error " + t);
            }
        }, new Action0() {
            @Override
            public void call() {
                System.out.println("Session ended normally");
            }
        });
View Full Code Here


        }
    }

    private void scheduleForRetry(final CouchbaseRequest request) {
        final AtomicReference<Subscription> subscription = new AtomicReference<Subscription>();
        subscription.set(worker.schedule(new Action0() {
            @Override
            public void call() {
                cluster.send(request);
                subscription.get().unsubscribe();
            }
View Full Code Here

        LOGGER.debug("Config for bucket \"" + config.name() + "\" marked as tainted, starting polling.");
        Observable.create(new Observable.OnSubscribe<Object>() {
            @Override
            public void call(final Subscriber<? super Object> subscriber) {
                Subscription subscription = environment.scheduler().createWorker().schedulePeriodically(new Action0() {
                    @Override
                    public void call() {
                        final InetAddress hostname = config.nodes().get(0).hostname();
                        cluster()
                            .<GetBucketConfigResponse>send(new GetBucketConfigRequest(config.name(), hostname))
View Full Code Here

        private boolean isWaitingForResponse;

        private long responseReceiveStartTimeMillis; // Reset every time we receive a header.

        private ResponseState() {
            contentSubject = UnicastContentSubject.createWithoutNoSubscriptionTimeout(new Action0() {
                @Override
                public void call() {
                    if (null != connection) {
                        connection.close();
                    }
View Full Code Here

                                                                              httpClientConfig.getResponseSubscriptionTimeoutMs()));

        if (followRedirect) {
            toReturn = toReturn.lift(new RedirectOperator<I, O>(request, this, httpClientConfig));
        }
        return toReturn.take(1).finallyDo(new Action0() {
            @Override
            public void call() {
                eventsSubject.onEvent(HttpClientMetricsEvent.REQUEST_PROCESSING_COMPLETE,
                                      Clock.onEndMillis(startTimeMillis));
            }
View Full Code Here

                                                 eventsSubject.onEvent(HttpClientMetricsEvent.RESPONSE_FAILED,
                                                                       Clock.onEndMillis(startTimeMillis), throwable);
                                             }
                                         })
                                         .subscribe(child)); //subscribe the child for response.
                        request.doOnWriteComplete(new Action0() {
                            @Override
                            public void call() {
                                connection.flush().subscribe(new Observer<Void>() {
                                    @Override
                                    public void onCompleted() {
View Full Code Here

                public void call(Subscriber<? super String> subscriber) {
                    try {
                        String nextLine;
                        final LineNumberReader reader =
                                new LineNumberReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(file))));
                        subscriber.add(Subscriptions.create(new Action0() {
                            @Override
                            public void call() {
                                try {
                                    reader.close();
                                } catch (IOException e) {
View Full Code Here

         * If we do it before getting the existingListener then the write that happens after the flush() from the user
         * will be contained in the retrieved listener and hence we will wait till the next flush() finish.
         */
        nettyChannel.flush();
        return existingListener.asObservable()
                               .doOnCompleted(new Action0() {
                                   @Override
                                   public void call() {
                                       eventsSubject.onEvent(metricEventProvider.getFlushSuccessEvent(),
                                                             Clock.onEndMillis(startTimeMillis));
                                   }
View Full Code Here

                                 final ClientConnectionFactory<I, O,? extends ObservableConnection<I, O>> connectionFactory) {
        final long startTimeMillis = Clock.newStartTimeMillis();
        eventsSubject.onEvent(ClientMetricsEvent.CONNECT_START);
        final ChannelFuture connectFuture = clientBootstrap.connect(serverInfo.getHost(), serverInfo.getPort());

        subscriber.add(Subscriptions.create(new Action0() {
            @Override
            public void call() {
                if (!connectFuture.isDone()) {
                    connectFuture.cancel(true); // Unsubscribe here means, no more connection is required. A close on connection is explicit.
                }
View Full Code Here

        throwIfErrorOccured(exception);
    }

    @Override
    public Subscription subscribe(final MetricEventsListener<? extends E> listener) {
        Subscription subscription = Subscriptions.create(new Action0() {
            @Override
            public void call() {
                listeners.remove(listener);
            }
        });
View Full Code Here

TOP

Related Classes of rx.functions.Action0

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.