Package rx

Examples of rx.Subscription


    Observable<Long> ob=timer.setPeriodic(50).take(3);

    final long startTime=System.currentTimeMillis();

    // Expect 3 values
    final Subscription sub=assertCountThen(ob,new Action0() {
      public void call() {
        long totalTime=System.currentTimeMillis()-startTime;
        System.out.println("Test complete after "+(totalTime)+"ms");
        // Ensure the total time is withing 20% of the expected value
        assertTrue("Time within 20% of expected",Math.abs((totalTime/(50*3))-1)<0.2);
 
View Full Code Here


        if (shouldSubscribe) {
            // register a subscription that will shut this down
            connection.call(Subscriptions.create(new Action0() {
                @Override
                public void call() {
                    Subscription s;
                    synchronized (guard) {
                        s = subscription;
                        subscription = null;
                        connectedSubject.set(null);
                    }
                    if (s != null) {
                        s.unsubscribe();
                    }
                }
            }));

            // now that everything is hooked up let's subscribe
View Full Code Here

      SlottingStrategy<T> slottingStrategy = configuration.getSlottingStrategy();
      final Func1<SlotValuePair<T>,Boolean> slotAssignmentFunction = slottingStrategy.slottingFunction();
      final Encoder<T> encoder = configuration.getEncoder();
     
      // write RxEvents over the connection   
      Subscription subscription = observable.
          filter(filterFunction.call(event.getSubscribeParameters()))
          // setup slotting
          .map(new Func1<T, SlotValuePair<T>>(){
            @Override
            public SlotValuePair<T> call(
View Full Code Here

          @Override
          public Observable<Void> call(RemoteRxEvent event) {
            if (event.getType() == RemoteRxEvent.Type.subscribed){
              return handleSubscribeRequest(event, connection, slottingStrategyReference, unsubscribeCallbackReference);
            }else if (event.getType() == RemoteRxEvent.Type.unsubscribed){
              Subscription subscription = unsubscribeCallbackReference.getValue();
              if (subscription != null){
                subscription.unsubscribe();
              }
              releaseSlot(slottingStrategyReference.getValue(), connection);
              serverMetrics.incrementUnsubscribedCount();
              logger.debug("Connection: "+connection.toString()+" unsubscribed");
            }
View Full Code Here

                // don't schedule, we are unsubscribed
                return Subscriptions.empty();
            }

            final AtomicReference<Subscription> sf = new AtomicReference<Subscription>();
            Subscription s = Subscriptions.from(threadPool.getExecutor().submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (subscription.isUnsubscribed()) {
                            return;
                        }
                        action.call();
                    } finally {
                        // remove the subscription now that we're completed
                        Subscription s = sf.get();
                        if (s != null) {
                            subscription.remove(s);
                        }
                    }
                }
View Full Code Here

    super(new Func1<Observer<T>, Subscription>() {
      @Override
      public Subscription call(Observer<T> observer) {
        final rx.operators.AtomicObservableSubscription subscription = new AtomicObservableSubscription();

        subscription.wrap(new Subscription() {
          @Override
          public void unsubscribe() {
            // on unsubscribe remove it from the map of outbound observers
            // to notify
            observers.remove(subscription);
View Full Code Here

        RxEventBus rxEventBus = new RxEventBus(eventBus);
       
        final CountDownLatch completion = new CountDownLatch(1);
        final CountDownLatch counter = new CountDownLatch(10);
       
        Subscription sub = rxEventBus.asObservable(Long.class)
            .doOnCompleted(new Action0() {
                @Override
                public void call() {
                    System.out.println("Done");
                    completion.countDown();
                }
            })
            .subscribe(new Action1<Long>() {
                @Override
                public void call(Long t1) {
                    System.out.println(t1);
                    counter.countDown();
                }
            });
       
        for (long i = 0; i < 10; i++) {
            eventBus.publish(i);
        }
       
        Assert.assertTrue(counter.await(1, TimeUnit.SECONDS));
       
        sub.unsubscribe();
       
        Assert.assertTrue(completion.await(1, TimeUnit.SECONDS));
       
    }
View Full Code Here

    private Observable<Void> handleHystrixRequest(final HttpServerResponse<O> response) {
        writeHeaders(response);

        final Subject<Void, Void> subject = PublishSubject.create();
        final MultipleAssignmentSubscription subscription = new MultipleAssignmentSubscription();
        Subscription actionSubscription = Observable.timer(0, interval, TimeUnit.MILLISECONDS, Schedulers.computation())
                .subscribe(new Action1<Long>() {
                    @Override
                    public void call(Long tick) {
                        if (!response.getChannelHandlerContext().channel().isOpen()) {
                            subscription.unsubscribe();
View Full Code Here

      @Override
      public Subscription onSubscribe(Observer<? super T> observer) {
        final rx.operators.SafeObservableSubscription subscription = new
          SafeObservableSubscription();

        subscription.wrap(new Subscription() {
          @Override
          public void unsubscribe() {
            // on unsubscribe remove it from the map of outbound observers
            // to notify
            observers.remove(subscription);
View Full Code Here

TOP

Related Classes of rx.Subscription

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.