本文整理汇总了Java中com.google.common.util.concurrent.Futures.immediateFuture方法的典型用法代码示例。如果您正苦于以下问题:Java Futures.immediateFuture方法的具体用法?Java Futures.immediateFuture怎么用?Java Futures.immediateFuture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.Futures
的用法示例。
在下文中一共展示了Futures.immediateFuture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findListByStatementAsync
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) {
if (statement != null) {
statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() {
@Nullable
@Override
public List<D> apply(@Nullable ResultSet resultSet) {
Result<E> result = getMapper().map(resultSet);
if (result != null) {
List<E> entities = result.all();
return DaoUtil.convertDataList(entities);
} else {
return Collections.emptyList();
}
}
});
}
return Futures.immediateFuture(Collections.emptyList());
}
示例2: handlesSuccess
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Test
public void handlesSuccess() throws Exception {
final AtomicReference<Object> value = new AtomicReference<>();
ListenableFuture<String> future = Futures.immediateFuture("42");
GuavaLFReturnValueHandler handler = new GuavaLFReturnValueHandler() {
@Override
protected void startDeferredResultProcessing(ModelAndViewContainer mavContainer, NativeWebRequest webRequest, DeferredResult<Object> deferredResult) throws Exception {
value.set(deferredResult.getResult());
}
};
handler.handleReturnValue(future, null, null, null);
assertThat(value.get()).isEqualTo("42");
}
示例3: callFromMainThread
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public <V> ListenableFuture<V> callFromMainThread(Callable<V> callable)
{
Validate.notNull(callable);
if (!this.isCallingFromMinecraftThread() && !this.isServerStopped())
{
ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callable);
synchronized (this.futureTaskQueue)
{
this.futureTaskQueue.add(listenablefuturetask);
return listenablefuturetask;
}
}
else
{
try
{
return Futures.<V>immediateFuture(callable.call());
}
catch (Exception exception)
{
return Futures.immediateFailedCheckedFuture(exception);
}
}
}
示例4: findOneByStatementAsync
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
protected ListenableFuture<D> findOneByStatementAsync(Statement statement) {
if (statement != null) {
statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = getSession().executeAsync(statement);
return Futures.transform(resultSetFuture, new Function<ResultSet, D>() {
@Nullable
@Override
public D apply(@Nullable ResultSet resultSet) {
Result<E> result = getMapper().map(resultSet);
if (result != null) {
E entity = result.one();
return DaoUtil.getData(entity);
} else {
return null;
}
}
});
}
return Futures.immediateFuture(null);
}
示例5: addScheduledTask
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public <V> ListenableFuture<V> addScheduledTask(Callable<V> callableToSchedule)
{
Validate.notNull(callableToSchedule);
if (!this.isCallingFromMinecraftThread())
{
ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callableToSchedule);
synchronized (this.scheduledTasks)
{
this.scheduledTasks.add(listenablefuturetask);
return listenablefuturetask;
}
}
else
{
try
{
return Futures.<V>immediateFuture(callableToSchedule.call());
}
catch (Exception exception)
{
return Futures.immediateFailedCheckedFuture(exception);
}
}
}
示例6: blocksOnFirstCallFromCallableOfType
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public static ExecutorService blocksOnFirstCallFromCallableOfType(final ExecutorService delegate, final Class<? extends Callable> type) {
return new ForwardingExecutorService() {
private boolean firstCall = true;
@Override
protected ExecutorService delegate() {
return delegate;
}
@Override
public <T> Future<T> submit(Callable<T> task) {
if (task.getClass().equals(type) && firstCall) {
firstCall = false;
try {
return Futures.immediateFuture(task.call());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return super.submit(task);
}
};
}
示例7: loadBuildTypeList
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Void> loadBuildTypeList( ) {
if ( !getApiVersion( ).isSupported( ApiFeature.BUILD_TYPE_STATUS ) )
return Futures.immediateFuture( null );
final SettableFuture<Void> ackFuture = SettableFuture.create( );
runInWorkerThread( ( ) -> {
final ListenableFuture<BuildTypeList> buildListFuture = _apiRequestController.sendRequest( getApiVersion( ), "buildTypes", BuildTypeList.class );
addCallback( buildListFuture, new FutureCallback<BuildTypeList>( ) {
@Override
public void onSuccess( final BuildTypeList result ) {
final List<BuildTypeData> buildTypes = result.getBuildTypes( ).stream( )
.map( ( btype ) -> _buildTypeProvider.get( getApiVersion( ) ).apply( btype ) )
.collect( Collectors.toList( ) );
_buildManager.registerBuildTypes( buildTypes );
_eventBus.post( _buildManager );
for ( final BuildTypeData buildType : _buildManager.getBuildTypes( ) ) {
final Optional<ProjectData> project = _projectManager.getProject( buildType.getProjectId( ) );
if ( project.isPresent( ) ) {
project.get( ).registerBuildType( buildType );
_eventBus.post( project.get( ) );
}
LOGGER.info( "Discovering build type " + buildType.getId( ) + " (" + buildType.getName( ) + ") on project " + buildType.getProjectId( ) + " (" + buildType.getProjectName( ) + ")" );
}
ackFuture.set( null );
}
@Override
public void onFailure( final Throwable t ) {
LOGGER.error( "Error during loading build type list:", t );
ackFuture.setException( t );
}
} );
} );
return ackFuture;
}
示例8: findPlayer
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public ListenableFuture<PlayerSearchResponse> findPlayer(CommandSender sender, @Nullable String name, Scope scope, Default def) {
try {
final Player player = getLocalPlayer(sender, name);
if(player != null) {
return Futures.immediateFuture(localPlayerResponse(sender, player));
}
if(scope.noGreaterThan(Scope.LOCAL)) {
throw new TranslatableCommandException("command.playerNotFound");
}
final SettableFuture<PlayerSearchResponse> playerResult = SettableFuture.create();
mainThreadExecutor.callback(
findUser(sender, name, scope, def),
new FutureCallback<UserSearchResponse>() {
@Override
public void onSuccess(@Nullable UserSearchResponse userResult) {
playerResult.set(new PlayerSearchResponse(userResult, onlinePlayers.find(userResult.user)));
}
@Override
public void onFailure(Throwable t) {
playerResult.setException(t);
}
}
);
return playerResult;
} catch(CommandException e) {
return Futures.immediateFailedFuture(e);
}
}
示例9: createStatusCacheLoader
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
/**
* Creates the cache loader for the status loading cache. This should be used
* to create an instance of the status cache that is passed into the
* FSDownload constructor.
*/
public static CacheLoader<Path,Future<FileStatus>>
createStatusCacheLoader(final Configuration conf) {
return new CacheLoader<Path,Future<FileStatus>>() {
public Future<FileStatus> load(Path path) {
try {
FileSystem fs = path.getFileSystem(conf);
return Futures.immediateFuture(fs.getFileStatus(path));
} catch (Throwable th) {
// report failures so it can be memoized
return Futures.immediateFailedFuture(th);
}
}
};
}
示例10: checkBuildStatus
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private void checkBuildStatus( final Iterable<BuildTypeData> monitoredBuilds ) {
try {
ListenableFuture<Void> future = Futures.immediateFuture( null );
for ( final BuildTypeData buildType : monitoredBuilds )
future = Futures.transform( future, (AsyncFunction<Void, Void>) o -> _apiController.requestLastBuildStatus( buildType ) );
future.get( );
} catch ( InterruptedException | ExecutionException ignored ) {
}
}
示例11: find
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<AttributeKvEntry>> find(EntityId entityId, String attributeType,
Collection<String> attributeKeys) {
List<AttributeKvCompositeKey> compositeKeys = attributeKeys.stream()
.map(attributeKey -> getAttributeKvCompositeKey(entityId, attributeType, attributeKey))
.collect(Collectors.toList());
return Futures
.immediateFuture(DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAll(compositeKeys))));
}
示例12: configureBundles
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public Future<RpcResult<ConfigureBundlesOutput>> configureBundles(ConfigureBundlesInput input) {
if (input == null) {
return Futures.immediateFuture(configBundlesMissingBodyErr);
}
IetfDmmFpcagentService ifc = getStrategy(input.getClientId());
if (ifc != null) {
return ifc.configureBundles(input);
}
return Futures.immediateFuture(configBundlesUnknownClientErr);
}
示例13: getRatings
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<MapRatingsResponse> getRatings(MapRatingsRequest request) {
return Futures.immediateFuture(Collections::emptyMap);
}
示例14: futureReturns
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
static <V> Stubber futureReturns(V value) {
ListenableFuture<V> ret = Futures.immediateFuture(value);
return Mockito.doReturn(ret);
}
示例15: findAll
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<List<AttributeKvEntry>> findAll(EntityId entityId, String attributeType) {
return Futures.immediateFuture(
DaoUtil.convertDataList(Lists.newArrayList(attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType(
entityId.getEntityType(), UUIDConverter.fromTimeUUID(entityId.getId()), attributeType))));
}