X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FLazyDOMRpcResultFuture.java;fp=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FLazyDOMRpcResultFuture.java;h=0000000000000000000000000000000000000000;hb=2611e6a728e586ea34dd891f30a473bf54d6cbd8;hp=dbdbf1d837a0f9c2e4ce949c69527cc07c2c296c;hpb=aaea3e9a92ae9d6fac04c4a065db4b35cbca9ed0;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/LazyDOMRpcResultFuture.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/LazyDOMRpcResultFuture.java deleted file mode 100644 index dbdbf1d837..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/LazyDOMRpcResultFuture.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.md.sal.binding.impl; - -import static java.util.Objects.requireNonNull; - -import com.google.common.base.Throwables; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; -import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult; -import org.opendaylight.mdsal.binding.dom.adapter.BindingRpcFutureAware; -import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.yangtools.yang.binding.DataContainer; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; - -@Deprecated(forRemoval = true) -final class LazyDOMRpcResultFuture implements CheckedFuture, BindingRpcFutureAware { - - private final ListenableFuture> bindingFuture; - private final BindingNormalizedNodeSerializer codec; - private volatile DOMRpcResult result; - - private LazyDOMRpcResultFuture(final ListenableFuture> delegate, - final BindingNormalizedNodeSerializer codec) { - this.bindingFuture = requireNonNull(delegate, "delegate"); - this.codec = requireNonNull(codec, "codec"); - } - - static CheckedFuture create(final BindingNormalizedNodeSerializer codec, - final ListenableFuture> bindingResult) { - return new LazyDOMRpcResultFuture(bindingResult, codec); - } - - @Override - public ListenableFuture> getBindingFuture() { - return bindingFuture; - } - - @Override - public boolean cancel(final boolean mayInterruptIfRunning) { - return bindingFuture.cancel(mayInterruptIfRunning); - } - - @Override - public void addListener(final Runnable listener, final Executor executor) { - bindingFuture.addListener(listener, executor); - } - - @Override - public DOMRpcResult get() throws InterruptedException, ExecutionException { - if (result != null) { - return result; - } - return transformIfNecessary(bindingFuture.get()); - } - - @Override - public DOMRpcResult get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, - TimeoutException { - if (result != null) { - return result; - } - return transformIfNecessary(bindingFuture.get(timeout, unit)); - } - - @Override - public DOMRpcResult checkedGet() { - try { - return get(); - } catch (InterruptedException | ExecutionException e) { - // FIXME: Add exception mapping - throw Throwables.propagate(e); - } - } - - @Override - public DOMRpcResult checkedGet(final long timeout, final TimeUnit unit) throws TimeoutException { - try { - return get(timeout, unit); - } catch (InterruptedException | ExecutionException e) { - // FIXME: Add exception mapping - throw Throwables.propagate(e); - } - } - - @Override - public boolean isCancelled() { - return bindingFuture.isCancelled(); - } - - @Override - public boolean isDone() { - return bindingFuture.isDone(); - } - - private synchronized DOMRpcResult transformIfNecessary(final RpcResult input) { - if (result == null) { - result = transform(input); - } - return result; - } - - private DOMRpcResult transform(final RpcResult input) { - if (input.isSuccessful()) { - final Object inputData = input.getResult(); - if (inputData instanceof DataContainer) { - return new DefaultDOMRpcResult(codec.toNormalizedNodeRpcData((DataContainer) inputData)); - } else { - return new DefaultDOMRpcResult((NormalizedNode) null); - } - } - return new DefaultDOMRpcResult(input.getErrors()); - } - -}