Example usage for com.google.common.util.concurrent Runnables doNothing

List of usage examples for com.google.common.util.concurrent Runnables doNothing

Introduction

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

Prototype

public static Runnable doNothing() 

Source Link

Document

Returns a Runnable instance that does nothing when run.

Usage

From source file:com.salesforce.grpc.contrib.LambdaStreamObserver.java

public LambdaStreamObserver(Consumer<T> onNext, Consumer<Throwable> onError) {
    this(onNext, onError, Runnables.doNothing());
}

From source file:com.salesforce.grpc.contrib.LambdaStreamObserver.java

public LambdaStreamObserver(Consumer<T> onNext) {
    this(onNext, t -> {
        throw new OnErrorNotImplementedException(t);
    }, Runnables.doNothing());
}

From source file:com.google.inject.service.AsyncService.java

public synchronized final Future<State> start() {
    Preconditions.checkState(state != State.STOPPED, "Cannot restart a service that has been stopped");

    // Starts are idempotent.
    if (state == State.STARTED) {
        return new FutureTask<State>(Runnables.doNothing(), State.STARTED);
    }/* ww w .ja va 2  s  .c  o m*/

    return executor.submit(new Callable<State>() {
        public State call() {
            onStart();
            return state = State.STARTED;
        }
    });
}

From source file:com.google.inject.service.AsyncService.java

public synchronized final Future<State> stop() {
    Preconditions.checkState(state != null, "Must start this service before you stop it!");

    // Likewise, stops are idempotent.
    if (state == State.STOPPED) {
        return new FutureTask<State>(Runnables.doNothing(), State.STOPPED);
    }//ww  w . j  a  v a2  s. com

    return executor.submit(new Callable<State>() {
        public State call() {
            onStop();
            return state = State.STOPPED;
        }
    });
}

From source file:com.eucalyptus.objectstorage.pipeline.ObjectStorageRESTExceptionHandler.java

@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final ExceptionEvent e) throws Exception {
    final Channel ch = e.getChannel();
    Throwable cause = e.getCause();
    if (cause.getCause() != null) {
        // wrapped exception
        cause = cause.getCause();/*from  w  ww .  j  ava  2s.  co  m*/
    }

    // Get the request ID from the context and clear the context. If you cant log an exception and move on
    String requestId = null;
    HttpVersion httpVersion = HttpVersion.HTTP_1_0;
    Runnable cleanup = Runnables.doNothing();
    try {
        if (ch != null) {
            Context context = Contexts.lookup(ch);
            requestId = context.getCorrelationId();
            MappingHttpRequest request = context.getHttpRequest();
            httpVersion = request != null ? request.getProtocolVersion() : httpVersion;
            cleanup = () -> Contexts.clear(context);
        }
    } catch (Exception ex) {
        LOG.trace("Error getting request ID or clearing context", ex);
    }

    // Populate the error response fields
    final HttpResponseStatus status;
    final String code;
    final String resource;

    if (cause instanceof ObjectStorageException) {
        ObjectStorageException walrusEx = (ObjectStorageException) cause;
        status = walrusEx.getStatus();
        code = walrusEx.getCode();
        resource = walrusEx.getResource();
    } else if (cause instanceof WebServicesException) {
        WebServicesException webEx = (WebServicesException) cause;
        status = webEx.getStatus();
        code = CODE_UNKNOWN;
        resource = null;
    } else {
        status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
        code = CODE_UNKNOWN;
        resource = null;
    }

    final ObjectStorageErrorMessageType errorResponse = new ObjectStorageErrorMessageType();
    errorResponse.setResource(Strings.nullToEmpty(resource));
    errorResponse.setMessage(Strings.nullToEmpty(cause.getMessage()));
    errorResponse.setCode(Strings.nullToEmpty(code));
    errorResponse.setRequestId(Strings.nullToEmpty(requestId));
    errorResponse.setStatus(status);

    if (cause instanceof InvalidAccessKeyIdException) {
        errorResponse.setAccessKeyId(((InvalidAccessKeyIdException) cause).getAccessKeyId());
        errorResponse.setResource(null);
    }

    if (cause instanceof SignatureDoesNotMatchException) {
        SignatureDoesNotMatchException ex = (SignatureDoesNotMatchException) cause;
        errorResponse.setAccessKeyId(ex.getAccessKeyId());
        errorResponse.setResource(null);
        errorResponse.setStringToSign(Strings.nullToEmpty(ex.getStringToSign()));
        errorResponse.setSignatureProvided(Strings.nullToEmpty(ex.getSignatureProvided()));
        if (ex.getStringToSign() != null)
            errorResponse.setStringToSignBytes(stringToByteString(ex.getStringToSign()));
        errorResponse.setCanonicalRequest(Strings.nullToEmpty(ex.getCanonicalRequest()));
        if (ex.getCanonicalRequest() != null)
            errorResponse.setCanonicalRequestBytes(stringToByteString(ex.getCanonicalRequest()));
    }

    if (ctx.getChannel().isConnected()) {
        final MappingHttpResponse response = new MappingHttpResponse(httpVersion);
        response.setStatus(status);
        response.setMessage(errorResponse);
        response.setCorrelationId(requestId);
        errorResponse.setCorrelationId(requestId);
        final ChannelFuture writeFuture = Channels.future(ctx.getChannel());
        writeFuture.addListener(ChannelFutureListener.CLOSE);
        response.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
        Channels.write(ctx, writeFuture, response);
        cleanup.run();
    } else {
        ctx.sendDownstream(e);
    }
}

