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


Java Futures.immediateFailedCheckedFuture方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.Futures.immediateFailedCheckedFuture方法的典型用法代码示例。如果您正苦于以下问题:Java Futures.immediateFailedCheckedFuture方法的具体用法?Java Futures.immediateFailedCheckedFuture怎么用?Java Futures.immediateFailedCheckedFuture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.Futures的用法示例。


在下文中一共展示了Futures.immediateFailedCheckedFuture方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:MinecraftServer.java

示例2: 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:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:Minecraft.java

示例3: 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,代码行数:19,代码来源:Minecraft.java

示例4: read

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
    LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
    checkNotNull(path, "Path must not be null.");

    final Optional<NormalizedNode<?, ?>> result;
    try {
        result = readSnapshotNode(path);
    } catch (Exception e) {
        LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e));
    }

    if (result == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
    } else {
        return Futures.immediateCheckedFuture(result);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:SnapshotBackedReadWriteTransaction.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())
    {
        try
        {
            return Futures.<V>immediateFuture(callableToSchedule.call());
        }
        catch (Exception exception)
        {
            return Futures.immediateFailedCheckedFuture(exception);
        }
    }
    else
    {
        ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callableToSchedule);

        synchronized (this.scheduledTasks)
        {
            this.scheduledTasks.add(listenablefuturetask);
            return listenablefuturetask;
        }
    }
}
 
开发者ID:NSExceptional,项目名称:Zombe-Modpack,代码行数:27,代码来源:Minecraft.java

