2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.api.schema.xpath;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import java.util.concurrent.Future;
14 import javax.annotation.Nonnull;
15 import javax.xml.xpath.XPathExpressionException;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 * Asynchronous interface to evaluation. It is functionally the same as an XPathExpression, but allows for asynchronous
20 * execution of evaluation of the expression.
22 * FIXME: Whether or not the resulting XPathResult can perform blocking calls is up for grabs, but implementations are
23 * definitely allowed to perform things like on-demand data transformation from foreign object and data models.
25 * @deprecated PREVIEW API. DO NOT IMPLEMENT YET AS THIS NEEDS TO BE VALIDATED FOR USE IN CLIENT APPLICATIONS.
26 * APPLICATIONS WILLING TO USE THIS API PLEASE CONTACT
27 * <a href="mailto:yangtools-dev@lists.opendaylight.org">yangtools-dev</a>.
31 public interface LazyXPathExpression {
33 * Evaluate this expression at the specified path in a document. If evaluation succeeds, it will return an
34 * {@link XPathResult} at some point it the future. If it fails to match anything, it {@link Future#get()} will
35 * return {@link Optional#absent()}.
37 * FIXME: The amount of overhead an implementation can incur on the user as data from the resulting
38 * {@link XPathResult} is being accessed is left UNDEFINED.
40 * Specifically, the user is expected to store each result returned directly or indirectly in a local
41 * variable instead of repeated calls to the result's methods, as these may incur CPU processing overhead.
43 * Furthermore all method invocations can throw {@link LazyXPathExpressionException}, which the users are
44 * expected to handle gracefully. RESILIENT USERS ARE EXPECTED TO CATCH {@link LazyXPathExpressionException}
45 * AND RECOVER IN THE SAME MANNER THEY WOULD IF AN {@link XPathExpressionException} WOULD HAVE BEEN THROWN.
47 * [ FIXME: would it be appropriate to allow implementations to SneakyThrow {@link XPathExpressionException}
48 * and not introduce a RuntimeExpcetion ? ]
50 * @param document {@link XPathDocument} on which evaluation should take place
51 * @param path Path to the node on which to evaluate the expression
52 * @return An optional {@link XPathResult}
53 * @throws NullPointerException if any of the arguments are null
54 * @throws IllegalArgumentException if the path does not match the path at which this expression was compiled
56 CheckedFuture<Optional<? extends XPathResult<?>>, XPathExpressionException> evaluateLazily(
57 @Nonnull XPathDocument document, @Nonnull YangInstanceIdentifier path);