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.jenkinsci.plugins.workflow.cps.CpsStepContext.java

private @Nonnull CpsThreadGroup getThreadGroupSynchronously() throws InterruptedException, IOException {
    if (threadGroup == null) {
        ListenableFuture<CpsThreadGroup> pp;
        CpsFlowExecution flowExecution = getFlowExecution();
        while ((pp = flowExecution.programPromise) == null) {
            Thread.sleep(100); // TODO does JENKINS-33005 remove the need for this?
        }/*  w  w w. ja va2 s .  c o  m*/
        try {
            threadGroup = pp.get();
        } catch (ExecutionException e) {
            throw new IOException(e);
        }
    }
    return threadGroup;
}

From source file:org.opendaylight.laas.impl.CentinelLaasAlertConditionImpl.java

/**
 * @param change/*ww w  . j a  v a 2s.  co m*/
 * @param tx
 *            Deletes data from operational data store if successfully
 *            deleted from Log analyzer
 */
private void removeFromOperational(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change,
        final ReadWriteTransaction tx) {
    DataObject deletedDataObjectFromConfig = null;
    Entry<InstanceIdentifier<?>, DataObject> configRemovedEntrySet = null;

    Set<InstanceIdentifier<?>> configRemovedPath = change.getRemovedPaths();

    for (Entry<InstanceIdentifier<?>, DataObject> obj : change.getOriginalData().entrySet()) {
        if (configRemovedPath.contains(obj.getKey())) {
            configRemovedEntrySet = obj;
        }
    }

    try {

        deletedDataObjectFromConfig = configRemovedEntrySet.getValue();
        if (deletedDataObjectFromConfig instanceof StreamAlertMessageCountRuleList
                && configRemovedEntrySet != null) {
            StreamAlertMessageCountRuleList alertMessageCountConfigObj = (StreamAlertMessageCountRuleList) deletedDataObjectFromConfig;

            // Read operational data store
            ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFutureFromOperational = tx
                    .read(LogicalDatastoreType.OPERATIONAL, ALERTMESSAGECOUNTRULERECORDID);

            Optional<AlertMessageCountRuleRecord> alertMessageCountRuleRecord = readFutureFromOperational.get();

            List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

            if (alertMessageCountRuleRecord.isPresent()) {
                streamAlertRuleList = alertMessageCountRuleRecord.get().getStreamAlertMessageCountRuleList();

            }
            java.util.Iterator<StreamAlertMessageCountRuleList> iterator1 = streamAlertRuleList.iterator();

            while (iterator1.hasNext()) {
                StreamAlertMessageCountRuleList streamAlertMessageOperationalObj = iterator1.next();
                if (streamAlertMessageOperationalObj.getConfigID()
                        .equals(alertMessageCountConfigObj.getConfigID())
                        && restService.deleteFromOperational(streamAlertMessageOperationalObj)) {
                    // if following statement returns true then remove from
                    // operational data store
                    LOG.info("Deleted succesfully from Graylog");
                    tx.delete(LogicalDatastoreType.OPERATIONAL, ALERTMESSAGECOUNTRULERECORDID.child(
                            StreamAlertMessageCountRuleList.class, streamAlertMessageOperationalObj.getKey()));
                    tx.submit();
                }
            }

        }

        else if (deletedDataObjectFromConfig instanceof StreamAlertFieldContentRuleList
                && configRemovedEntrySet != null) {
            StreamAlertFieldContentRuleList alertFieldContentConfigObj = (StreamAlertFieldContentRuleList) deletedDataObjectFromConfig;

            // Read operational data store
            ListenableFuture<Optional<AlertFieldContentRuleRecord>> readFutureFromOperational = tx
                    .read(LogicalDatastoreType.OPERATIONAL, ALERTFIELDCONTENTRULERECORDID);

            Optional<AlertFieldContentRuleRecord> alertFieldContentRuleRecord = readFutureFromOperational.get();

            List<StreamAlertFieldContentRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldContentRuleList>();

            if (alertFieldContentRuleRecord.isPresent()) {
                streamAlertRuleList = alertFieldContentRuleRecord.get().getStreamAlertFieldContentRuleList();

            }
            java.util.Iterator<StreamAlertFieldContentRuleList> iterator1 = streamAlertRuleList.iterator();

            while (iterator1.hasNext()) {
                StreamAlertFieldContentRuleList streamAlertFieldContentOperationalObj = iterator1.next();
                if (streamAlertFieldContentOperationalObj.getConfigID()
                        .equals(alertFieldContentConfigObj.getConfigID())
                        && restService.deleteFromOperational(streamAlertFieldContentOperationalObj)) {
                    // if following statement returns true then remove from
                    // operational data store
                    LOG.info("Deleted succesfully from Graylog");
                    tx.delete(LogicalDatastoreType.OPERATIONAL,
                            ALERTFIELDCONTENTRULERECORDID.child(StreamAlertFieldContentRuleList.class,
                                    streamAlertFieldContentOperationalObj.getKey()));
                    tx.submit();
                }
            }

        } else if (deletedDataObjectFromConfig instanceof StreamAlertFieldValueRuleList
                && configRemovedEntrySet != null) {
            StreamAlertFieldValueRuleList alertFieldValueConfigObj = (StreamAlertFieldValueRuleList) deletedDataObjectFromConfig;

            // Read operational data store
            ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFutureFromOperational = tx
                    .read(LogicalDatastoreType.OPERATIONAL, ALERTFIELDVALUERULERECORDID);

            Optional<AlertFieldValueRuleRecord> alertFieldValueRuleRecord = readFutureFromOperational.get();

            List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();

            if (alertFieldValueRuleRecord.isPresent()) {
                streamAlertRuleList = alertFieldValueRuleRecord.get().getStreamAlertFieldValueRuleList();

            }
            java.util.Iterator<StreamAlertFieldValueRuleList> iterator1 = streamAlertRuleList.iterator();

            while (iterator1.hasNext()) {
                StreamAlertFieldValueRuleList streamAlertFieldValueOperationalObj = iterator1.next();
                if (streamAlertFieldValueOperationalObj.getConfigID()
                        .equals(alertFieldValueConfigObj.getConfigID())
                        && restService.deleteFromOperational(streamAlertFieldValueOperationalObj)) {
                    LOG.info("Deleted succesfully from Graylog");
                    tx.delete(LogicalDatastoreType.OPERATIONAL, ALERTFIELDVALUERULERECORDID.child(
                            StreamAlertFieldValueRuleList.class, streamAlertFieldValueOperationalObj.getKey()));
                    tx.submit();
                }
            }

        }
    } catch (Exception e) {
        LOG.error("Exception occured while getting record from operational data store", e);
    }
}

