当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentUtils.constantFuture方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.concurrent.ConcurrentUtils.constantFuture方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentUtils.constantFuture方法的具体用法?Java ConcurrentUtils.constantFuture怎么用?Java ConcurrentUtils.constantFuture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.concurrent.ConcurrentUtils的用法示例。


在下文中一共展示了ConcurrentUtils.constantFuture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@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));
    }
    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);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:23,代码来源:DefaultBackgroundExecutor.java

示例2: setUp

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Before
public void setUp() {
	config = Configuration.buildFromConfig("config-mock.properties");
	when(connectionStrategy.getHttpClient()).thenReturn(asyncHttpClient);
	HttpResponse response = mock(HttpResponse.class);
	Future<HttpResponse> future = ConcurrentUtils.constantFuture(response);
	when(asyncHttpClient.execute(any(HttpUriRequest.class),any(FutureCallback.class))).thenReturn(future, null);
	HttpEntity httpEntity = mock(HttpEntity.class);
	when(response.getEntity()).thenReturn(httpEntity);
	StatusLine statusLine = mock(StatusLine.class);
	when(response.getStatusLine()).thenReturn(statusLine);
	when(statusLine.getStatusCode()).thenReturn(200);
	try {
		InputStream inputStream = IOUtils.toInputStream(SERVER_RESPONSE_EXPECTED, "UTF-8");
		when(httpEntity.getContent()).thenReturn(inputStream);
		client = new LogInsightClient(config, connectionStrategy);
		// client.connect(user, password);
		assertEquals("Invalid session id!!",
				"qyOLWEe7f/GjdM1WnczrCeQure97B/NpTbWTeqqYPBd1AYMf9cMNfQYqltITI4ffPMx822Sz9i/X47t8VwsDb0oGckclJUdn83cyIPk6WlsOpI4Yjw6WpurAnv9RhDsYSzKhAMzskzhTOJKfDHZjWR5v576WwtJA71wqI7igFrG91LG5c/3GfzMb68sUHF6hV+meYtGS4A1y/lUItvfkqTTAxBtTCZNoKrvCJZ4R+b6vuAAYoBNSWL7ycIy2LsALrVFxftAkA8n9DBAZYA9T5A==",
				client.getSessionId());
	} catch (Exception e) {
		logger.error("Exception raised " + ExceptionUtils.getStackTrace(e));
	}
}
 
开发者ID:vmware,项目名称:loginsight-java-api,代码行数:25,代码来源:LogInsightClientMockTest.java

示例3: getLogValue

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
/**
 * Reads LogValue from LogMap.
 * <p>
 * It will use the cached value if it exist, if not it will
 * get the value from distributed store.
 *
 * @param key log sequence number
 * @return Future containing log value
 */
public Future<LogValue> getLogValue(final SeqNum key) {
    try {
        return cache.get(key, new Callable<Future<LogValue>>() {

            @Override
            public Future<LogValue> call() throws Exception {
                return logMap.getAsync(key);
            }
        });
    } catch (ExecutionException e) {
        log.error("Reading from Log Map failed.", e);
        // should never happen?
        return ConcurrentUtils.constantFuture(null);
    }
}
 
开发者ID:opennetworkinglab,项目名称:spring-open,代码行数:25,代码来源:LogMapManager.java

示例4: run

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
public Future<Boolean> run(String...args) {
    String[] argA = new String[2 + args.length];
    argA[0] = DEFAULT_SHELL;
    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);
    }
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:20,代码来源:RunShell.java

示例5: background

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
/**
 * Will queue up the <code>BackgroundAction</code> to be run in a background thread
 *
 * @param action The runnable to execute in a secondary thread
 */
@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);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:14,代码来源:AbstractController.java

示例6: getJsonObject

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Override
public Future<Response> getJsonObject(
        SuccessCallback success,
        HttpErrorCallback error,
        FailureCallback failure,
        String resourcePath
) {
    LOG.info("Invoking test druid webservice: {}", this);

    // Store the most recent query sent through
    lastUrl = resourcePath;

    // Invoke failure callback if we have a throwable to give it
    if (throwable != null) {
        failure.invoke(throwable);
        return CompletedFuture.throwing(throwable);
    }

     try {
         if (statusCode == 200) {
            success.invoke(mapper.readTree(jsonResponse.call()));
        } else {
            error.invoke(statusCode, reasonPhrase, jsonResponse.call());
        }
    } catch (IOException e) {
        failure.invoke(e);
         return CompletedFuture.throwing(throwable);
    }

    return ConcurrentUtils.constantFuture(null);
}
 
开发者ID:yahoo,项目名称:fili,代码行数:32,代码来源:TestDruidWebService.java

示例7: saveAsync

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> FutureObject<T> saveAsync(Object object) {
    ObjectHolder objectHolder = new ObjectHolder(object);

    setIdIfNecessary(objectHolder);

    MockStore.put(objectHolder.getId(), object, tx());

    Future<?> futureId = ConcurrentUtils.constantFuture(objectHolder.getId());
    return new FutureObject<T>(r, (Future<IdRef<?>>) futureId, (T) object);
}
 
开发者ID:feroult,项目名称:yawp,代码行数:13,代码来源:MockPersistenceDriver.java

