rx.exceptions.MissingBackpressureException Java Examples

The following examples show how to use rx.exceptions.MissingBackpressureException. 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: OrderedMerge.java    From rxjava-extras with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(T t) {
    if (done) {
        return;
    }
    try {
        queue.onNext(NotificationLite.next(t));
    } catch (MissingBackpressureException mbe) {
        try {
            onError(mbe);
        } finally {
            unsubscribe();
        }
        return;
    } catch (IllegalStateException ex) {
        if (!isUnsubscribed()) {
            try {
                onError(ex);
            } finally {
                unsubscribe();
            }
        }
        return;
    }
    parent.emit();
}
 
Example #2
Source File: RxRingBuffer.java    From rxjava-extras with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param o the value to buffer
 * @throws MissingBackpressureException
 *             if more onNext are sent than have been requested
 */
public void onNext(Object o) throws MissingBackpressureException {
    boolean iae = false;
    boolean mbe = false;
    synchronized (this) {
        Queue<Object> q = queue;
        if (q != null) {
            mbe = !q.offer(NotificationLite.next(o));
        } else {
            iae = true;
        }
    }

    if (iae) {
        throw new IllegalStateException("This instance has been unsubscribed and the queue is no longer usable.");
    }
    if (mbe) {
        throw new MissingBackpressureException();
    }
}
 
Example #3
Source File: SortedMerge.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(T t) {
    try {
        queue.onNext(NotificationLite.next(t));
    } catch (MissingBackpressureException mbe) {
        try {
            onError(mbe);
        } finally {
            unsubscribe();
        }
        return;
    } catch (IllegalStateException ex) {
        if (!isUnsubscribed()) {
            try {
                onError(ex);
            } finally {
                unsubscribe();
            }
        }
        return;
    }
    parent.emit();
}
 
Example #4
Source File: RxValve.java    From RXBus with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(T t) {
    if (!queue.offer(NotificationLite.next(t))) {
        onError(new MissingBackpressureException());
    } else {
        drain();
    }
}
 
Example #5
Source File: PublishSubjectRaceTest.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Test
public void racy() throws Exception {
    Worker worker = Schedulers.computation().createWorker();
    try {
        for (int i = 0; i < 1000; i++) {
            AtomicInteger wip = new AtomicInteger(2);
    
            PublishSubject<Integer> ps = PublishSubject.create();
            
            AssertableSubscriber<Integer> as = ps.test(1);
            
            CountDownLatch cdl = new CountDownLatch(1);
            
            worker.schedule(() -> {
                if (wip.decrementAndGet() != 0) {
                    while (wip.get() != 0) ;
                }
                ps.onNext(1);
                
                cdl.countDown();
            });
            if (wip.decrementAndGet() != 0) {
                while (wip.get() != 0) ;
            }
            ps.onNext(1);
            
            cdl.await();
            
            as.assertFailure(MissingBackpressureException.class, 1);
        }
    } finally {
        worker.unsubscribe();
    }
}
 
Example #6
Source File: PublishSubjectRaceTest.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Test
public void nonRacy() throws Exception {
    Worker worker = Schedulers.computation().createWorker();
    try {
        for (int i = 0; i < 1000; i++) {
            AtomicInteger wip = new AtomicInteger(2);
    
            Subject<Integer, Integer> ps = PublishSubject.<Integer>create().toSerialized();
            
            AssertableSubscriber<Integer> as = ps.test(1);
            
            CountDownLatch cdl = new CountDownLatch(1);
            
            worker.schedule(() -> {
                if (wip.decrementAndGet() != 0) {
                    while (wip.get() != 0) ;
                }
                ps.onNext(1);
                
                cdl.countDown();
            });
            if (wip.decrementAndGet() != 0) {
                while (wip.get() != 0) ;
            }
            ps.onNext(1);
            
            cdl.await();
            
            as.assertFailure(MissingBackpressureException.class, 1);
        }
    } finally {
        worker.unsubscribe();
    }
}
 
Example #7
Source File: MesosClientBackpressureIntegrationTest.java    From mesos-rxjava with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void testBurstyObservable_missingBackpressureException() throws Throwable {
    final String subscribedMessage = "{\"type\": \"SUBSCRIBED\",\"subscribed\": {\"framework_id\": {\"value\":\"12220-3440-12532-2345\"},\"heartbeat_interval_seconds\":15.0}";
    final String heartbeatMessage = "{\"type\":\"HEARTBEAT\"}";
    final byte[] hmsg = heartbeatMessage.getBytes(StandardCharsets.UTF_8);
    final byte[] hbytes = String.format("%d\n", heartbeatMessage.getBytes().length).getBytes(StandardCharsets.UTF_8);

    final RequestHandler<ByteBuf, ByteBuf> handler = (request, response) -> {
        response.setStatus(HttpResponseStatus.OK);
        response.getHeaders().setHeader("Content-Type", "text/plain;charset=utf-8");
        writeRecordIOMessage(response, subscribedMessage);
        for (int i = 0; i < 20000; i++) {
            response.writeBytes(hbytes);
            response.writeBytes(hmsg);
        }
        return response.flush();
    };
    final HttpServer<ByteBuf, ByteBuf> server = RxNetty.createHttpServer(0, handler);
    server.start();
    final URI uri = URI.create(String.format("http://localhost:%d/api/v1/scheduler", server.getServerPort()));
    final MesosClient<String, String> client = createClientForStreaming(uri).build();

    try {
        client.openStream().await();
        fail("Expect an exception to be propagated up due to backpressure");
    } catch (MissingBackpressureException e) {
        // expected
        e.printStackTrace();
        assertThat(e.getMessage()).isNullOrEmpty();
    } finally {
        server.shutdown();
    }
}
 
Example #8
Source File: OperatorParallelMerge.java    From RxJavaParallel with Apache License 2.0 5 votes vote down vote up
private void handleScalarSynchronousObservableWithRequestLimits(SingleValueParallelObservable<? extends T> t) {

            boolean emitted = false;
            try {
                //Assume we can proceed by decrementing requested.  If we're wrong, "put it back" in the else block.
                if (MergeProducer.REQUESTED.decrementAndGet(mergeProducer) >= 0) {
                    emitted = true;
                    actual.onNext(t.get());

                    // we handle this Observable without ever incrementing the wip or touching other machinery so just return here
                    return;
                } else {
                    MergeProducer.REQUESTED.incrementAndGet(mergeProducer);
                }

            } finally {
                drainQueuesIfNeeded();

                if (emitted) {
                    request(1);
                }
            }

            // if we didn't return above we need to enqueue
            // enqueue the values for later delivery
            //TODO: This is the only place we actually use the scalarValueQueue - can we get rid of it entirely?
            initScalarValueQueueIfNeeded();
            try {
                scalarValueQueue.onNext(t.get());
                missedEmitting.incrementAndGet();
            } catch (MissingBackpressureException e) {
                onError(e);
            }
        }
 
Example #9
Source File: OperatorParallelMerge.java    From RxJavaParallel with Apache License 2.0 5 votes vote down vote up
private void enqueue(T t, boolean complete) {
    try {
        if (complete) {
            q.onCompleted();
        } else {
            q.onNext(t);
        }
    } catch (MissingBackpressureException e) {
        onError(e);
    }
}