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.thingsboard.server.dao.sql.attributes.JpaAttributeDao.java

@Override
public ListenableFuture<List<AttributeKvEntry>> findAll(TenantId tenantId, EntityId entityId,
        String attributeType) {//  w w  w  . j a va 2 s .  c  o m
    return Futures.immediateFuture(DaoUtil.convertDataList(
            Lists.newArrayList(attributeKvRepository.findAllByEntityTypeAndEntityIdAndAttributeType(
                    entityId.getEntityType(), UUIDConverter.fromTimeUUID(entityId.getId()), attributeType))));
}

From source file:org.opendaylight.ipsec.impl.IPsecImpl.java

@Override
public Future<RpcResult<RuleAddOutput>> ruleAdd(RuleAddInput input) {
    try {/*from   w w w.j a va2  s  . com*/
        InetAddress srcAddress = InetAddress.getByName(input.getSource());
        InetAddress dstAddress = InetAddress.getByName(input.getDestination());
        IPsecRule rule = new IPsecRule(srcAddress, input.getSrcPrefixLen(), dstAddress, input.getDstPrefixLen(),
                input.getAction(), input.getConnectionName());
        if (IPsecConnectionBuffer.getActiveByName(input.getConnectionName()) == null) {
            throw new RuleConflictException("connection not found");
        }
        if (input.getPos() != null) {
            LOG.info("insert rule at " + input.getPos() + ": " + rule.getSource() + " --> "
                    + rule.getDestination());
            IPsecRuleBuffer.add(input.getPos(), rule);
        } else {
            LOG.info("add rule: " + rule.getSource() + " --> " + rule.getDestination());
            IPsecRuleBuffer.add(rule);
        }
        // return result
        RuleAddOutputBuilder builder = new RuleAddOutputBuilder();
        builder.setResult("success");
        RpcResult<RuleAddOutput> rpcResult = Rpcs.<RuleAddOutput>getRpcResult(true, builder.build(),
                Collections.<RpcError>emptySet());
        return Futures.immediateFuture(rpcResult);
    } catch (UnknownHostException e) {
        // return error message
        RuleAddOutputBuilder builder = new RuleAddOutputBuilder();
        builder.setResult("unknown host");
        RpcResult<RuleAddOutput> rpcResult = Rpcs.<RuleAddOutput>getRpcResult(true, builder.build(),
                Collections.<RpcError>emptySet());
        return Futures.immediateFuture(rpcResult);
    } catch (RuleConflictException e) {
        LOG.info(e.getMessage());
        // return error message
        RuleAddOutputBuilder builder = new RuleAddOutputBuilder();
        builder.setResult(e.getMessage());
        RpcResult<RuleAddOutput> rpcResult = Rpcs.<RuleAddOutput>getRpcResult(true, builder.build(),
                Collections.<RpcError>emptySet());
        return Futures.immediateFuture(rpcResult);
    }
}

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

@Override
public <T> Future<Set<T>> deleteAll(Collection<T> keys, long millisNoReAdd) {
    return Futures.immediateFuture(memcacheService.deleteAll(keys, millisNoReAdd));
}

From source file:org.opendaylight.coretutorials.clustering.singleton.hs.topo.SampleDeviceTopologyDiscoveryContext.java

@Override
public ListenableFuture<Void> closeServiceInstance() {
    scheduleTaskCanceled = true;
    return Futures.immediateFuture(null);
}

From source file:io.crate.autocomplete.AutoCompleter.java

public ListenableFuture<CompletionResult> complete(String statement) {
    StatementLexer lexer = getLexer(statement);
    final Context ctx = new Context(statement.length());
    List<ListenableFuture<List<String>>> futureCompletions;
    try {//from ww  w . j a v  a  2  s.co  m
        futureCompletions = innerComplete(lexer, statement, ctx);
    } catch (ParsingException e) {
        return Futures.immediateFuture(new CompletionResult(0, Collections.<String>emptyList()));
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        return Futures.immediateFuture(new CompletionResult(0, Collections.<String>emptyList()));
    }

    final SettableFuture<CompletionResult> result = SettableFuture.create();
    Futures.addCallback(Futures.allAsList(futureCompletions), new FutureCallback<List<List<String>>>() {
        @Override
        public void onSuccess(@Nullable List<List<String>> completionsList) {
            if (completionsList == null) {
                result.set(new CompletionResult(0, ImmutableList.<String>of()));
                return;
            }
            if (ctx.parts.size() > 1) {
                Set<String> fullyQualifiedCompletions = new TreeSet<>();
                for (List<String> completions : completionsList) {
                    for (String completion : completions) {
                        ctx.parts.set(ctx.parts.size() - 1, completion);
                        fullyQualifiedCompletions.add(dotJoiner.join(ctx.parts));
                    }
                }
                result.set(new CompletionResult(ctx.startIdx, fullyQualifiedCompletions));
            } else {
                Set<String> uniqueSortedCompletions = new TreeSet<>();
                for (List<String> completions : completionsList) {
                    uniqueSortedCompletions.addAll(completions);
                }
                result.set(new CompletionResult(ctx.startIdx, uniqueSortedCompletions));
            }
        }

        @Override
        public void onFailure(@Nonnull Throwable t) {
            result.setException(t);
        }
    });
    return result;
}

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

@Override
public Future<Person> getPerson(UserId id, Set<String> fields, SecurityToken token) throws ProtocolException {

    return Futures.immediateFuture(convertPerson(getPersonForId(id, token), fields));
}

From source file:org.thingsboard.rule.engine.action.TbClearAlarmNode.java

@Override
protected ListenableFuture<AlarmResult> processAlarm(TbContext ctx, TbMsg msg) {
    ListenableFuture<Alarm> latest = ctx.getAlarmService().findLatestByOriginatorAndType(ctx.getTenantId(),
            msg.getOriginator(), config.getAlarmType());
    return Futures.transformAsync(latest, a -> {
        if (a != null && !a.getStatus().isCleared()) {
            return clearAlarm(ctx, msg, a);
        }/*from   ww w. j  a va  2 s.co m*/
        return Futures.immediateFuture(new AlarmResult(false, false, false, null));
    }, ctx.getDbCallbackExecutor());
}

From source file:com.proofpoint.event.monitor.test.SerialScheduledExecutorService.java

@Override
public <T> Future<T> submit(Callable<T> tCallable) {
    try {//from ww w  .j a v  a2 s  .com
        return Futures.immediateFuture(tCallable.call());
    } catch (Exception e) {
        return Futures.immediateFailedFuture(e);
    }
}

From source file:org.apache.qpid.server.txn.MockStoreTransaction.java

public <X> ListenableFuture<X> commitTranAsync(final X val) {
    return Futures.immediateFuture(val);
}

From source file:org.apache.apex.malhar.lib.state.managed.ManagedTimeUnifiedStateImpl.java

@Override
public Future<Slice> getAsync(long time, @NotNull Slice key) {
    long timeBucket = timeBucketAssigner.getTimeBucket(time);
    if (timeBucket == -1) {
        //time is expired so return expired slice.
        return Futures.immediateFuture(BucketedState.EXPIRED);
    }/* w  w  w .j  a  v  a  2s.  c  o m*/
    return getValueFromBucketAsync(timeBucket, timeBucket, key);
}