示例8: submit

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
public Future<TransferStatus> submit(final TransferCallable runnable) throws BackgroundException {
    return ConcurrentUtils.constantFuture(runnable.call());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:4,代码来源:SingleTransferWorker.java

示例9: postDruidQuery

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
/**
 * If TestDruidWebService#throwable is set, invokes the failure callback.  Otherwise invokes success or failure
 * dependent on whether TestDruidWebService#statusCode equals 200.
 * Note that since this doesn't send requests to druid all the responses will be null or {@link CompletedFuture}.
 */
@Override
@SuppressWarnings("checkstyle:cyclomaticcomplexity")
public Future<Response> postDruidQuery(
        RequestContext context,
        SuccessCallback success,
        HttpErrorCallback error,
        FailureCallback failure,
        DruidQuery<?> query
) {
    LOG.info("Invoking test druid webservice: {}", this);

    // Store the most recent query sent through
    lastQuery = query;

    // Convert the query to json
    try {
        jsonQuery = writer.withDefaultPrettyPrinter().writeValueAsString(query);
    } catch (JsonProcessingException ignored) {
        // Ignore
    }

    // Invoke failure callback if we have a throwable to give it
    if (throwable != null) {
        failure.invoke(throwable);
        return CompletedFuture.throwing(throwable);
    }

    if (lastQuery.getQueryType() instanceof DefaultQueryType) {
        // For known response types, create a default response provider

        // Set the response to use based on the type of the query we're processing
        DefaultQueryType defaultQueryType = (DefaultQueryType) lastQuery.getQueryType();
        switch (defaultQueryType) {
            case GROUP_BY:
            case TOP_N:
            case TIMESERIES:
            case LOOKBACK:
                // default response is groupBy response
                break;
            case SEGMENT_METADATA:
                jsonResponse = () -> segmentMetadataResponse;
                break;
            case TIME_BOUNDARY:
                jsonResponse = () -> timeBoundaryResponse;
                break;
            default:
                throw new IllegalArgumentException("Illegal query type : " + lastQuery.getQueryType());
        }

    } else {
        // Otherwise extended query types will have to set up their own responses
    }

    try {
        if (query instanceof WeightEvaluationQuery) {
            success.invoke(mapper.readTree(weightResponse));
        } else if (statusCode == 200) {
            success.invoke(mapper.readTree(jsonResponse.call()));
        } else {
            error.invoke(statusCode, reasonPhrase, jsonResponse.call());
        }
    } catch (IOException e) {
        failure.invoke(e);
        return CompletedFuture.throwing(e);
    }

    return ConcurrentUtils.constantFuture(null);
}
 
开发者ID:yahoo,项目名称:fili,代码行数:74,代码来源:TestDruidWebService.java

示例10: send

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Override
public Future<RecordMetadata> send(ProducerRecord record) {
  // Fake result: only for testing purpose
  return ConcurrentUtils.constantFuture(new RecordMetadata(null, 0, 0, 0, 0, 0, 0));
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:6,代码来源:KsqlResourceTest.java

示例11: fetchAsync

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Override
public <T> FutureObject<T> fetchAsync(IdRef<T> id) {
    T object = fetch(id);
    Future<?> futureObject = ConcurrentUtils.constantFuture(object);
    return new FutureObject<>(r, futureObject);
}
 
开发者ID:feroult,项目名称:yawp,代码行数:7,代码来源:PGQueryDriver.java

示例12: destroyAsync

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Override
public FutureObject<Void> destroyAsync(IdRef<?> id) {
    destroy(id);
    Future<Void> future = ConcurrentUtils.constantFuture(null);
    return new FutureObject<>(r, future);
}
 
开发者ID:feroult,项目名称:yawp,代码行数:7,代码来源:PGPersistenceDriver.java

示例13: saveEntityAsync

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> FutureObject<T> saveEntityAsync(ObjectHolder objectHolder, Entity entity) {
    Key key = datastore.put(entity);
    Future<?> futureId = ConcurrentUtils.constantFuture(IdRefToKey.toIdRef(r, key, objectHolder.getModel()));
    return new FutureObject<>(r, (Future<IdRef<?>>) futureId, (T) objectHolder.getObject());
}
 
开发者ID:feroult,项目名称:yawp,代码行数:7,代码来源:PGPersistenceDriver.java

示例14: fetchAsync

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Override
public <T> FutureObject<T> fetchAsync(IdRef<T> id) {
    T object = fetch(id);
    Future<?> futureObject = ConcurrentUtils.constantFuture(object);
    return new FutureObject<T>(r, futureObject);
}
 
开发者ID:feroult,项目名称:yawp,代码行数:7,代码来源:MockQueryDriver.java

示例15: destroyAsync

import org.apache.commons.lang3.concurrent.ConcurrentUtils; //导入方法依赖的package包/类
@Override
public FutureObject<Void> destroyAsync(IdRef<?> id) {
    destroy(id);
    Future<Void> future = ConcurrentUtils.constantFuture(null);
    return new FutureObject<Void>(r, future);
}
 
开发者ID:feroult,项目名称:yawp,代码行数:7,代码来源:MockPersistenceDriver.java


注:本文中的org.apache.commons.lang3.concurrent.ConcurrentUtils.constantFuture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。