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.dsbenchmark.simpletx.SimpletxBaRead.java

@Override
public void executeList() {
    ReadTransaction tx = dataBroker.newReadOnlyTransaction();

    for (long l = 0; l < outerListElem; l++) {

        OuterList outerList;//from  w w w. j ava2s.  com
        InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class,
                new OuterListKey((int) l));
        Optional<OuterList> optionalDataObject;
        CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx
                .read(LogicalDatastoreType.CONFIGURATION, iid);
        try {
            optionalDataObject = submitFuture.checkedGet();
            if (optionalDataObject != null && optionalDataObject.isPresent()) {
                outerList = optionalDataObject.get();

                String[] objectsArray = new String[outerList.getInnerList().size()];

                //LOG.info("innerList element: " + objectsArray );
                for (InnerList innerList : outerList.getInnerList()) {
                    if (objectsArray[innerList.getName()] != null) {
                        LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
                                innerList.getValue());
                    }
                    objectsArray[innerList.getName()] = innerList.getValue();
                    // LOG.info("innerList: name: {}, value: {}", innerList.getName(), innerList.getValue());
                }
                boolean foundAll = true;
                for (int i = 0; i < outerList.getInnerList().size(); i++) {
                    String itemStr = objectsArray[i];
                    if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
                        foundAll = false;
                        LOG.error("innerList: name: {}, value: {}", i, itemStr);
                        break;
                    }
                }
                txOk++;
            } else {
                txError++;
            }
        } catch (ReadFailedException e) {
            LOG.warn("failed to ....", e);
            txError++;
        }
    }

}

From source file:org.opendaylight.vtn.manager.neutron.impl.MdsalUtils.java

/**
 * Executes delete as a blocking transaction.
 *
 * @param store {@link LogicalDatastoreType} which should be modified
 * @param path {@link InstanceIdentifier} to read from
 * @param <D> the data object type
 * @return the result of the request/*from  w ww  .j a v  a  2s . co m*/
 */
public <D extends DataObject> boolean delete(final LogicalDatastoreType store,
        final InstanceIdentifier<D> path) {
    boolean result = false;
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.delete(store, path);
    CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
    try {
        future.checkedGet();
        result = true;
    } catch (TransactionCommitFailedException e) {
        LOG.warn("Failed to delete {} ", path, e);
    }
    return result;
}

From source file:org.opendaylight.vtn.manager.neutron.impl.MdsalUtils.java

/**
 * Executes merge as a blocking transaction.
 *
 * @param <D> the data object type
 * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
 * @param path {@link InstanceIdentifier} for path to read
 * @param data the data object of type D
 * @return the result of the request/*from  ww  w  . ja  v a 2s.c  om*/
 */
public <D extends DataObject> boolean merge(final LogicalDatastoreType logicalDatastoreType,
        final InstanceIdentifier<D> path, D data) {
    boolean result = false;
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.merge(logicalDatastoreType, path, data, true);
    CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
    try {
        future.checkedGet();
        result = true;
    } catch (TransactionCommitFailedException e) {
        LOG.warn("Failed to merge {} ", path, e);
    }
    return result;
}

From source file:org.opendaylight.vtn.manager.neutron.impl.MdsalUtils.java

/**
 * Executes put as a blocking transaction.
 *
 * @param <D> the data object type
 * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
 * @param path {@link InstanceIdentifier} for path to read
 * @param data the data object of type D
 * @return the result of the request// www .  j  a  v  a 2  s .  com
 */
public <D extends DataObject> boolean put(final LogicalDatastoreType logicalDatastoreType,
        final InstanceIdentifier<D> path, D data) {
    boolean result = false;
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(logicalDatastoreType, path, data, true);
    CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
    try {
        future.checkedGet();
        result = true;
    } catch (TransactionCommitFailedException e) {
        LOG.warn("Failed to put {} ", path, e);
    }
    return result;
}

From source file:org.opendaylight.vpnservice.neutronvpn.NeutronRouterChangeListener.java

