當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。