From source file:org.opendaylight.sdninterfaceapp.impl.SdniTopologyMsgServiceImpl.java

private List<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology> getAllTopologies() {

    List<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology> topo = new ArrayList<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology>();
    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology> ntII = InstanceIdentifier
            .builder(/*  w ww  . j  a v  a 2s.  c o m*/
                    org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology.class)
            .build();
    ListenableFuture<Optional<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology>> lfONT;
    try (ReadOnlyTransaction rot = dataService.newReadOnlyTransaction()) {
        lfONT = rot.read(LogicalDatastoreType.OPERATIONAL, ntII);
        rot.close();
    }
    Optional<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology> oNT;
    try {
        oNT = lfONT.get();
    } catch (InterruptedException | ExecutionException ex) {
        log.warn(ex.getLocalizedMessage());
        return null;
    }
    if (oNT != null && oNT.isPresent()) {
        org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology networkTopo = oNT
                .get();
        topo = networkTopo.getTopology();
    }
    return topo;
}

From source file:net.oneandone.troilus.ListReadQuery.java

/**
 * 12-11-2015: jwestra/*from w ww  .  j  a  v a 2s.  c  o  m*/
 * 
 * Prepares the Statement for Pagination, if fetchSize is set. Otherwise, it simply  
 * returns ReadQueryDataImpl.toStatementAsync(data, udtValueMapper, dbSession)
 * as in the original code did in executeAsync().
 * 
 * @param queryData
 * @param udtValueMapper
 * @param dbSession
 * 
 * @return ListenableFuture<Statement>
 */
private ListenableFuture<Statement> toStatementAsync(final ReadQueryData queryData,
        UDTValueMapper udtValueMapper, DBSession dbSession) {
    ListenableFuture<Statement> lfs = ReadQueryDataImpl.toStatementAsync(data, udtValueMapper, dbSession);

    Integer fetchSize = data.getFetchSize();
    if (fetchSize != null) {
        Statement statement = null;
        try {
            statement = lfs.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException("Failed to get the Statement from ListenableFuture<Statement>", e);
        }

        // The FetchSize is lost somehow when ReadQueryData.toStatementAsync() is invoked.
        // In the debugger, it was always zero.  So, it is reset here directly on the Statement
        // This sets the fetchsize specifically on the Statement before executing.
        statement.setFetchSize(fetchSize);

        // The PagingState is not set during ReadQueryData.toStatementAsync() because
        // the driver compares the Select (a RegularStatement) to the previous PagingState's
        // BoundStatement and fails the hash() check with a PagingStateException.
        // So, like the fetch size, the PagingState must be done here.
        statement.setPagingState(data.getPagingState());
    }
    return lfs;
}