示例6: submit

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public synchronized CheckedFuture<Void, TransactionCommitFailedException> submit() {
    Preconditions.checkState(!closed, "Transaction %s is already closed", identifier);

    final Set<DOMStoreWriteTransaction> txns = ImmutableSet.copyOf(idToTransaction.values());
    final List<DOMStoreThreePhaseCommitCohort> cohorts = new ArrayList<>(txns.size());
    for (DOMStoreWriteTransaction tx : txns) {
        cohorts.add(tx.ready());
    }

    try {
        return Futures.immediateCheckedFuture(new CommitCoordinationTask(this, cohorts, null).call());
    } catch (TransactionCommitFailedException e) {
        return Futures.immediateFailedCheckedFuture(e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:ShardedDOMDataWriteTransaction.java

示例7: invokeRpc

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
    final AbstractDOMRpcRoutingTableEntry entry = rpcs.get(type);
    if (entry == null) {
        return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
            new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", type));
    }

    return entry.invokeRpc(input);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:DOMRpcRoutingTable.java

示例8: submit

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
protected CheckedFuture<Void,TransactionCommitFailedException> submit(final DOMDataWriteTransaction transaction,
        final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
    Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
    Preconditions.checkArgument(cohorts != null, "Cohorts must not be null.");
    LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());

    ListenableFuture<Void> commitFuture = null;
    try {
        commitFuture = executor.submit(new CommitCoordinationTask(transaction, cohorts,
                commitStatsTracker));
    } catch(RejectedExecutionException e) {
        LOG.error("The commit executor's queue is full - submit task was rejected. \n" +
                  executor, e);
        return Futures.immediateFailedCheckedFuture(
                new TransactionCommitFailedException(
                    "Could not submit the commit task - the commit queue capacity has been exceeded.", e));
    }

    return MappingCheckedFuture.create(commitFuture,
            TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:23,代码来源:SerializedDOMDataBroker.java

示例9: read

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
    LOG.debug("Tx: {} Read: {}", getIdentifier(), path);
    checkNotNull(path, "Path must not be null.");

    final DataTreeSnapshot snapshot = stableSnapshot;
    if (snapshot == null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed"));
    }

    try {
        return Futures.immediateCheckedFuture(snapshot.readNode(path));
    } catch (Exception e) {
        LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e);
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed",e));
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:SnapshotBackedReadTransaction.java

示例10: exists

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
    LOG.debug("Tx: {} Exists: {}", getIdentifier(), path);
    checkNotNull(path, "Path must not be null.");

    try {
        return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent());
    } catch (ReadFailedException e) {
        return Futures.immediateFailedCheckedFuture(e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:SnapshotBackedReadTransaction.java

示例11: invokeRpc

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input) {
    final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId);

    // Routing key is present, attempt to deliver as a routed RPC
    if (maybeKey.isPresent()) {
        final NormalizedNode<?, ?> key = maybeKey.get();
        final Object value = key.getValue();
        if (value instanceof YangInstanceIdentifier) {
            final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;

            // Find a DOMRpcImplementation for a specific iid
            final List<DOMRpcImplementation> specificImpls = getImplementations(iid);
            if (specificImpls != null) {
                return specificImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
            }

            LOG.debug("No implementation for context {} found will now look for wildcard id", iid);

            // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
            // implementation this way
            final List<DOMRpcImplementation> mayBeRemoteImpls = getImplementations(YangInstanceIdentifier.EMPTY);

            if(mayBeRemoteImpls != null){
                return mayBeRemoteImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
            }

        } else {
            LOG.warn("Ignoring wrong context value {}", value);
        }
    }

    final List<DOMRpcImplementation> impls = getImplementations(null);
    if (impls != null) {
        return impls.get(0).invokeRpc(globalRpcId, input);
    } else {
        return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", getSchemaPath()));
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:RoutedDOMRpcRoutingTableEntry.java

示例12: canCommit

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(final Object txId,
        final DOMDataTreeCandidate candidate, final SchemaContext ctx) {

    // Simple data validation - verify the year, if present, is >= 1990

    final DataTreeCandidateNode rootNode = candidate.getRootNode();
    final Optional<NormalizedNode<?, ?>> dataAfter = rootNode.getDataAfter();

    LOG.info("In canCommit: modificationType: {}, dataBefore: {}, dataAfter: {}", rootNode.getModificationType(),
            rootNode.getDataBefore(), dataAfter);

    // Note: we don't want to process DELETE modifications but we don't need to explicitly check the
    // ModificationType because dataAfter will not be present. Also dataAfter *should* always contain a
    // MapEntryNode but we verify anyway.
    if (dataAfter.isPresent()) {
        final NormalizedNode<?, ?> normalizedNode = dataAfter.get();
        Verify.verify(normalizedNode instanceof DataContainerNode, "Expected type DataContainerNode, actual was %s",
                normalizedNode.getClass());
        DataContainerNode<?> entryNode = (DataContainerNode<?>) normalizedNode;
        final Optional<DataContainerChild<? extends PathArgument, ?>> possibleYear =
                entryNode.getChild(YEAR_NODE_ID);
        if (possibleYear.isPresent()) {
            final Number year = (Number) possibleYear.get().getValue();

            LOG.info("year is {}", year);

            if (!(year.longValue() >= 1990)) {
                return Futures.immediateFailedCheckedFuture(new DataValidationFailedException(
                        DOMDataTreeIdentifier.class, candidate.getRootPath(),
                            String.format("Invalid year %d - year must be >= 1990", year)));
            }
        }
    }

    // Return the noop PostCanCommitStep as we're only validating input data and not participating in the
    // remaining 3PC stages (pre-commit and commit).
    return PostCanCommitStep.NOOP_SUCCESS_FUTURE;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:CarEntryDataTreeCommitCohort.java

示例13: sendReadRequest

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private <T> CheckedFuture<T, ReadFailedException> sendReadRequest(final AbstractReadTransactionRequest<?> request,
        final Consumer<Response<?, ?>> completer, final ListenableFuture<T> future) {
    // Check if a previous operation failed. If it has, do not bother sending anything and report a failure
    final Exception local = operationFailure;
    if (local != null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Previous operation failed", local));
    }

    // Make sure we send any modifications before issuing a read
    ensureFlushedBuider();
    sendRequest(request, completer);
    return MappingCheckedFuture.create(future, ReadFailedException.MAPPER);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:14,代码来源:RemoteProxyTransaction.java

示例14: UnknownDOMRpcRoutingTableEntry

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
UnknownDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> impls) {
    super(schemaPath, impls);
    unknownRpc = Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(
        new DOMRpcImplementationNotAvailableException("SchemaPath %s is not resolved to an RPC", schemaPath));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:6,代码来源:UnknownDOMRpcRoutingTableEntry.java


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