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.
23 * FIXME: Whether or not the resulting XPathResult can perform blocking calls is up for grabs, but implementations are
24 * definitely allowed to perform things like on-demand data transformation from foreign object and data models.
26 * @deprecated PREVIEW API. DO NOT IMPLEMENT YET AS THIS NEEDS TO BE VALIDATED FOR USE IN CLIENT APPLICATIONS.
27 * APPLICATIONS WILLING TO USE THIS API PLEASE CONTACT
28 * <a href="mailto:yangtools-dev@lists.opendaylight.org">yangtools-dev</a>.
32 public interface LazyXPathExpression {
34 * Evaluate this expression at the specified path in a document. If evaluation succeeds, it will return an
35 * {@link XPathResult} at some point it the future. If it fails to match anything, it {@link Future#get()} will
36 * return {@link Optional#absent()}.
39 * FIXME: The amount of overhead an implementation can incur on the user as data from the resulting
40 * {@link XPathResult} is being accessed is left UNDEFINED.
41 * Specifically, the user is expected to store each result returned directly or indirectly in a local
42 * 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.
46 * [ FIXME: would it be appropriate to allow implementations to SneakyThrow {@link XPathExpressionException}
47 * and not introduce a RuntimeExpcetion ? ]
49 * @param document {@link XPathDocument} on which evaluation should take place
50 * @param path Path to the node on which to evaluate the expression
51 * @return An optional {@link XPathResult}
52 * @throws NullPointerException if any of the arguments are null
53 * @throws IllegalArgumentException if the path does not match the path at which this expression was compiled
55 CheckedFuture<Optional<? extends XPathResult<?>>, XPathExpressionException> evaluateLazily(
56 @Nonnull XPathDocument document, @Nonnull YangInstanceIdentifier path);