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


Java Futures.immediateFuture方法代码示例

本文整理汇总了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());
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:21,代码来源:CassandraAbstractModelDao.java

示例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");
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:17,代码来源:GuavaLFReturnValueHandlerTest.java

示例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);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:27,代码来源:MinecraftServer.java

示例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);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:21,代码来源:CassandraAbstractModelDao.java

示例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);
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:27,代码来源:Minecraft.java

示例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);
        }
    };
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:24,代码来源:TestExecutors.java

示例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;
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:41,代码来源:ApiController.java

示例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);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:33,代码来源:UserFinder.java

示例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);
      }
    }
  };
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:FSDownload.java

示例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 ) {
    }
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:10,代码来源:ApiMonitoringService.java

示例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))));
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:10,代码来源:JpaAttributeDao.java

示例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);
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:13,代码来源:FpcagentDispatcher.java

示例13: getRatings

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<MapRatingsResponse> getRatings(MapRatingsRequest request) {
    return Futures.immediateFuture(Collections::emptyMap);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:LocalMapService.java

示例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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:5,代码来源:TestQuorumJournalManagerUnit.java

示例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))));
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:7,代码来源:JpaAttributeDao.java


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