Example usage for com.google.common.util.concurrent SettableFuture setException

List of usage examples for com.google.common.util.concurrent SettableFuture setException

Introduction

In this page you can find the example usage for com.google.common.util.concurrent SettableFuture setException.

Prototype

@Override
    public boolean setException(Throwable throwable) 

Source Link

Usage

From source file:com.groupon.mesos.util.HttpProtocolSender.java

@Override
public void onFailure(final Request request, final IOException e) {
    final Object tag = request.tag();
    checkState(tag != null, "saw a request with null tag");

    final SettableFuture<Void> future = inFlight.remove(tag);
    checkState(future != null, "Saw tag %s but not in in flight map", tag);
    future.setException(e);

    LOG.warn("While running %s %s: %s", request.method(), request.urlString(), e.getMessage());
}

From source file:org.opendaylight.controller.cluster.datastore.messages.DataExists.java

@Override
public void processResponse(Object response, SettableFuture<Boolean> returnFuture) {
    if (DataExistsReply.isSerializedType(response)) {
        returnFuture.set(Boolean.valueOf(DataExistsReply.fromSerializable(response).exists()));
    } else {//  ww w .ja v a 2  s  .  c  o m
        returnFuture.setException(
                new ReadFailedException("Invalid response checking exists for path " + getPath()));
    }
}

From source file:org.testfx.toolkit.impl.ApplicationServiceImpl.java

@Override
public Future<Void> init(ApplicationFixture applicationFixture) {
    // Should be called in TestFX launcher thread.
    SettableFuture<Void> future = SettableFuture.create();
    try {//from   ww  w  . ja  va  2 s  . c o m
        applicationFixture.init();
        future.set(null);
    } catch (Exception exception) {
        future.setException(exception);
    }
    return future;
}

From source file:org.opendaylight.controller.cluster.databroker.actors.dds.RemoteProxyTransaction.java

private void failFuture(final SettableFuture<?> future, final Response<?, ?> response) {
    future.setException(recordFailedResponse(response));
}

From source file:com.continuuity.loom.common.queue.internal.ElementsTrackingQueue.java

@Override
public ListenableFuture<String> add(Element element) {
    Preconditions.checkArgument(element != null, "element to add must not be null");
    SettableFuture<String> result = addConsumingResultToWaitFor(element.getId());
    if (!elementsTracking.addToQueue(element)) {
        result.setException(new RuntimeException("failed to add element to a queue " + element.toString()));
        stopWaitingForConsumingResult(element.getId());
    }/*ww w  .j a  va 2 s  .  c om*/

    return result;
}

From source file:com.microsoft.windowsazure.mobileservices.http.MobileServiceHttpClient.java

/**
 * Makes a request over HTTP//from w  w w  .j  av a 2 s  .c  om
 *
 * @param path           The path of the request URI
 * @param content        The string to send as the request body
 * @param httpMethod     The HTTP Method used to invoke the API
 * @param requestHeaders The extra headers to send in the request
 * @param parameters     The query string parameters sent in the request
 * @param features       The features used in the request
 * @throws java.io.UnsupportedEncodingException If the content cannot be converted into a byte array.
 */
public ListenableFuture<ServiceFilterResponse> request(String path, String content, String httpMethod,
        List<Pair<String, String>> requestHeaders, List<Pair<String, String>> parameters,
        EnumSet<MobileServiceFeatures> features) {
    try {
        byte[] byteContent = null;

        if (content != null) {
            byteContent = content.getBytes(MobileServiceClient.UTF8_ENCODING);
        }

        return this.request(path, byteContent, httpMethod, requestHeaders, parameters, features);
    } catch (UnsupportedEncodingException e) {
        SettableFuture<ServiceFilterResponse> future = SettableFuture.create();
        future.setException(e);
        return future;
    }
}

From source file:com.android.builder.internal.packaging.zip.compress.ExecutorCompressor.java

@NonNull
@Override/* w  w w .  j a v a  2s  . c  o  m*/
public ListenableFuture<CompressionResult> compress(@NonNull final CloseableByteSource source) {
    final SettableFuture<CompressionResult> future = SettableFuture.create();
    mExecutor.execute(() -> {
        try {
            future.set(immediateCompress(source));
        } catch (Exception e) {
            future.setException(e);
        }
    });

    return future;
}

From source file:org.openqa.selenium.safari.WebSocketConnection.java

public WebSocketConnection(Channel channel) {
    this.channel = channel;

    this.channel.getPipeline().addLast("websocket-handler", new SimpleChannelUpstreamHandler() {
        @Override/*www . j a  v  a  2s  .  c om*/
        public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
            if (!(e.getMessage() instanceof WebSocketFrame)) {
                ctx.sendUpstream(e);
            } else {
                handleWebSocketFrame((WebSocketFrame) e.getMessage());
            }
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
            handleUncaughtException(e.getCause());
        }
    });

    this.channel.getCloseFuture().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            SettableFuture<String> response = pendingResponse.getAndSet(null);
            if (null != response) {
                response.setException(new ConnectionClosedException("The underlying channel was closed"));
            }
        }
    });
}

From source file:io.crate.executor.transport.task.elasticsearch.EsJobContextTask.java

@Override
public void execute(RowReceiver rowReceiver) {
    assert builder != null : "Context must be created first";
    SettableFuture<TaskResult> result = results.get(0);
    try {/*from  w ww  .java2s .  c o m*/
        JobExecutionContext ctx = jobContextService.createContext(builder);
        ctx.start();
    } catch (Throwable throwable) {
        result.setException(throwable);
    }
    JobTask.resultToRowReceiver(result, rowReceiver);
}

From source file:io.v.v23.InputChannels.java

private static <T> FutureCallback<T> newCallbackForCallback(final InputChannel<T> channel,
        final SettableFuture<Void> future, final InputChannelCallback<? super T> callback,
        final Executor executor) {
    return new FutureCallback<T>() {
        @Override//from   w w  w.j  a  v a 2 s.  co  m
        public void onSuccess(T result) {
            ListenableFuture<Void> done = callback.onNext(result);
            if (done == null) {
                done = Futures.immediateFuture(null);
            }
            Futures.addCallback(Futures.transform(done, new AsyncFunction<Void, T>() {
                @Override
                public ListenableFuture<T> apply(Void input) throws Exception {
                    return channel.recv();
                }
            }), newCallbackForCallback(channel, future, callback, executor), executor);
        }

        @Override
        public void onFailure(Throwable t) {
            if (t instanceof EndOfFileException) {
                future.set(null);
                return;
            }
            future.setException(t);
        }
    };
}