From source file:org.gradle.cache.internal.FixedExclusiveModeCrossProcessCacheAccess.java

@Override
public Runnable acquireFileLock() {
    return Runnables.doNothing();
}

From source file:com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog.java

/**
 * Instantiates a new standard input dialog.
 *
 * @param owner       Dialog owner/* w  w w. j a va2 s.c om*/
 * @param modal       modality type
 * @param iconManager The icon manager to use for validating text fields.
 * @param title       Dialog title
 * @param message     Dialog message
 */
public StandardInputDialog(final Window owner, final ModalityType modal, final IconManager iconManager,
        final String title, final String message, final Consumer<String> save) {
    this(owner, modal, iconManager, title, message, s -> {
        save.accept(s);
        return true;
    }, Runnables.doNothing());
}

From source file:org.gradle.cache.internal.InMemoryDecoratedCache.java

@Override
public V get(final K key, final Transformer<? extends V, ? super K> producer, final Runnable completion) {
    final AtomicReference<Runnable> completionRef = new AtomicReference<Runnable>(completion);
    Object value;/*from w w  w  . jav  a  2  s. c o  m*/
    try {
        value = inMemoryCache.getIfPresent(key);
        final boolean wasNull = value == NULL;
        if (wasNull) {
            inMemoryCache.invalidate(key);
        } else if (value != null) {
            return Cast.uncheckedCast(value);
        }
        value = inMemoryCache.get(key, new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                if (!wasNull) {
                    Object out = delegate.get(key);
                    if (out != null) {
                        return out;
                    }
                }
                V value = producer.transform(key);
                delegate.putLater(key, value, completion);
                completionRef.set(Runnables.doNothing());
                return value;
            }
        });
    } catch (UncheckedExecutionException e) {
        throw UncheckedException.throwAsUncheckedException(e.getCause());
    } catch (ExecutionException e) {
        throw UncheckedException.throwAsUncheckedException(e.getCause());
    } finally {
        completionRef.get().run();
    }
    if (value == NULL) {
        return null;
    } else {
        return Cast.uncheckedCast(value);
    }
}

From source file:com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog.java

/**
 * Instantiates a new standard input dialog.
 *
 * @param owner       Dialog owner//from  www  . ja va2s  .co m
 * @param modal       modality type
 * @param iconManager The icon manager to use for validating text fields.
 * @param title       Dialog title
 * @param message     Dialog message
 */
public StandardInputDialog(final Window owner, final ModalityType modal, final IconManager iconManager,
        final String title, final String message, final Function<String, Boolean> save) {
    this(owner, modal, iconManager, title, message, save, Runnables.doNothing());
}

From source file:com.google.gerrit.server.notedb.RepoSequence.java

public RepoSequence(GitRepositoryManager repoManager, Project.NameKey projectName, String name, Seed seed,
        int batchSize) {
    this(repoManager, projectName, name, seed, batchSize, Runnables.doNothing(), RETRYER);
}