Example usage for com.google.common.util.concurrent CheckedFuture checkedGet

List of usage examples for com.google.common.util.concurrent CheckedFuture checkedGet

Introduction

In this page you can find the example usage for com.google.common.util.concurrent CheckedFuture checkedGet.

Prototype

V checkedGet() throws X;

Source Link

Document

Exception checking version of Future#get() that will translate InterruptedException , CancellationException and ExecutionException into application-specific exceptions.

Usage

From source file:org.opendaylight.sfc.pot.netconf.renderer.utils.SfcPotNetconfReaderWriterAPI.java

public static <T extends DataObject> boolean put(DataBroker broker, LogicalDatastoreType logicalDatastoreType,
        InstanceIdentifier<T> iid, T dataObject) {
    try {/*from   w w  w . jav  a 2  s.  c om*/
        WriteTransaction tx = broker.newWriteOnlyTransaction();
        tx.put(logicalDatastoreType, iid, dataObject);
        CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
        future.checkedGet();

        return true;
    } catch (TransactionCommitFailedException e) {
        LOG.warn("iOAM:PoT:SB:Netconf put to nodeid: failed:", e);
        return false;
    }
}

From source file:org.opendaylight.sfc.pot.netconf.renderer.utils.SfcPotNetconfReaderWriterAPI.java

public static <T extends DataObject> boolean delete(DataBroker broker,
        LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> iid) {
    try {/*  www. j a  v a2s.c  o  m*/
        WriteTransaction tx = broker.newWriteOnlyTransaction();
        tx.delete(logicalDatastoreType, iid);
        CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
        future.checkedGet();

        return true;
    } catch (TransactionCommitFailedException e) {
        LOG.warn("iOAM:PoT:SB:Netconf delete to nodeid failed:", e);
        return false;
    }
}

From source file:org.opendaylight.groupbasedpolicy.util.DataStoreHelper.java

/**
 * Calls {@link WriteTransaction#submit()} on write transaction.
 * @param wTx write transaction//from  www  .j  a v a 2 s.  c o  m
 * @return {@code true} if transaction commit was successful; {@code false} otherwise
 */
public static boolean submitToDs(WriteTransaction wTx) {
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = wTx.submit();
    try {
        submitFuture.checkedGet();
        return true;
    } catch (TransactionCommitFailedException e) {
        LOG.warn("Transaction commit failed to DS.", e);
        return false;
    }
}

From source file:org.opendaylight.groupbasedpolicy.util.DataStoreHelper.java

/**
 * Reads data from datastore as synchrone call.
 * @return {@link Optional#isPresent()} is {@code true} if reading was successful and data exists in datastore; {@link Optional#isPresent()} is {@code false} otherwise
 *//* w  w  w  .  j  a  va 2  s.c o m*/
public static <T extends DataObject> Optional<T> readFromDs(LogicalDatastoreType store,
        InstanceIdentifier<T> path, ReadTransaction rTx) {
    CheckedFuture<Optional<T>, ReadFailedException> resultFuture = rTx.read(store, path);
    try {
        return resultFuture.checkedGet();
    } catch (ReadFailedException e) {
        LOG.warn("Read failed from DS.", e);
        return Optional.absent();
    }
}

From source file:org.opendaylight.faas.fabricmgr.FabMgrDatastoreUtil.java

public static <T extends DataObject> Optional<T> readData(final LogicalDatastoreType storeType,
        final InstanceIdentifier<T> path) {
    final ReadTransaction tx = FabMgrDatastoreDependency.getDataProvider().newReadOnlyTransaction();
    CheckedFuture<Optional<T>, ReadFailedException> resultFuture = tx.read(storeType, path);
    try {//from w ww. ja  v a2s. co  m
        return resultFuture.checkedGet();
    } catch (ReadFailedException e) {
        LOG.error("FABMGR: ERROR: Read failed from DS.", e);
        return Optional.absent();
    }
}

From source file:org.opendaylight.sfc.sfc_netconf.provider.api.SfcNetconfReaderWriterAPI.java

