e174bb4154eb7aefd1c82e6d9ba997df7364d7d3
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / xpath / LazyXPathExpression.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.api.schema.xpath;
9
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;
17
18 /**
19  * Asynchronous interface to evaluation. It is functionally the same as an XPathExpression, but allows for asynchronous
20  * execution of evaluation of the expression.
21  *
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.
24  *
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>.
28  */
29 @Beta
30 @Deprecated
31 public interface LazyXPathExpression {
32     /**
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()}.
36      *
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.
39      *
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.
42      *
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.
46      *
47      *        [ FIXME: would it be appropriate to allow implementations to SneakyThrow {@link XPathExpressionException}
48      *                 and not introduce a RuntimeExpcetion ? ]
49      *
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
55      */
56     CheckedFuture<Optional<? extends XPathResult<?>>, XPathExpressionException> evaluateLazily(
57             @Nonnull XPathDocument document, @Nonnull YangInstanceIdentifier path);
58 }