private Set<Port> getInterfaces(final Uuid deviceId) {
    final Set<Port> interfaces = new HashSet<>();
    InstanceIdentifier<Ports> path = InstanceIdentifier.create(Neutron.class).child(Ports.class);

    try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
        final CheckedFuture<Optional<Ports>, ReadFailedException> future = tx
                .read(LogicalDatastoreType.CONFIGURATION, path);
        Optional<Ports> optional = future.checkedGet();
        if (optional.isPresent()) {
            for (final Port port : optional.get().getPort()) {
                if (port.getDeviceOwner().equals("network:router_interface")
                        && port.getDeviceId().equals(deviceId.getValue())) {
                    interfaces.add(port);
                }/*from w  w  w . ja va  2 s .  c  om*/
            }
        }
    } catch (final ReadFailedException e) {
        LOG.warn("Failed to read {}", path, e);
    }

    return interfaces;
}

From source file:org.opendaylight.netconf.messagebus.eventsources.netconf.StreamNotificationTopicRegistration.java

/**
 * Subscribes to notification stream associated with this registration. If replay is supported, notifications from last
 * received event time will be requested.
 *//* ww w  .ja v a 2  s.  com*/
void reActivateNotificationSource() {
    if (isActive()) {
        LOG.info("Stream {} is reactivating on node {}.", this.getStreamName(), this.nodeId);
        final CheckedFuture<DOMRpcResult, DOMRpcException> result;
        result = mountPoint.invokeCreateSubscription(stream, getLastEventTime());
        try {
            result.checkedGet();
            setActive(true);
        } catch (DOMRpcException e) {
            LOG.warn("Can not resubscribe stream {} on node {}", this.getSourceName(), this.nodeId);
            setActive(false);
        }
    }
}

From source file:org.opendaylight.ofconfig.southbound.impl.topology.OfconfigTopoHandler.java

public void addOfconfigNode(NodeId netconfNodeId, NetconfNode netconfNode, MountPointService mountService,
        DataBroker dataBroker) throws TransactionCommitFailedException {

    final Optional<MountPoint> capableSwichNodeOptional = mountService.getMountPoint(
            OfconfigConstants.NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(netconfNodeId))));

    final MountPoint capableSwichMountPoint = capableSwichNodeOptional.get();

    final DataBroker capableSwichNodeBroker = capableSwichMountPoint.getService(DataBroker.class).get();

    final ReadOnlyTransaction capableSwichNodeReadTx = capableSwichNodeBroker.newReadOnlyTransaction();

    Optional<CapableSwitch> capableSwitchConfig = helper.getCapableSwitchCinfigureFromOfDevice(netconfNodeId,
            capableSwichNodeReadTx);//w w  w.  j a v  a  2 s  .  com

    if (capableSwitchConfig.isPresent()) {
        BindingTransactionChain chain = null;
        try {
            chain = dataBroker.createTransactionChain(this);
            final WriteTransaction invTopoWriteTx = chain.newWriteOnlyTransaction();

            addCapableSwitchTopoNodeAttributes(netconfNodeId, capableSwitchConfig, invTopoWriteTx);
            addLogicalSwitchTopoNodeAttributes(netconfNodeId, capableSwitchConfig, invTopoWriteTx);

            CheckedFuture<Void, TransactionCommitFailedException> future = invTopoWriteTx.submit();
            try {
                future.checkedGet();
            } catch (TransactionCommitFailedException e) {
                LOG.warn("{} of-config switch failed to merge Inventory topology ", netconfNode, e);
                throw e;

            }
        } finally {
            if (chain != null) {
                chain.close();
            }
        }
    } else {
        throw new IllegalStateException("Unexpected error reading data from " + netconfNode);
    }

}

From source file:org.opendaylight.sfc.ofrenderer.utils.operDsUpdate.OperDsUpdateHandlerLSFFImpl.java

/**
 * Asynchronous commit of the passed transaction
 * @param trans The transaction to submit
 *///from  w ww  .  j  av  a  2  s.c  o  m
private void commitChangesAsync(WriteTransaction trans) {
    threadPoolExecutorService.submit(() -> {
        CheckedFuture<Void, TransactionCommitFailedException> submitFuture = trans.submit();
        try {
            submitFuture.checkedGet();
        } catch (TransactionCommitFailedException e) {
            LOG.error("commitChangesAsync: Transaction failed. Message: {}", e.getMessage(), e);
        }
    });
}