From source file:org.apache.abdera2.common.protocol.Session.java

/**
 * Processes requests asynchronously.. the listener will
 * be invoked once the call completes//from  w ww .  ja  v  a  2 s.  c o m
 */
public <X extends ClientResponse> void process(ExecutorService executor, Callable<X> resp,
        final Listener<X> listener) {
    ListeningExecutorService exec = MoreExecutors.listeningDecorator(executor);
    final ListenableFuture<X> lf = exec.submit(resp);
    lf.addListener(new Runnable() {
        public void run() {
            X resp = null;
            try {
                resp = lf.get();
                listener.onResponse(resp);
            } catch (Throwable t) {
                throw ExceptionHelper.propogate(t);
            } finally { // auto release since by this point we know we're done with it
                if (resp != null)
                    resp.release();
            }
        }
    }, executor);
}

From source file:org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore.java

protected void visitMemento(final String phase, final BrooklynMementoRawData rawData, final Visitor visitor,
        final RebindExceptionHandler exceptionHandler) {
    List<ListenableFuture<?>> futures = Lists.newArrayList();

    class VisitorWrapper implements Runnable {
        private final BrooklynObjectType type;
        private final Map.Entry<String, String> objectIdAndData;

        public VisitorWrapper(BrooklynObjectType type, Map.Entry<String, String> objectIdAndData) {
            this.type = type;
            this.objectIdAndData = objectIdAndData;
        }//from  w w  w  .j  a  v  a2s . c  o  m

        public void run() {
            try {
                visitor.visit(type, objectIdAndData.getKey(), objectIdAndData.getValue());
            } catch (Exception e) {
                Exceptions.propagateIfFatal(e);
                exceptionHandler.onLoadMementoFailed(type,
                        "memento " + objectIdAndData.getKey() + " " + phase + " error", e);
            }
        }
    }

    for (BrooklynObjectType type : BrooklynPersistenceUtils.STANDARD_BROOKLYN_OBJECT_TYPE_PERSISTENCE_ORDER) {
        for (final Map.Entry<String, String> entry : rawData.getObjectsOfType(type).entrySet()) {
            futures.add(executor.submit(new VisitorWrapper(type, entry)));
        }
    }

    try {
        // Wait for all, failing fast if any exceptions.
        Futures.allAsList(futures).get();
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);

        List<Exception> exceptions = Lists.newArrayList();

        for (ListenableFuture<?> future : futures) {
            if (future.isDone()) {
                try {
                    future.get();
                } catch (InterruptedException e2) {
                    throw Exceptions.propagate(e2);
                } catch (ExecutionException e2) {
                    LOG.warn("Problem loading memento (" + phase + "): " + e2, e2);
                    exceptions.add(e2);
                }
                future.cancel(true);
            }
        }
        if (exceptions.isEmpty()) {
            throw Exceptions.propagate(e);
        } else {
            // Normally there should be at lesat one failure; otherwise all.get() would not have failed.
            throw new CompoundRuntimeException("Problem loading mementos (" + phase + ")", exceptions);
        }
    }
}

From source file:org.litecoinj.tools.WalletTool.java