public static <T extends DataObject> boolean put(NodeId nodeId, LogicalDatastoreType logicalDatastoreType,
        InstanceIdentifier<T> iid, T dataObject) {
    boolean ret;//ww  w .j  a va 2s.c om
    if (mountPointService == null) {
        mountPointService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService();
    }
    try {
        Optional<MountPoint> mountPointOptional = mountPointService
                .getMountPoint(NETCONF_TOPO_IID.child(Node.class, new NodeKey(nodeId)));
        DataBroker broker = mountPointOptional.get().getService(DataBroker.class).get();

        WriteTransaction tx = broker.newWriteOnlyTransaction();
        tx.put(logicalDatastoreType, iid, dataObject);
        CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
        future.checkedGet();
        ret = true;
    } catch (Exception e) {
        LOG.error("Netconf put failed: {}", e.getMessage());
        ret = false;
    }
    return ret;
}

From source file:org.opendaylight.sfc.sfc_netconf.provider.api.SfcNetconfReaderWriterAPI.java

public static <T extends DataObject> boolean merge(NodeId nodeId, LogicalDatastoreType logicalDatastoreType,
        InstanceIdentifier<T> iid, T dataObject) {
    boolean ret;/*from   w  ww.  j a  v a 2 s.c  o m*/
    if (mountPointService == null) {
        mountPointService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService();
    }
    try {
        Optional<MountPoint> mountPointOptional = mountPointService
                .getMountPoint(NETCONF_TOPO_IID.child(Node.class, new NodeKey(nodeId)));
        DataBroker broker = mountPointOptional.get().getService(DataBroker.class).get();

        WriteTransaction tx = broker.newWriteOnlyTransaction();
        tx.merge(logicalDatastoreType, iid, dataObject);
        CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
        future.checkedGet();
        ret = true;
    } catch (Exception e) {
        LOG.error("Netconf merge failed: {}", e.getMessage());
        ret = false;
    }
    return ret;
}

From source file:org.opendaylight.sfc.sfc_netconf.provider.api.SfcNetconfReaderWriterAPI.java

public static <T extends DataObject> boolean delete(NodeId nodeId, LogicalDatastoreType logicalDatastoreType,
        InstanceIdentifier<T> iid) {
    boolean ret;//from  w  w w.ja  v a2 s .  c  o  m
    if (mountPointService == null) {
        mountPointService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService();
    }
    try {
        Optional<MountPoint> mountPointOptional = mountPointService
                .getMountPoint(NETCONF_TOPO_IID.child(Node.class, new NodeKey(nodeId)));
        DataBroker broker = mountPointOptional.get().getService(DataBroker.class).get();

        WriteTransaction tx = broker.newWriteOnlyTransaction();
        tx.delete(logicalDatastoreType, iid);
        CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
        future.checkedGet();
        ret = true;
    } catch (Exception e) {
        LOG.error("Netconf delete failed: {}", e.getMessage());
        ret = false;
    }
    return ret;
}

From source file:org.opendaylight.sfc.provider.api.SfcDataStoreAPI.java

public static <U extends org.opendaylight.yangtools.yang.binding.DataObject> boolean writeMergeTransactionAPI(
        InstanceIdentifier<U> addIID, U data, LogicalDatastoreType logicalDatastoreType) {
    boolean ret = false;
    if (dataProvider == null) {
        LOG.error("writeMergeTransactionAPI: dataProvider not initialized!");
        return ret;
    }/* w  w  w  .j  a  v a 2 s.  co m*/
    WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction();
    writeTx.merge(logicalDatastoreType, addIID, data, true);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
    try {
        submitFuture.checkedGet();
        ret = true;
    } catch (TransactionCommitFailedException e) {
        LOG.error("writeMergeTransactionAPI: Transaction failed. Message: {}", e.getMessage());
    }
    return ret;
}

From source file:org.opendaylight.sfc.provider.api.SfcDataStoreAPI.java

public static <U extends org.opendaylight.yangtools.yang.binding.DataObject> boolean writePutTransactionAPI(
        InstanceIdentifier<U> addIID, U data, LogicalDatastoreType logicalDatastoreType) {
    boolean ret = false;
    if (dataProvider == null) {
        LOG.error("writePutTransactionAPI: dataProvider not initialized!");
        return ret;
    }//from w  ww  .  java 2  s . com
    WriteTransaction writeTx = dataProvider.newWriteOnlyTransaction();
    writeTx.put(logicalDatastoreType, addIID, data, true);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
    try {
        submitFuture.checkedGet();
        ret = true;
    } catch (TransactionCommitFailedException e) {
        LOG.error("writePutTransactionAPI: Transaction failed. Message: {}", e.getMessage());
    }
    return ret;
}