From source file:org.opendaylight.dsbenchmark.simpletx.SimpletxDomRead.java

@Override
public void executeList() {
    org.opendaylight.yangtools.yang.common.QName OL_ID = QName.create(OuterList.QNAME, "id");
    DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction();

    for (long l = 0; l < outerListElem; l++) {
        NormalizedNode<?, ?> ret = null;

        YangInstanceIdentifier yid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME)
                .nodeWithKey(OuterList.QNAME, OL_ID, l).build();
        Optional<NormalizedNode<?, ?>> optionalDataObject;
        CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> submitFuture = tx
                .read(LogicalDatastoreType.CONFIGURATION, yid);
        try {//  w ww  .j av a  2  s . c om
            optionalDataObject = submitFuture.checkedGet();
            if (optionalDataObject != null && optionalDataObject.isPresent()) {
                ret = optionalDataObject.get();
                LOG.info("/n" + String.valueOf(ret));
                txOk++;
            }
            /*if (optionalDataObject != null && optionalDataObject.isPresent()) {
            ret = optionalDataObject.get();
                    
            String[] objectsArray = new String[ret.getInnerList().size()];
                    
            //LOG.info("innerList element: " + objectsArray );
            for (InnerList innerList : ret.getInnerList()) {
                if (objectsArray[innerList.getName()] != null) {
                    LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(), innerList.getValue());
                }
                objectsArray[innerList.getName()] = innerList.getValue();
                // LOG.info("innerList: name: {}, value: {}", innerList.getName(), innerList.getValue());
            }
            boolean foundAll = true;
            for (int i = 0; i < ret.getInnerList().size(); i++) {
                String itemStr = objectsArray[i];
                if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
                    foundAll = false;
                    LOG.error("innerList: name: {}, value: {}", i, itemStr);
                    break;
                }
            }
            txOk++;
            }*/ else {
                txError++;
                LOG.info("In the else part");
            }
        } catch (ReadFailedException e) {
            LOG.warn("failed to ....", e);
            txError++;
        }
    }
}

From source file:eu.virtuwind.monitoring.impl.AddressMonitor.java

/**
 * Returns the node from a given ip address
 *//*from  www  .j  a  va2s  . c o  m*/
public Node getNodeFromIpAddress(String ipAddress) {
    LOG.info("Finding node with IP address {}. ", ipAddress);
    try {
        List<Node> nodeList = new ArrayList<>();
        InstanceIdentifier<Nodes> nodesIid = InstanceIdentifier.builder(Nodes.class).build();
        ReadOnlyTransaction nodesTransaction = db.newReadOnlyTransaction();
        CheckedFuture<Optional<Nodes>, ReadFailedException> nodesFuture = nodesTransaction
                .read(LogicalDatastoreType.OPERATIONAL, nodesIid);
        Optional<Nodes> nodesOptional = Optional.absent();
        nodesOptional = nodesFuture.checkedGet();

        if (nodesOptional != null && nodesOptional.isPresent()) {
            nodeList = nodesOptional.get().getNode();
        }

        if (nodeList != null) {
            for (Node n : nodeList) {
                List<NodeConnector> nodeConnectors = n.getNodeConnector();
                for (NodeConnector nc : nodeConnectors) {

                    AddressCapableNodeConnector acnc = nc.getAugmentation(AddressCapableNodeConnector.class);
                    if (acnc != null && acnc.getAddresses() != null) {
                        // get address list from augmentation.
                        List<Addresses> addresses = acnc.getAddresses();
                        for (Addresses address : addresses) {
                            LOG.info("Checking address {} for connector {}",
                                    address.getIp().getIpv4Address().getValue(), nc.getId().getValue());
                            if (address.getIp().getIpv4Address().getValue().equals(ipAddress))
                                return n;
                        }
                    }

                }
            }
        }
    } catch (Exception e) {
        LOG.info("IP address reading failed");
    }
    return null;
}