private static void send(PaymentSession session) {
    try {/*from   w w w. jav  a2  s.c  om*/
        System.out.println("Payment Request");
        System.out.println("Coin: " + session.getValue().toFriendlyString());
        System.out.println("Date: " + session.getDate());
        System.out.println("Memo: " + session.getMemo());
        if (session.pkiVerificationData != null) {
            System.out.println("Pki-Verified Name: " + session.pkiVerificationData.displayName);
            System.out.println("PKI data verified by: " + session.pkiVerificationData.rootAuthorityName);
        }
        final SendRequest req = session.getSendRequest();
        if (password != null) {
            req.aesKey = passwordToKey(true);
            if (req.aesKey == null)
                return; // Error message already printed.
        }
        wallet.completeTx(req); // may throw InsufficientMoneyException.
        if (options.has("offline")) {
            wallet.commitTx(req.tx);
            return;
        }
        setup();
        // No refund address specified, no user-specified memo field.
        ListenableFuture<PaymentProtocol.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null,
                null);
        if (future == null) {
            // No payment_url for submission so, broadcast and wait.
            peers.start();
            peers.broadcastTransaction(req.tx).future().get();
        } else {
            PaymentProtocol.Ack ack = future.get();
            wallet.commitTx(req.tx);
            System.out.println("Memo from server: " + ack.getMemo());
        }
    } catch (PaymentProtocolException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (VerificationException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (ExecutionException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Invalid payment " + e.getMessage());
        System.exit(1);
    } catch (InterruptedException e1) {
        // Ignore.
    } catch (InsufficientMoneyException e) {
        System.err.println("Insufficient funds: have " + wallet.getBalance().toFriendlyString());
    } catch (BlockStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.opendaylight.laas.impl.CentinelLaasAlertConditionImpl.java

/**
 * @param change/*from   ww  w.j  av a2 s  . c  om*/
 * @param tx
 *            Updates data into operational data store if successfully
 *            updated in Log analyzer
 */
private void updateOperational(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change,
        final ReadWriteTransaction tx) {
    DataObject configUpdatedData = change.getUpdatedSubtree();
    DataObject configOriginalData = change.getOriginalSubtree();
    try {

        if (configUpdatedData instanceof AlertMessageCountRuleRecord
                && configOriginalData instanceof AlertMessageCountRuleRecord) {
            AlertMessageCountRuleRecord configUpdatedAlertMessageCountRuleRecord = (AlertMessageCountRuleRecord) configUpdatedData;
            AlertMessageCountRuleRecord configOriginalAlertMessageCountRuleRecord = (AlertMessageCountRuleRecord) configOriginalData;
            List<StreamAlertMessageCountRuleList> configUpdatedAlertMessageCountRuleList = configUpdatedAlertMessageCountRuleRecord
                    .getStreamAlertMessageCountRuleList();
            List<StreamAlertMessageCountRuleList> configOriginalAlertMessageCountRuleList = configOriginalAlertMessageCountRuleRecord
                    .getStreamAlertMessageCountRuleList();
            StreamAlertMessageCountRuleList alertMessageCountRuleList = null;
            Iterator<StreamAlertMessageCountRuleList> iteratorz = configUpdatedAlertMessageCountRuleList
                    .iterator();
            while (iteratorz.hasNext()) {
                StreamAlertMessageCountRuleList anObj = null;
                anObj = iteratorz.next();
                if (!configOriginalAlertMessageCountRuleList.contains(anObj)) {
                    alertMessageCountRuleList = anObj;
                    break;
                }
            }

            // Read operational data store
            ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFutureFromOperational = tx
                    .read(LogicalDatastoreType.OPERATIONAL, ALERTMESSAGECOUNTRULERECORDID);

            Optional<AlertMessageCountRuleRecord> alertMessageCountRuleRecord = readFutureFromOperational.get();

            List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

            if (alertMessageCountRuleRecord.isPresent()) {
                streamAlertRuleList = alertMessageCountRuleRecord.get().getStreamAlertMessageCountRuleList();
            }

            java.util.Iterator<StreamAlertMessageCountRuleList> iterator1 = streamAlertRuleList.iterator();

            while (iterator1.hasNext()) {
                StreamAlertMessageCountRuleList streamAlertMessageOperationalObj = iterator1.next();
                LOG.info("Operational Data store .getConfigID()"
                        + streamAlertMessageOperationalObj.getConfigID());
                LOG.info("Config data store .getConfigID() " + alertMessageCountRuleList.getConfigID());
                if (streamAlertMessageOperationalObj.getConfigID()
                        .equals(alertMessageCountRuleList.getConfigID())
                        && restService.updateToOperational(alertMessageCountRuleList)) {
                    tx.merge(LogicalDatastoreType.OPERATIONAL,
                            ALERTMESSAGECOUNTRULERECORDID.child(StreamAlertMessageCountRuleList.class,
                                    streamAlertMessageOperationalObj.getKey()),
                            alertMessageCountRuleList);
                    tx.submit();
                }
            }
        } else if (configUpdatedData instanceof AlertFieldContentRuleRecord
                && configOriginalData instanceof AlertFieldContentRuleRecord) {
            AlertFieldContentRuleRecord configUpdatedAlertFieldContentRuleRecord = (AlertFieldContentRuleRecord) configUpdatedData;
            AlertFieldContentRuleRecord configOriginalAlertFieldContentRuleRecord = (AlertFieldContentRuleRecord) configOriginalData;
            List<StreamAlertFieldContentRuleList> configUpdatedAlertFieldContentRuleList = configUpdatedAlertFieldContentRuleRecord
                    .getStreamAlertFieldContentRuleList();
            List<StreamAlertFieldContentRuleList> configOriginalAlertFieldContentRuleList = configOriginalAlertFieldContentRuleRecord
                    .getStreamAlertFieldContentRuleList();
            StreamAlertFieldContentRuleList alertFieldContentRuleList = null;
            Iterator<StreamAlertFieldContentRuleList> iteratorz = configUpdatedAlertFieldContentRuleList
                    .iterator();
            while (iteratorz.hasNext()) {
                StreamAlertFieldContentRuleList anObj = null;
                anObj = iteratorz.next();
                if (!configOriginalAlertFieldContentRuleList.contains(anObj)) {
                    alertFieldContentRuleList = anObj;
                    break;
                }
            }

            // Read operational data store
            ListenableFuture<Optional<AlertFieldContentRuleRecord>> readFutureFromOperational = tx
                    .read(LogicalDatastoreType.OPERATIONAL, ALERTFIELDCONTENTRULERECORDID);

            Optional<AlertFieldContentRuleRecord> alertFieldContentRuleRecord = readFutureFromOperational.get();

            List<StreamAlertFieldContentRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldContentRuleList>();

            if (alertFieldContentRuleRecord.isPresent()) {
                streamAlertRuleList = alertFieldContentRuleRecord.get().getStreamAlertFieldContentRuleList();
            }

            java.util.Iterator<StreamAlertFieldContentRuleList> iterator1 = streamAlertRuleList.iterator();

            while (iterator1.hasNext()) {
                StreamAlertFieldContentRuleList streamAlertFieldContentOperationalObj = iterator1.next();
                LOG.info("Operational Data store .getConfigID()"
                        + streamAlertFieldContentOperationalObj.getConfigID());
                LOG.info("Config data store .getConfigID() " + alertFieldContentRuleList.getConfigID());
                if (streamAlertFieldContentOperationalObj.getConfigID()
                        .equals(alertFieldContentRuleList.getConfigID())
                        && restService.updateToOperational(alertFieldContentRuleList)) {
                    tx.merge(LogicalDatastoreType.OPERATIONAL,
                            ALERTFIELDCONTENTRULERECORDID.child(StreamAlertFieldContentRuleList.class,
                                    streamAlertFieldContentOperationalObj.getKey()),
                            alertFieldContentRuleList);
                    tx.submit();
                }
            }
        } else if (configUpdatedData instanceof AlertFieldValueRuleRecord
                && configOriginalData instanceof AlertFieldValueRuleRecord) {
            AlertFieldValueRuleRecord configUpdatedAlertFieldValueRuleRecord = (AlertFieldValueRuleRecord) configUpdatedData;
            AlertFieldValueRuleRecord configOriginalAlertFieldValueRuleRecord = (AlertFieldValueRuleRecord) configOriginalData;
            List<StreamAlertFieldValueRuleList> configUpdatedAlertFieldValueRuleList = configUpdatedAlertFieldValueRuleRecord
                    .getStreamAlertFieldValueRuleList();
            List<StreamAlertFieldValueRuleList> configOriginalAlertFieldValueRuleList = configOriginalAlertFieldValueRuleRecord
                    .getStreamAlertFieldValueRuleList();
            StreamAlertFieldValueRuleList alertFieldValueRuleList = null;
            Iterator<StreamAlertFieldValueRuleList> iteratorz = configUpdatedAlertFieldValueRuleList.iterator();
            while (iteratorz.hasNext()) {
                StreamAlertFieldValueRuleList anObj = null;
                anObj = iteratorz.next();
                if (!configOriginalAlertFieldValueRuleList.contains(anObj)) {
                    alertFieldValueRuleList = anObj;
                    break;
                }
            }

            // Read operational data store
            ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFutureFromOperational = tx
                    .read(LogicalDatastoreType.OPERATIONAL, ALERTFIELDVALUERULERECORDID);

            Optional<AlertFieldValueRuleRecord> alertFieldValueRuleRecord = readFutureFromOperational.get();

            List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();

            if (alertFieldValueRuleRecord.isPresent()) {
                streamAlertRuleList = alertFieldValueRuleRecord.get().getStreamAlertFieldValueRuleList();
            }

            java.util.Iterator<StreamAlertFieldValueRuleList> iterator1 = streamAlertRuleList.iterator();

            while (iterator1.hasNext()) {
                StreamAlertFieldValueRuleList streamAlertFieldValueOperationalObj = iterator1.next();
                LOG.info("Operational Data store .getConfigID()"
                        + streamAlertFieldValueOperationalObj.getConfigID());
                LOG.info("Config data store .getConfigID() " + alertFieldValueRuleList.getConfigID());
                if (streamAlertFieldValueOperationalObj.getConfigID()
                        .equals(alertFieldValueRuleList.getConfigID())
                        && restService.updateToOperational(alertFieldValueRuleList)) {
                    tx.merge(LogicalDatastoreType.OPERATIONAL,
                            ALERTFIELDVALUERULERECORDID.child(StreamAlertFieldValueRuleList.class,
                                    streamAlertFieldValueOperationalObj.getKey()),
                            alertFieldValueRuleList);
                    tx.submit();
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Exception occured while getting record from operational data store", e);
    }
}

From source file:org.litecoinj.tools.WalletTool.java

private static void sendPaymentRequest(String location, boolean verifyPki) {
    if (location.startsWith("http") || location.startsWith("litecoin")) {
        try {/*from w  w  w  .  j  av  a 2s  .c  o m*/
            ListenableFuture<PaymentSession> future;
            if (location.startsWith("http")) {
                future = PaymentSession.createFromUrl(location, verifyPki);
            } else {
                BitcoinURI paymentRequestURI = new BitcoinURI(location);
                future = PaymentSession.createFromBitcoinUri(paymentRequestURI, verifyPki);
            }
            PaymentSession session = future.get();
            if (session != null) {
                send(session);
            } else {
                System.err.println("Server returned null session");
                System.exit(1);
            }
        } catch (PaymentProtocolException e) {
            System.err.println("Error creating payment session " + e.getMessage());
            System.exit(1);
        } catch (BitcoinURIParseException e) {
            System.err.println("Invalid litecoin uri: " + e.getMessage());
            System.exit(1);
        } catch (InterruptedException e) {
            // Ignore.
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    } else {
        // Try to open the payment request as a file.
        FileInputStream stream = null;
        try {
            File paymentRequestFile = new File(location);
            stream = new FileInputStream(paymentRequestFile);
        } catch (Exception e) {
            System.err.println("Failed to open file: " + e.getMessage());
            System.exit(1);
        }
        try {
            paymentRequest = org.litecoin.protocols.payments.Protos.PaymentRequest.newBuilder()
                    .mergeFrom(stream).build();
        } catch (IOException e) {
            System.err.println("Failed to parse payment request from file " + e.getMessage());
            System.exit(1);
        }
        PaymentSession session = null;
        try {
            session = new PaymentSession(paymentRequest, verifyPki);
        } catch (PaymentProtocolException e) {
            System.err.println("Error creating payment session " + e.getMessage());
            System.exit(1);
        }
        send(session);
    }
}

From source file:io.druid.query.aggregation.atomcube.AtomCubeQueryRunner.java

private boolean subQuerySucceed(final ListenableFuture<List<ImmutableBitmap>> futures,
        final AtomCubeQuery atomQ) {
    boolean ret = false;
    final Number timeout = atomQ.getContextValue(QueryContextKeys.TIMEOUT, (Number) null);
    List<ImmutableBitmap> bitmaps = null;
    try {//from   ww w .j  a v  a  2 s . c o m
        if (timeout == null) {
            bitmaps = futures.get();
        } else {
            bitmaps = futures.get(timeout.longValue(), TimeUnit.MILLISECONDS);
        }
    } catch (ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    } catch (InterruptedException e) {
        log.warn(e, "Query interrupted, cancelling pending results, query id [%s]", atomQ.getId());
        futures.cancel(true);
        throw new QueryInterruptedException(e);
    } catch (TimeoutException e) {
        log.info("Query timeout, cancelling pending results for query id [%s]", atomQ.getId());
        futures.cancel(true);
        throw new QueryInterruptedException(e);
    } finally {
        if (bitmaps != null && atomQ.getQueries().size() == bitmaps.size()) {
            log.debug("sub queries done!");
            ret = true;
        } else {
            log.error(
                    "not all sub queries response correctly, but set \"done\" be true to let the progress continue!!!");
            logQueryStack();
        }
        queryStack.clear();
    }
    return ret;
}