Example usage for org.apache.commons.lang3.concurrent ConcurrentUtils constantFuture

List of usage examples for org.apache.commons.lang3.concurrent ConcurrentUtils constantFuture

Introduction

In this page you can find the example usage for org.apache.commons.lang3.concurrent ConcurrentUtils constantFuture.

Prototype

public static <T> Future<T> constantFuture(final T value) 

Source Link

Document

Gets an implementation of Future that is immediately done and returns the specified constant value.

Usage

From source file:com.netflix.hystrix.contrib.javanica.collapser.CollapserResult.java

/**
 * This method is used in asynchronous calls.
 *
 * @param <T> the result type//from w ww  .j a va  2  s . co m
 * @return fake instance of Future
 */
public static <T> Future<T> async() {
    return ConcurrentUtils.constantFuture(null);
}

From source file:com.microsoft.azure.storage.DictionaryKeyResolver.java

@Override
public Future<IKey> resolveKeyAsync(String keyId) {
    return ConcurrentUtils.constantFuture(this.keys.get(keyId));
}

From source file:com.microsoft.azure.storage.util.LocalResolver.java

/**
 * Map from a keyID to a key. This will be called when decrypting. The data
 * to decrypt will include the keyID used to encrypt it.
 * /*  w w w .ja v  a  2  s. co m*/
 * @param keyId
 *            The KeyID to map to a key
 */
@Override
public Future<IKey> resolveKeyAsync(String keyId) {
    return ConcurrentUtils.constantFuture(this.keys.get(keyId));
}

From source file:com.epimorphics.registry.util.RunShell.java

public Future<Boolean> run(String... args) {
    String[] argA = new String[2 + args.length];
    argA[0] = DEFAULT_SHELL;/*www  . j a v a 2s.  c o  m*/
    argA[1] = scriptFile;
    for (int i = 0; i < args.length; i++) {
        argA[2 + i] = args[i];
    }
    ProcessBuilder scriptPB = new ProcessBuilder(argA);
    scriptPB.redirectErrorStream(true);

    try {
        Process scriptProcess = scriptPB.start();
        Future<Boolean> scriptStatus = TimerManager.get().submit(new TrackShell(scriptProcess));
        return scriptStatus;
    } catch (IOException e) {
        log.error("Error invoking script: " + scriptFile, e);
        return ConcurrentUtils.constantFuture(false);
    }
}

From source file:com.yahoo.bard.webservice.druid.client.impl.AsyncDruidWebServiceImplWrapper.java

/**
 * Capture arguments to test for expected values.
 * Since there is no response, the future will hold a null value.
 *
 * @param success  callback for handling successful requests.
 * @param error  callback for handling http errors.
 * @param failure  callback for handling exception failures.
 * @param requestBuilder  The bound request builder for the request to be sent.
 * @param timerName  The name that distinguishes this request as part of a druid query or segment metadata request
 * @param outstanding  The counter that keeps track of the outstanding (in flight) requests for the top level query
 *
 * @return a future with a null response.
 *//* www.  j  a  va2s .c  om*/
@Override
protected Future<Response> sendRequest(final SuccessCallback success, final HttpErrorCallback error,
        final FailureCallback failure, final BoundRequestBuilder requestBuilder, final String timerName,
        final AtomicLong outstanding) {
    this.request = requestBuilder.build();
    return ConcurrentUtils.constantFuture(null);
}

From source file:ch.cyberduck.core.AbstractController.java

/**
 * Will queue up the <code>BackgroundAction</code> to be run in a background thread
 *
 * @param action The runnable to execute in a secondary thread
 *//*from   ww  w. java2  s.  c o  m*/
@Override
public <T> Future<T> background(final BackgroundAction<T> action) {
    if (registry.contains(action)) {
        log.warn(String.format("Skip duplicate background action %s found in registry", action));
        return ConcurrentUtils.constantFuture(null);
    }
    return DefaultBackgroundExecutor.get().execute(this, registry, action);
}

From source file:com.mcleodmoores.mvn.natives.BuildMojoTest.java

public void testExecute() throws Exception {
    final BuildMojo instance = executeInstance();
    final ProcessExecutor executor = Mockito.mock(ProcessExecutor.class);
    Mockito.when(executor.exec("build.bat")).thenReturn(ConcurrentUtils.constantFuture(0));
    instance.setExecutor(executor);//w w  w  . j ava 2 s.c o  m
    instance.execute();
    Mockito.verify(executor).exec("build.bat");
}

From source file:ch.cyberduck.core.threading.DefaultBackgroundExecutor.java

@Override
public <T> Future<T> execute(final Controller controller, final BackgroundActionRegistry registry,
        final BackgroundAction<T> action) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Run action %s in background", action));
    }/*w  w w.  ja  va  2s. c  om*/
    registry.add(action);
    action.init();
    // Start background task
    final Callable<T> command = new BackgroundCallable<T>(action, controller, registry);
    try {
        final Future<T> task = concurrentExecutor.execute(command);
        if (log.isInfoEnabled()) {
            log.info(String.format("Scheduled background runnable %s for execution", action));
        }
        return task;
    } catch (RejectedExecutionException e) {
        log.error(
                String.format("Error scheduling background task %s for execution. %s", action, e.getMessage()));
        action.cleanup();
        return ConcurrentUtils.constantFuture(null);
    }
}

From source file:com.mcleodmoores.mvn.natives.BuildMojoTest.java

@Test(expectedExceptions = MojoFailureException.class)
public void testExecuteExitCodeFail() throws Exception {
    final BuildMojo instance = executeInstance();
    final ProcessExecutor executor = Mockito.mock(ProcessExecutor.class);
    Mockito.when(executor.exec("build.bat")).thenReturn(ConcurrentUtils.constantFuture(1));
    instance.setExecutor(executor);//  w w w  .  java 2s.c o  m
    instance.execute();
}

From source file:io.cloudslang.lang.logging.LoggingServiceImplTest.java

@Test
public void testLogEventWithTwoParams() {
    final List<Runnable> runnableList = new ArrayList<>();
    final MutableInt mutableInt = new MutableInt(0);
    doAnswer(new Answer() {
        @Override//  w  w w . jav  a  2s  .  co  m
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            mutableInt.increment();
            Object[] arguments = invocationOnMock.getArguments();
            runnableList.add((Runnable) arguments[0]);
            if (mutableInt.getValue() == 1) {
                return ConcurrentUtils.constantFuture("aaa");
            } else if (mutableInt.getValue() == 2) {
                return ConcurrentUtils.constantFuture("bbb");
            } else {
                return null;
            }
        }
    }).when(singleThreadExecutor).submit(Mockito.any(Runnable.class));

    // Tested calls
    loggingService.logEvent(Level.INFO, "aaa");
    loggingService.logEvent(Level.ERROR, "bbb");

    assertEquals(2, runnableList.size());

    assertTrue(runnableList.get(0) instanceof LoggingServiceImpl.LoggingDetailsRunnable);
    assertTrue(runnableList.get(1) instanceof LoggingServiceImpl.LoggingDetailsRunnable);

    assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.INFO, "aaa"), runnableList.get(0));
    assertEquals(new LoggingServiceImpl.LoggingDetailsRunnable(Level.ERROR, "bbb"), runnableList.get(1));
}