All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.jsonrpc.provider.cluster.tx.FailedProxyTransaction Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020 Lumina Networks, Inc. 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.jsonrpc.provider.cluster.tx;

import com.google.common.util.concurrent.FluentFuture;
import java.util.Objects;
import java.util.Optional;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class FailedProxyTransaction implements ProxyTransactionFacade {
    private static final Logger LOG = LoggerFactory.getLogger(FailedProxyTransaction.class);

    private final String name;
    private final Throwable failure;
    private final FluentFuture completionFuture;

    FailedProxyTransaction(final String name, final Throwable failure) {
        this.name = Objects.requireNonNull(name);
        this.failure = Objects.requireNonNull(failure);
        completionFuture = FluentFutures.immediateFailedFluentFuture(
            failure instanceof TransactionCommitFailedException tcfe ? tcfe :
                new TransactionCommitFailedException("commit", failure));
    }

    @Override
    public Object getIdentifier() {
        return name;
    }

    @Override
    public FluentFuture> read(final LogicalDatastoreType store,
            final YangInstanceIdentifier path) {
        LOG.debug("[{}][FAILED] Read {} {}", name, store, path, failure);
        return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER
                .apply(failure instanceof Exception ex ? ex : new ReadFailedException("read", failure)));
    }

    @Override
    public FluentFuture exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
        LOG.debug("[{}][FAILED] Exists {} {}", name, store, path, failure);
        return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
                failure instanceof Exception ex ? ex : new ReadFailedException("exists", failure)));
    }

    @Override
    public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
        LOG.debug("[{}][FAILED] Delete {} {}", name, store, path, failure);
    }

    @Override
    public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
        LOG.debug("[{}][FAILED] Put {} {} - failure", name, store, path, failure);
    }

    @Override
    public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
        LOG.debug("[{}][FAILED] Merge {} {}", name, store, path, failure);
    }

    @Override
    public boolean cancel() {
        LOG.debug("[{}][FAILED] Cancel", name, failure);
        return true;
    }

    @Override
    public FluentFuture commit() {
        LOG.debug("[{}][FAILED] Commit", name, failure);
        return completionFuture;
    }

    @Override
    public FluentFuture completionFuture() {
        return completionFuture;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy