Java Code Examples for reactor.core.publisher.FluxSink#error()

The following examples show how to use reactor.core.publisher.FluxSink#error() . 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: TcpConnectorPeer.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void connectionClosing()
{
    connected = false;
    authenticated = false;

    // deactivate all interest in READ or WRITE operations
    setOpInterest(0);

    synchronized (openRpcs)
    {
        // preventing ConcurrentModificationException with "#apiCall's fluxSink.onDispose(...openRpcs.remove(...))
        Set<FluxSink<ByteArrayInputStream>> copyOpenRpcsSet = new HashSet<>(openRpcs.values());
        for (FluxSink<ByteArrayInputStream> rpcSink : copyOpenRpcsSet)
        {
            rpcSink.error(new PeerNotConnectedException());
        }
        openRpcs.clear(); // basically no-op, more for documentation purpose
    }
}
 
Example 2
Source File: ExecuteSinkConsumer.java    From retrofit2-reactor-adapter with Apache License 2.0 6 votes vote down vote up
@Override public void accept(FluxSink<Response<T>> sink) {
  // Since Call is a one-shot type, clone it for each new subscriber.
  Call<T> call = originalCall.clone();

  sink.onDispose(call::cancel);

  Response<T> response;
  try {
    response = call.execute();
  } catch (IOException e) {
    sink.error(e);
    return;
  }
  sink.next(response);
  sink.complete();
}
 
Example 3
Source File: ElementsStream.java    From redisson with Apache License 2.0 6 votes vote down vote up
private static <V> void take(final Callable<RFuture<V>> factory, final FluxSink<V> emitter, final AtomicLong counter, final AtomicReference<RFuture<V>> futureRef) {
    RFuture<V> future;
    try {
        future = factory.call();
    } catch (Exception e) {
        emitter.error(e);
        return;
    }
    futureRef.set(future);
    future.onComplete((res, e) -> {
        if (e != null) {
            emitter.error(e);
            return;
        }
        
        emitter.next(res);
        if (counter.decrementAndGet() == 0) {
            emitter.complete();
        }
        
        take(factory, emitter, counter, futureRef);
    });
}
 
Example 4
Source File: GenericEvent.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void closeStreamNoConnection(ObjectIdentifier objectIdentifier)
{
    FluxSink<T> sink = removeStream(objectIdentifier);

    if (sink != null)
    {
        sink.error(new PeerNotConnectedException());
    }
}
 
Example 5
Source File: TcpConnectorPeer.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void apiCallError(long apiCallId, Throwable exc)
{
    FluxSink<ByteArrayInputStream> rpcSink = openRpcs.get(apiCallId);
    if (rpcSink == null)
    {
        errorReporter.logDebug("Unexpected API call error received");
    }
    else
    {
        rpcSink.error(exc);
    }
}
 
Example 6
Source File: FluxMethodBridge.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private FluxInvocation(FluxSink<Object> sink, Object[] args) {
    StreamObserver<Object> grpcStreamObserver = new ClientResponseObserver<Object, Object>() {
        @Override
        public void beforeStart(ClientCallStreamObserver requestStream) {
            sink.onCancel(() -> requestStream.cancel("React subscription cancelled", null));
        }

        @Override
        public void onNext(Object value) {
            sink.next(value);
        }

        @Override
        public void onError(Throwable error) {
            sink.error(error);
        }

        @Override
        public void onCompleted() {
            sink.complete();
        }
    };

    Object[] grpcArgs = new Object[]{
            grpcArgPos < 0 ? Empty.getDefaultInstance() : args[grpcArgPos],
            grpcStreamObserver
    };

    GRPC_STUB invocationStub = handleCallMetadata(args)
            .withDeadline(Deadline.after(timeout.toMillis(), TimeUnit.MILLISECONDS));

    try {
        grpcMethod.invoke(invocationStub, grpcArgs);
    } catch (Exception e) {
        sink.error(e);
    }
}
 
Example 7
Source File: ReactorHeadTransformer.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
private boolean drainBuffer(FluxSink<T> emitter, Queue<Object> buffer) {
    for (Object next = buffer.poll(); !emitter.isCancelled() && next != null; next = buffer.poll()) {
        if (next == END_OF_STREAM_MARKER) {
            return false;
        }
        if (next instanceof ErrorWrapper) {
            emitter.error(((ErrorWrapper) next).cause);
            return false;
        }
        emitter.next((T) next);
    }
    return true;
}