Example usage for com.google.common.util.concurrent ListenableFuture get

List of usage examples for com.google.common.util.concurrent ListenableFuture get

Introduction

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

Prototype

V get() throws InterruptedException, ExecutionException;

Source Link

Document

Waits if necessary for the computation to complete, and then retrieves its result.

Usage

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public boolean setNodeData(String topologyId, final BierNode node) {
    if (null == dataBroker || node == null) {
        LOG.error("Set bier node input is error!");
        return false;
    }//from ww w .  j  a  va 2  s  .c  om

    BierTopologyProcess<BierNode> processor = new BierTopologyProcess<BierNode>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierNodeBuilder()).build());
    final InstanceIdentifier<BierNode> path = getNodePath(topologyId, node.getNodeId());

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override
        public void writeOperation(ReadWriteTransaction transaction) {
            transaction.merge(datastoreType, path, node, true);
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<Node>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierNode>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierNode> result = future.get();
        if (null == result.get()) {
            LOG.error("Set bier node failed!");
            return false;
        }

        LOG.info("Set bier node succeed!");
        return true;
    } catch (InterruptedException e) {
        LOG.error("Set bier node is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Set bier node is faild cause by", e);
    }

    LOG.error("Set bier node failed!");
    return false;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public BierLink getLinkData(String topologyId, String linkId) {
    BierTopologyProcess<BierLink> processor = new BierTopologyProcess<BierLink>(dataBroker,
            BierTopologyProcess.FLAG_READ, (new BierLinkBuilder()).build());

    final InstanceIdentifier<BierTopology> topoPath = getTopoPath(topologyId);
    final InstanceIdentifier<BierLink> path = topoPath.child(BierLink.class, new BierLinkKey(linkId));

    processor.enqueueOperation(new BierTopologyOperation() {

        @Override/*from   w  w w.j  av a  2  s  .  c om*/
        public void writeOperation(ReadWriteTransaction transaction) {
            // Auto-generated method stub
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<BierLink>> readOperation(ReadWriteTransaction transaction) {
            ListenableFuture<Optional<BierLink>> listenableFuture = transaction.read(datastoreType, path);
            return listenableFuture;
        }
    });

    Future<ListenableFuture<BierLink>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierLink> result = future.get();
        BierLink link = result.get();
        if (null == link || null == link.getLinkId()) {
            LOG.error("Get bier link is faild!");
            return null;
        }
        return link;
    } catch (InterruptedException e) {
        LOG.error("Get bier link is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Get bier link is faild cause by", e);
    }
    LOG.error("Get bier link is faild!");
    return null;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public boolean delDomainData(final String topologyId, final DomainId domainId, final List<BierNode> nodeList) {
    if (null == dataBroker || null == domainId) {
        LOG.error("Del bier domain input is error!");
        return false;
    }//from  w  w  w . ja  va 2  s .  c o  m

    BierTopologyProcess<BierDomain> processor = new BierTopologyProcess<BierDomain>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierDomainBuilder()).build());
    final InstanceIdentifier<BierDomain> path = getDomainPath(topologyId, domainId);

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override
        public void writeOperation(ReadWriteTransaction transaction) {
            transaction.delete(datastoreType, path);
            updateAffectedDomainNode(transaction, topologyId, domainId, nodeList);
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<Node>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierDomain>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierDomain> result = future.get();
        if (null == result.get()) {
            LOG.error("Del bier domain failed!");
            return false;
        }

        LOG.info("Del bier domain succeed!");
        return true;
    } catch (InterruptedException e) {
        LOG.error("Del bier domain is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Del bier domain is faild cause by", e);
    }

    LOG.error("Del bier domain failed!");
    return false;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public void setTopologyData(final BierTopology bierTopology) {
    if (null == dataBroker || null == bierTopology) {
        LOG.error("Set Bier Topology input is error!");
        return;/*from   w  w  w. ja va  2  s . c  o m*/
    }

    BierTopologyProcess<BierTopology> processor = new BierTopologyProcess<BierTopology>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierTopologyBuilder()).build());

    final InstanceIdentifier<BierTopology> path = InstanceIdentifier.create(BierNetworkTopology.class)
            .child(BierTopology.class, bierTopology.getKey());
    processor.enqueueOperation(new BierTopologyOperation() {
        @Override
        public void writeOperation(ReadWriteTransaction transaction) {
            transaction.put(datastoreType, path, bierTopology, true);
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<BierTopology>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierTopology>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierTopology> result = future.get();
        if (null == result.get()) {
            LOG.error("Set bier topology failed!");
            return;
        }
        LOG.info("Set bier topology succeed!");
        return;
    } catch (InterruptedException e) {
        LOG.error("Set bier topology is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Set bier topology is faild cause by", e);
    }

    LOG.error("Set bier topology failed!");
    return;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public boolean delNodeFromDomain(String topologyId, final DomainId domainId, final SubDomainId subDomainId,
        final BierNode node) {
    BierTopologyProcess<BierNode> processor = new BierTopologyProcess<BierNode>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierNodeBuilder()).build());
    final InstanceIdentifier<BierNode> path = getNodePath(topologyId, node.getNodeId());

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override// w ww . j  av a 2 s .  c om
        public void writeOperation(ReadWriteTransaction transaction) {
            BierNodeBuilder newNodeBuilder = new BierNodeBuilder(node);
            int domainIndex = getDomainIndex(domainId, node);
            int subDomainIndex = getSubDomainIndex(domainId, subDomainId, node);
            List<SubDomain> newSubDomainList = newNodeBuilder.getBierNodeParams().getDomain().get(domainIndex)
                    .getBierGlobal().getSubDomain();
            newSubDomainList.remove(subDomainIndex);
            if (newSubDomainList.isEmpty()) {
                List<Domain> newDomainList = newNodeBuilder.getBierNodeParams().getDomain();
                newDomainList.remove(domainIndex);
            }
            transaction.put(datastoreType, path, newNodeBuilder.build());
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<BierNode>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierNode>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierNode> result = future.get();
        if (null == result.get()) {
            LOG.error("Del bier node failed!");
            return false;
        }

        LOG.info("Del bier node succeed!");
        return true;
    } catch (InterruptedException e) {
        LOG.error("Del bier node is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Del bier node is faild cause by", e);
    }

    LOG.error("Del bier Node failed!");
    return false;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public boolean setDomainData(final String topologyId, final List<BierDomain> domainList) {

    if (null == dataBroker || null == domainList || domainList.isEmpty()) {
        LOG.error("Set bier domain input is error!");
        return false;
    }/*from  w  w w  .  j a va2  s  . co m*/

    BierTopologyProcess<BierDomain> processor = new BierTopologyProcess<BierDomain>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierDomainBuilder()).build());

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override
        public void writeOperation(ReadWriteTransaction transaction) {
            int domainSize = domainList.size();
            for (int iloop = 0; iloop < domainSize; ++iloop) {
                BierDomain domain = domainList.get(iloop);
                final InstanceIdentifier<BierDomain> path = getDomainPath(topologyId, domain.getDomainId());
                transaction.put(datastoreType, path, domain, true);
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<Node>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierDomain>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierDomain> result = future.get();
        if (null == result.get()) {
            LOG.error("Set bier domain failed!");
            return false;
        }

        LOG.info("Set bier domain succeed!");
        return true;
    } catch (InterruptedException e) {
        LOG.error("Set bier domain is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Set bier domain is faild cause by", e);
    }

    LOG.error("Set bier domain failed!");
    return false;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public BierDomain getDomainData(String topologyId, DomainId domainId) {

    BierTopologyProcess<BierDomain> processor = new BierTopologyProcess<BierDomain>(dataBroker,
            BierTopologyProcess.FLAG_READ, (new BierDomainBuilder()).build());

    final InstanceIdentifier<BierDomain> path = getDomainPath(topologyId, domainId);

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override// w  w w .  j a va 2  s .c  o m
        public void writeOperation(ReadWriteTransaction transaction) {
            // Auto-generated method stub
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<BierDomain>> readOperation(ReadWriteTransaction transaction) {

            ListenableFuture<Optional<BierDomain>> listenableFuture = transaction.read(datastoreType, path);

            return listenableFuture;
        }
    });

    Future<ListenableFuture<BierDomain>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierDomain> result = future.get();
        BierDomain domain = result.get();
        if (null == domain || null == domain.getDomainId()) {
            LOG.error("Get bier domain is faild!");
            return null;
        }
        return domain;
    } catch (InterruptedException e) {
        LOG.error("Get bier domain is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Get bier domain is faild cause by", e);
    }
    LOG.error("Get bier domain is faild!");
    return null;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public boolean delSubDomainData(final String topologyId, final DomainId domainId, final SubDomainId subDomainId,
        final List<BierNode> nodeList) {

    if (null == dataBroker || null == domainId) {
        LOG.error("Del bier sub-domain input is error!");
        return false;
    }//from   w  ww  .  ja v a2s  .  c o  m

    BierTopologyProcess<BierSubDomain> processor = new BierTopologyProcess<BierSubDomain>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierSubDomainBuilder()).build());
    final InstanceIdentifier<BierSubDomain> path = getSubDomainPath(topologyId, domainId, subDomainId);

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override
        public void writeOperation(ReadWriteTransaction transaction) {
            transaction.delete(datastoreType, path);

            updateAffectedSubDomainNode(transaction, topologyId, domainId, subDomainId, nodeList);
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<Node>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierSubDomain>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierSubDomain> result = future.get();
        if (null == result.get()) {
            LOG.error("Del bier sub-domain failed!");
            return false;
        }

        LOG.info("Del bier sub-domain succeed!");
        return true;
    } catch (InterruptedException e) {
        LOG.error("Del bier sub-domain is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Del bier sub-domain is faild cause by", e);
    }

    LOG.error("Del bier sub-domain failed!");
    return false;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public BierTopology getTopologyData(String topologyId) {
    BierTopologyProcess<BierTopology> processor = new BierTopologyProcess<BierTopology>(dataBroker,
            BierTopologyProcess.FLAG_READ, (new BierTopologyBuilder()).build());
    final InstanceIdentifier<BierTopology> path = getTopoPath(topologyId);
    processor.enqueueOperation(new BierTopologyOperation() {
        @Override/*from  w w  w .j  a v  a2  s.  com*/
        public void writeOperation(ReadWriteTransaction transaction) {
            // Auto-generated method stub
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<BierTopology>> readOperation(ReadWriteTransaction transaction) {

            ListenableFuture<Optional<BierTopology>> listenableFuture = transaction.read(datastoreType, path);

            return listenableFuture;
        }
    });

    Future<ListenableFuture<BierTopology>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierTopology> result = future.get();
        BierTopology topology = result.get();
        if (null == topology || null == topology.getTopologyId()) {
            LOG.error("Get bier topology is faild!");
            return null;
        }
        return topology;
    } catch (InterruptedException e) {
        LOG.error("Get bier topology is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Get bier topology is faild cause by", e);
    }
    LOG.error("Get bier topology is faild!");
    return null;
}

