Example usage for com.google.common.util.concurrent Futures immediateFuture

List of usage examples for com.google.common.util.concurrent Futures immediateFuture

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures immediateFuture.

Prototype

@CheckReturnValue
public static <V> ListenableFuture<V> immediateFuture(@Nullable V value) 

Source Link

Document

Creates a ListenableFuture which has its value set immediately upon construction.

Usage

From source file:org.apache.qpid.server.security.FileTrustStoreImpl.java

@StateTransition(currentState = { State.ACTIVE, State.ERRORED }, desiredState = State.DELETED)
protected ListenableFuture<Void> doDelete() {
    // verify that it is not in use
    String storeName = getName();

    Collection<Port<?>> ports = new ArrayList<Port<?>>(_broker.getPorts());
    for (Port port : ports) {
        Collection<TrustStore> trustStores = port.getTrustStores();
        if (trustStores != null) {
            for (TrustStore store : trustStores) {
                if (storeName.equals(store.getAttribute(TrustStore.NAME))) {
                    throw new IntegrityViolationException("Trust store '" + storeName
                            + "' can't be deleted as it is in use by a port: " + port.getName());
                }/*from w w w . j ava 2s .co m*/
            }
        }
    }

    Collection<AuthenticationProvider> authenticationProviders = new ArrayList<AuthenticationProvider>(
            _broker.getAuthenticationProviders());
    for (AuthenticationProvider authProvider : authenticationProviders) {
        if (authProvider instanceof SimpleLDAPAuthenticationManager) {
            SimpleLDAPAuthenticationManager simpleLdap = (SimpleLDAPAuthenticationManager) authProvider;
            if (simpleLdap.getTrustStore() == this) {
                throw new IntegrityViolationException("Trust store '" + storeName
                        + "' can't be deleted as it is in use by an authentication manager: "
                        + authProvider.getName());
            }
        }
    }
    deleted();
    setState(State.DELETED);
    _eventLogger.message(TrustStoreMessages.DELETE(getName()));
    return Futures.immediateFuture(null);
}

From source file:io.v.v23.VFutures.java

/**
 * Returns a new {@link ListenableFuture} that runs on an {@link Executor} specified in the
 * given {@code context}. If the future completes but the given {@code context} has been
 * canceled, the returned future is canceled as well.
 *//* w  w  w . jav  a  2 s .  c  om*/
public static <T> ListenableFuture<T> withUserLandChecks(final VContext context,
        final ListenableFuture<T> future) {
    Executor executor = V.getExecutor(context);
    if (executor == null) {
        throw new RuntimeException("NULL executor in context: did you derive this context "
                + "from the context returned by V.init()?");
    }
    return Futures.transform(future, new AsyncFunction<T, T>() {
        @Override
        public ListenableFuture<T> apply(T input) throws Exception {
            if (context.isCanceled()) {
                return Futures.immediateCancelledFuture();
            }
            return Futures.immediateFuture(input);
        }
    }, executor);
}

From source file:org.apache.shindig.social.websockbackend.spi.WsNativeMediaItemSPI.java

private Future<RestfulCollection<MediaItem>> converList(IQueryCallback result) {
    ListResult lResult = null;/*from  w  w w  .  j a v  a2s.  c o m*/

    try {
        lResult = (ListResult) result.get();

        // TODO: proper not found exception
        if (lResult == null) {
            return null;
        }
    } catch (final Exception e) {
        e.printStackTrace();
        this.fLogger.log(Level.SEVERE, "server error", e);
        throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "could not retrieve results",
                e);
    }

    @SuppressWarnings("unchecked")
    final List<Map<String, Object>> mapList = (List<Map<String, Object>>) lResult.getResults();

    final List<MediaItem> mediaItems = new LinkedList<MediaItem>();

    for (final Map<String, Object> aMap : mapList) {
        mediaItems.add(new MediaItemDTO(aMap));
    }

    final RestfulCollection<MediaItem> rColl = new RestfulCollection<MediaItem>(mediaItems);
    rColl.setStartIndex(lResult.getFirst());
    rColl.setTotalResults(lResult.getTotal());
    rColl.setItemsPerPage(lResult.getMax());
    return Futures.immediateFuture((rColl));
}

From source file:org.opendaylight.lispflowmapping.southbound.LispSouthboundRPC.java

@Override
public Future<RpcResult<Void>> resetStats() {
    LOG.trace("resetStats called!!");

    LispSouthboundStats stats = lispSbPlugin.getStats();

    if (stats == null) {
        return Futures.immediateFuture(RpcResultBuilder.<Void>failed()
                .withError(RpcError.ErrorType.APPLICATION, "data-missing", "No stats found").build());
    } else {//from   w w  w .j  av a  2  s.c  o  m
        stats.resetStats();
        return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
    }
}

From source file:com.orangerhymelabs.helenus.cassandra.AbstractCassandraRepository.java

public ListenableFuture<List<T>> readAll(PreparedStatement statement, Object... parms) {
    ListenableFuture<ResultSet> future = submitStatement(statement, parms);
    return Futures.transformAsync(future, new AsyncFunction<ResultSet, List<T>>() {
        @Override/*from   w w w . j  a  v  a2 s.  c o m*/
        public ListenableFuture<List<T>> apply(ResultSet input) {
            return Futures.immediateFuture(marshalAll(input));
        }
    }, MoreExecutors.directExecutor());
}

From source file:com.google.api.server.spi.config.datastore.testing.FakeAsyncMemcacheService.java

@Override
public <T> Future<Set<T>> putIfUntouched(Map<T, CasValues> values) {
    return Futures.immediateFuture(memcacheService.putIfUntouched(values));
}

From source file:org.opendaylight.idmanager.IdManager.java

@Override
public Future<RpcResult<Void>> createIdPool(CreateIdPoolInput input) {
    LOG.debug("createIdPool called with input {}", input);
    String poolName = input.getPoolName();
    long low = input.getLow();
    long high = input.getHigh();
    long blockSize = IdUtils.computeBlockSize(low, high);
    RpcResultBuilder<Void> createIdPoolRpcBuilder;
    IdUtils.lockPool(lockManager, poolName);
    try {//from w  w w .j a  va2  s. c  o  m
        InstanceIdentifier<IdPool> idPoolInstanceIdentifier = IdUtils.getIdPoolInstance(poolName);
        poolName = poolName.intern();
        IdPool idPool;
        idPool = createGlobalPool(poolName, low, high, blockSize, idPoolInstanceIdentifier);
        String localPoolName = IdUtils.getLocalPoolName(poolName);
        if (createLocalPool(localPoolName, idPool)) {
            LOG.debug("Updating global id pool {} with childPool {}", poolName, localPoolName);
            updateChildPool(poolName, localPoolName);
        }
        createIdPoolRpcBuilder = RpcResultBuilder.success();
    } catch (Exception ex) {
        LOG.error("Creation of Id Pool {} failed due to {}", poolName, ex);
        createIdPoolRpcBuilder = RpcResultBuilder.failed();
        createIdPoolRpcBuilder.withError(ErrorType.APPLICATION, ex.getMessage());
    } finally {
        IdUtils.unlockPool(lockManager, poolName);
    }
    return Futures.immediateFuture(createIdPoolRpcBuilder.build());
}

From source file:org.apache.twill.internal.AbstractZKServiceController.java

protected synchronized void forceShutDown() {
    if (stopMessageFuture == null) {
        // In force shutdown, don't send message.
        stopMessageFuture = Futures.immediateFuture(State.TERMINATED);
    }//  ww w  . j  a va  2s .  c  o m
    stop();
}

From source file:org.apache.shindig.social.websockbackend.spi.WsNativeAppDataSPI.java

@Override
public Future<Void> deletePersonData(UserId userId, GroupId groupId, String appId, Set<String> fields,
        SecurityToken token) throws ProtocolException {
    String group = null;/*from  w  w  w  . ja  va  2s  . co m*/

    if (groupId != null) {
        // actual group
        if (groupId.getType() == GroupId.Type.objectId) {
            group = groupId.getObjectId().toString();
        }
        // group type
        else {
            group = '@' + groupId.getType().toString();
        }
    }

    // create query
    final WebsockQuery query = new WebsockQuery(EQueryType.PROCEDURE_CALL);
    query.setPayload(ShindigNativeQueries.DELETE_APP_DATA_QUERY);

    // set parameters for method
    query.setParameter(ShindigNativeQueries.USER_ID, userId.getUserId(token));
    query.setParameter(ShindigNativeQueries.GROUP_ID, group);
    query.setParameter(ShindigNativeQueries.APP_ID, appId);

    if (fields != null) {
        final List<String> fieldList = new ArrayList<String>(fields);
        query.setParameter(ShindigNativeQueries.FIELD_LIST, fieldList);
    }

    // execute query
    try {
        this.fQueryHandler.sendQuery(query).get();
    } catch (final Exception e) {
        e.printStackTrace();
        this.fLogger.log(Level.SEVERE, "server error", e);
        throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "could not delete application data", e);
    }

    return Futures.immediateFuture(null);
}

From source file:org.apache.rave.opensocial.service.impl.DefaultActivityStreamsService.java

/**
 * Returns an activity for the passed in user and group that corresponds to a single activityId.
 * <p/>/*from   w  ww . j av a  2s  .c om*/
 * Specified by: getActivityEntry(...) in ActivityStreamService
 * Parameters:
 * userId The id to fetch activities for.
 * groupId Indicates whether to fetch activities for a group.
 * appId The app id.
 * fields The fields to return. Empty set implies all
 * activityId The activity id to fetch.
 * token A valid SecurityToken
 * Returns:
 * a response item with the list of activities.
 * Throws:
 * ProtocolException - if any.
 */
@Override
public Future<ActivityEntry> getActivityEntry(UserId userId, GroupId groupId, String appId, Set<String> fields,
        String activityId, SecurityToken token) throws ProtocolException {
    return Futures.immediateFuture(
            getActivity(fields, userId.getUserId(token), Maps.<String, Person>newHashMap(), activityId));
}