From source file:org.opendaylight.topomanager.impl.BierTopologyManager.java

public boolean setSubDomainData(final String topologyId, final DomainId domainId,
        final List<BierSubDomain> subDomainList) {
    if (null == dataBroker || null == subDomainList || subDomainList.isEmpty()) {
        LOG.error("Set bier sub-domai input is error!");
        return false;
    }//from   w w  w .  j  av  a2  s .c  o m

    BierTopologyProcess<BierSubDomain> processor = new BierTopologyProcess<BierSubDomain>(dataBroker,
            BierTopologyProcess.FLAG_WRITE, (new BierSubDomainBuilder()).build());

    processor.enqueueOperation(new BierTopologyOperation() {
        @Override
        public void writeOperation(ReadWriteTransaction transaction) {
            int subDomainSize = subDomainList.size();
            for (int iloop = 0; iloop < subDomainSize; ++iloop) {
                BierSubDomain subDomain = subDomainList.get(iloop);
                final InstanceIdentifier<BierSubDomain> path = getSubDomainPath(topologyId, domainId,
                        subDomain.getSubDomainId());
                transaction.put(datastoreType, path, subDomain, true);
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public ListenableFuture<Optional<Node>> readOperation(ReadWriteTransaction transaction) {
            return null;
        }
    });

    Future<ListenableFuture<BierSubDomain>> future = EXECUTOR.submit(processor);

    try {
        ListenableFuture<BierSubDomain> result = future.get();
        if (null == result.get()) {
            LOG.error("Set bier sub-domain failed!");
            return false;
        }

        LOG.info("Set bier sub-domain succeed!");
        return true;
    } catch (InterruptedException e) {
        LOG.error("Set bier sub-domain is Interrupted by", e);
    } catch (ExecutionException e) {
        LOG.error("Set bier sub-domain is faild cause by", e);
    }

    LOG.error("Set bier sub-domain failed!");
    return false;
}