Search in sources :

Example 81 with FutureCallback

use of com.google.common.util.concurrent.FutureCallback in project bisq-core by bisq-network.

the class BtcWalletService method doubleSpendTransaction.

// /////////////////////////////////////////////////////////////////////////////////////////
// Double spend unconfirmed transaction (unlock in case we got into a tx with a too low mining fee)
// /////////////////////////////////////////////////////////////////////////////////////////
public void doubleSpendTransaction(String txId, Runnable resultHandler, ErrorMessageHandler errorMessageHandler) throws InsufficientFundsException {
    AddressEntry addressEntry = getFreshAddressEntry();
    checkNotNull(addressEntry.getAddress(), "addressEntry.getAddress() must not be null");
    Optional<Transaction> transactionOptional = wallet.getTransactions(true).stream().filter(t -> t.getHashAsString().equals(txId)).findAny();
    if (transactionOptional.isPresent()) {
        Transaction txToDoubleSpend = transactionOptional.get();
        Address toAddress = addressEntry.getAddress();
        final TransactionConfidence.ConfidenceType confidenceType = txToDoubleSpend.getConfidence().getConfidenceType();
        if (confidenceType == TransactionConfidence.ConfidenceType.PENDING) {
            log.debug("txToDoubleSpend no. of inputs " + txToDoubleSpend.getInputs().size());
            Transaction newTransaction = new Transaction(params);
            txToDoubleSpend.getInputs().stream().forEach(input -> {
                final TransactionOutput connectedOutput = input.getConnectedOutput();
                if (connectedOutput != null && connectedOutput.isMine(wallet) && connectedOutput.getParentTransaction() != null && connectedOutput.getParentTransaction().getConfidence() != null && input.getValue() != null) {
                    // if (connectedOutput.getParentTransaction().getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) {
                    newTransaction.addInput(new TransactionInput(params, newTransaction, new byte[] {}, new TransactionOutPoint(params, input.getOutpoint().getIndex(), new Transaction(params, connectedOutput.getParentTransaction().bitcoinSerialize())), Coin.valueOf(input.getValue().value)));
                /* } else {
                                    log.warn("Confidence of parent tx is not of type BUILDING: ConfidenceType=" +
                                            connectedOutput.getParentTransaction().getConfidence().getConfidenceType());
                                }*/
                }
            });
            log.info("newTransaction no. of inputs " + newTransaction.getInputs().size());
            log.info("newTransaction size in kB " + newTransaction.bitcoinSerialize().length / 1024);
            if (!newTransaction.getInputs().isEmpty()) {
                Coin amount = Coin.valueOf(newTransaction.getInputs().stream().mapToLong(input -> input.getValue() != null ? input.getValue().value : 0).sum());
                newTransaction.addOutput(amount, toAddress);
                try {
                    Coin fee;
                    int counter = 0;
                    int txSize = 0;
                    Transaction tx;
                    SendRequest sendRequest;
                    Coin txFeeForWithdrawalPerByte = getTxFeeForWithdrawalPerByte();
                    do {
                        counter++;
                        fee = txFeeForWithdrawalPerByte.multiply(txSize);
                        newTransaction.clearOutputs();
                        newTransaction.addOutput(amount.subtract(fee), toAddress);
                        sendRequest = SendRequest.forTx(newTransaction);
                        sendRequest.fee = fee;
                        sendRequest.feePerKb = Coin.ZERO;
                        sendRequest.ensureMinRequiredFee = false;
                        sendRequest.aesKey = aesKey;
                        sendRequest.coinSelector = new BtcCoinSelector(toAddress);
                        sendRequest.changeAddress = toAddress;
                        wallet.completeTx(sendRequest);
                        tx = sendRequest.tx;
                        txSize = tx.bitcoinSerialize().length;
                        printTx("FeeEstimationTransaction", tx);
                        sendRequest.tx.getOutputs().forEach(o -> log.debug("Output value " + o.getValue().toFriendlyString()));
                    } while (feeEstimationNotSatisfied(counter, tx));
                    if (counter == 10)
                        log.error("Could not calculate the fee. Tx=" + tx);
                    Wallet.SendResult sendResult = null;
                    try {
                        sendRequest = SendRequest.forTx(newTransaction);
                        sendRequest.fee = fee;
                        sendRequest.feePerKb = Coin.ZERO;
                        sendRequest.ensureMinRequiredFee = false;
                        sendRequest.aesKey = aesKey;
                        sendRequest.coinSelector = new BtcCoinSelector(toAddress);
                        sendRequest.changeAddress = toAddress;
                        sendResult = wallet.sendCoins(sendRequest);
                    } catch (InsufficientMoneyException e) {
                        // in some cases getFee did not calculate correctly and we still get an InsufficientMoneyException
                        log.warn("We still have a missing fee " + (e.missing != null ? e.missing.toFriendlyString() : ""));
                        amount = amount.subtract(e.missing);
                        newTransaction.clearOutputs();
                        newTransaction.addOutput(amount, toAddress);
                        sendRequest = SendRequest.forTx(newTransaction);
                        sendRequest.fee = fee;
                        sendRequest.feePerKb = Coin.ZERO;
                        sendRequest.ensureMinRequiredFee = false;
                        sendRequest.aesKey = aesKey;
                        sendRequest.coinSelector = new BtcCoinSelector(toAddress, false);
                        sendRequest.changeAddress = toAddress;
                        try {
                            sendResult = wallet.sendCoins(sendRequest);
                            printTx("FeeEstimationTransaction", newTransaction);
                        } catch (InsufficientMoneyException e2) {
                            errorMessageHandler.handleErrorMessage("We did not get the correct fee calculated. " + (e2.missing != null ? e2.missing.toFriendlyString() : ""));
                        }
                    }
                    if (sendResult != null) {
                        log.info("Broadcasting double spending transaction. " + sendResult.tx);
                        Futures.addCallback(sendResult.broadcastComplete, new FutureCallback<Transaction>() {

                            @Override
                            public void onSuccess(Transaction result) {
                                log.info("Double spending transaction published. " + result);
                                resultHandler.run();
                            }

                            @Override
                            public void onFailure(@NotNull Throwable t) {
                                log.error("Broadcasting double spending transaction failed. " + t.getMessage());
                                errorMessageHandler.handleErrorMessage(t.getMessage());
                            }
                        });
                    }
                } catch (InsufficientMoneyException e) {
                    throw new InsufficientFundsException("The fees for that transaction exceed the available funds " + "or the resulting output value is below the min. dust value:\n" + "Missing " + (e.missing != null ? e.missing.toFriendlyString() : "null"));
                }
            } else {
                String errorMessage = "We could not find inputs we control in the transaction we want to double spend.";
                log.warn(errorMessage);
                errorMessageHandler.handleErrorMessage(errorMessage);
            }
        } else if (confidenceType == TransactionConfidence.ConfidenceType.BUILDING) {
            errorMessageHandler.handleErrorMessage("That transaction is already in the blockchain so we cannot double spend it.");
        } else if (confidenceType == TransactionConfidence.ConfidenceType.DEAD) {
            errorMessageHandler.handleErrorMessage("One of the inputs of that transaction has been already double spent.");
        }
    }
}
Also used : Arrays(java.util.Arrays) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Coin(org.bitcoinj.core.Coin) Wallet(org.bitcoinj.wallet.Wallet) LoggerFactory(org.slf4j.LoggerFactory) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) ImmutableList(com.google.common.collect.ImmutableList) AddressEntryList(bisq.core.btc.AddressEntryList) SendRequest(org.bitcoinj.wallet.SendRequest) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt) KeyParameter(org.spongycastle.crypto.params.KeyParameter) DeterministicKey(org.bitcoinj.crypto.DeterministicKey) Nullable(javax.annotation.Nullable) ScriptBuilder(org.bitcoinj.script.ScriptBuilder) AddressFormatException(org.bitcoinj.core.AddressFormatException) AddressEntryException(bisq.core.btc.AddressEntryException) WalletException(bisq.core.btc.exceptions.WalletException) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) Logger(org.slf4j.Logger) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) AddressEntry(bisq.core.btc.AddressEntry) TransactionInput(org.bitcoinj.core.TransactionInput) Preferences(bisq.core.user.Preferences) TransactionOutput(org.bitcoinj.core.TransactionOutput) Optional(java.util.Optional) FeeService(bisq.core.provider.fee.FeeService) Address(org.bitcoinj.core.Address) Preconditions(com.google.common.base.Preconditions) NotNull(org.jetbrains.annotations.NotNull) Restrictions(bisq.core.btc.Restrictions) TransactionOutput(org.bitcoinj.core.TransactionOutput) SendRequest(org.bitcoinj.wallet.SendRequest) Address(org.bitcoinj.core.Address) AddressEntry(bisq.core.btc.AddressEntry) Wallet(org.bitcoinj.wallet.Wallet) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) TransactionInput(org.bitcoinj.core.TransactionInput) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Example 82 with FutureCallback

use of com.google.common.util.concurrent.FutureCallback in project bisq-core by bisq-network.

the class JsonBlockChainExporter method maybeExport.

public void maybeExport() {
    if (dumpBlockchainData) {
        ListenableFuture<Void> future = executor.submit(() -> {
            final BsqState bsqStateClone = bsqStateService.getClone();
            Map<String, Tx> txMap = bsqStateService.getBlocksFromState(bsqStateClone).stream().filter(Objects::nonNull).flatMap(block -> block.getTxs().stream()).collect(Collectors.toMap(Tx::getId, tx -> tx));
            for (Tx tx : txMap.values()) {
                String txId = tx.getId();
                final Optional<TxType> optionalTxType = bsqStateService.getOptionalTxType(txId);
                optionalTxType.ifPresent(txType1 -> {
                    JsonTxType txType = txType1 != TxType.UNDEFINED_TX_TYPE ? JsonTxType.valueOf(txType1.name()) : null;
                    List<JsonTxOutput> outputs = new ArrayList<>();
                    tx.getTxOutputs().forEach(txOutput -> {
                        final Optional<SpentInfo> optionalSpentInfo = bsqStateService.getSpentInfo(txOutput);
                        final boolean isBsqOutput = bsqStateService.isBsqTxOutputType(txOutput);
                        final PubKeyScript pubKeyScript = txOutput.getPubKeyScript();
                        final JsonTxOutput outputForJson = new JsonTxOutput(txId, txOutput.getIndex(), isBsqOutput ? txOutput.getValue() : 0, !isBsqOutput ? txOutput.getValue() : 0, txOutput.getBlockHeight(), isBsqOutput, bsqStateService.getBurntFee(tx.getId()), txOutput.getAddress(), pubKeyScript != null ? new JsonScriptPubKey(pubKeyScript) : null, optionalSpentInfo.map(JsonSpentInfo::new).orElse(null), tx.getTime(), txType, txType != null ? txType.getDisplayString() : "", txOutput.getOpReturnData() != null ? Utils.HEX.encode(txOutput.getOpReturnData()) : null);
                        outputs.add(outputForJson);
                        txOutputFileManager.writeToDisc(Utilities.objectToJson(outputForJson), outputForJson.getId());
                    });
                    List<JsonTxInput> inputs = tx.getTxInputs().stream().map(txInput -> {
                        Optional<TxOutput> optionalTxOutput = bsqStateService.getConnectedTxOutput(txInput);
                        if (optionalTxOutput.isPresent()) {
                            final TxOutput connectedTxOutput = optionalTxOutput.get();
                            final boolean isBsqOutput = bsqStateService.isBsqTxOutputType(connectedTxOutput);
                            return new JsonTxInput(txInput.getConnectedTxOutputIndex(), txInput.getConnectedTxOutputTxId(), connectedTxOutput.getValue(), isBsqOutput, connectedTxOutput.getAddress(), tx.getTime());
                        } else {
                            return null;
                        }
                    }).filter(Objects::nonNull).collect(Collectors.toList());
                    final JsonTx jsonTx = new JsonTx(txId, tx.getBlockHeight(), tx.getBlockHash(), tx.getTime(), inputs, outputs, txType, txType != null ? txType.getDisplayString() : "", bsqStateService.getBurntFee(tx.getId()));
                    txFileManager.writeToDisc(Utilities.objectToJson(jsonTx), txId);
                });
            }
            jsonFileManager.writeToDisc(Utilities.objectToJson(bsqStateClone), "BsqStateService");
            return null;
        });
        Futures.addCallback(future, new FutureCallback<Void>() {

            public void onSuccess(Void ignore) {
                log.trace("onSuccess");
            }

            public void onFailure(@NotNull Throwable throwable) {
                log.error(throwable.toString());
                throwable.printStackTrace();
            }
        });
    }
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Utilities(bisq.common.util.Utilities) TxOutput(bisq.core.dao.state.blockchain.TxOutput) Inject(com.google.inject.Inject) DaoOptionKeys(bisq.core.dao.DaoOptionKeys) TxType(bisq.core.dao.state.blockchain.TxType) ArrayList(java.util.ArrayList) JsonFileManager(bisq.common.storage.JsonFileManager) Map(java.util.Map) Named(javax.inject.Named) SpentInfo(bisq.core.dao.state.blockchain.SpentInfo) BsqState(bisq.core.dao.state.BsqState) Utils(org.bitcoinj.core.Utils) Tx(bisq.core.dao.state.blockchain.Tx) BsqStateService(bisq.core.dao.state.BsqStateService) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) PubKeyScript(bisq.core.dao.state.blockchain.PubKeyScript) Objects(java.util.Objects) FileUtil(bisq.common.storage.FileUtil) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Paths(java.nio.file.Paths) Storage(bisq.common.storage.Storage) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TxOutput(bisq.core.dao.state.blockchain.TxOutput) BsqState(bisq.core.dao.state.BsqState) ArrayList(java.util.ArrayList) PubKeyScript(bisq.core.dao.state.blockchain.PubKeyScript) SpentInfo(bisq.core.dao.state.blockchain.SpentInfo) Tx(bisq.core.dao.state.blockchain.Tx) TxType(bisq.core.dao.state.blockchain.TxType) Objects(java.util.Objects)

Example 83 with FutureCallback

use of com.google.common.util.concurrent.FutureCallback in project bisq-core by bisq-network.

the class WalletConfig method startUp.

@Override
protected void startUp() throws Exception {
    // Runs in a separate thread.
    Context.propagate(context);
    if (!directory.exists()) {
        if (!directory.mkdirs()) {
            throw new IOException("Could not create directory " + directory.getAbsolutePath());
        }
    }
    log.info("Wallet directory: {}", directory);
    try {
        File chainFile = new File(directory, spvChainFileName);
        boolean chainFileExists = chainFile.exists();
        // BTC wallet
        vBtcWalletFile = new File(directory, btcWalletFileName);
        boolean shouldReplayWallet = (vBtcWalletFile.exists() && !chainFileExists) || seed != null;
        BisqKeyChainGroup keyChainGroup;
        if (seed != null)
            keyChainGroup = new BisqKeyChainGroup(params, new BtcDeterministicKeyChain(seed), true);
        else
            keyChainGroup = new BisqKeyChainGroup(params, true);
        vBtcWallet = createOrLoadWallet(vBtcWalletFile, shouldReplayWallet, keyChainGroup, false, seed);
        vBtcWallet.allowSpendingUnconfirmedTransactions();
        vBtcWallet.setRiskAnalyzer(new BisqRiskAnalysis.Analyzer());
        if (seed != null)
            keyChainGroup = new BisqKeyChainGroup(params, new BisqDeterministicKeyChain(seed), false);
        else
            keyChainGroup = new BisqKeyChainGroup(params, new BisqDeterministicKeyChain(vBtcWallet.getKeyChainSeed()), false);
        // BSQ wallet
        if (BisqEnvironment.isBaseCurrencySupportingBsq()) {
            vBsqWalletFile = new File(directory, bsqWalletFileName);
            vBsqWallet = createOrLoadWallet(vBsqWalletFile, shouldReplayWallet, keyChainGroup, true, seed);
            vBsqWallet.setRiskAnalyzer(new BisqRiskAnalysis.Analyzer());
        }
        // Initiate Bitcoin network objects (block store, blockchain and peer group)
        vStore = provideBlockStore(chainFile);
        if (!chainFileExists || seed != null) {
            if (checkpoints != null) {
                // Initialize the chain file with a checkpoint to speed up first-run sync.
                long time;
                if (seed != null) {
                    // we created both wallets at the same time
                    time = seed.getCreationTimeSeconds();
                    if (chainFileExists) {
                        log.info("Deleting the chain file in preparation from restore.");
                        vStore.close();
                        if (!chainFile.delete())
                            throw new IOException("Failed to delete chain file in preparation for restore.");
                        vStore = new SPVBlockStore(params, chainFile);
                    }
                } else {
                    time = vBtcWallet.getEarliestKeyCreationTime();
                }
                if (time > 0)
                    CheckpointManager.checkpoint(params, checkpoints, vStore, time);
                else
                    log.warn("Creating a new uncheckpointed block store due to a wallet with a creation time of zero: this will result in a very slow chain sync");
            } else if (chainFileExists) {
                log.info("Deleting the chain file in preparation from restore.");
                vStore.close();
                if (!chainFile.delete())
                    throw new IOException("Failed to delete chain file in preparation for restore.");
                vStore = new SPVBlockStore(params, chainFile);
            }
        }
        vChain = new BlockChain(params, vStore);
        vPeerGroup = createPeerGroup();
        if (minBroadcastConnections > 0)
            vPeerGroup.setMinBroadcastConnections(minBroadcastConnections);
        vPeerGroup.setUserAgent(userAgent, Version.VERSION);
        // before we're actually connected the broadcast waits for an appropriate number of connections.
        if (peerAddresses != null) {
            for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr);
            log.info("We try to connect to {} btc nodes", numConnectionForBtc);
            vPeerGroup.setMaxConnections(Math.min(numConnectionForBtc, peerAddresses.length));
            peerAddresses = null;
        } else if (!params.equals(RegTestParams.get())) {
            vPeerGroup.addPeerDiscovery(discovery != null ? discovery : new DnsDiscovery(params));
        }
        vChain.addWallet(vBtcWallet);
        vPeerGroup.addWallet(vBtcWallet);
        if (vBsqWallet != null) {
            // noinspection ConstantConditions
            vChain.addWallet(vBsqWallet);
            // noinspection ConstantConditions
            vPeerGroup.addWallet(vBsqWallet);
        }
        onSetupCompleted();
        if (blockingStartup) {
            vPeerGroup.start();
            // Make sure we shut down cleanly.
            installShutdownHook();
            final DownloadProgressTracker listener = new DownloadProgressTracker();
            vPeerGroup.startBlockChainDownload(listener);
            listener.await();
        } else {
            Futures.addCallback(vPeerGroup.startAsync(), new FutureCallback() {

                @Override
                public void onSuccess(@Nullable Object result) {
                    final PeerDataEventListener listener = downloadListener == null ? new DownloadProgressTracker() : downloadListener;
                    vPeerGroup.startBlockChainDownload(listener);
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    throw new RuntimeException(t);
                }
            });
        }
    } catch (BlockStoreException e) {
        throw new IOException(e);
    }
}
Also used : BlockChain(org.bitcoinj.core.BlockChain) BlockStoreException(org.bitcoinj.store.BlockStoreException) PeerDataEventListener(org.bitcoinj.core.listeners.PeerDataEventListener) SPVBlockStore(org.bitcoinj.store.SPVBlockStore) IOException(java.io.IOException) DnsDiscovery(org.bitcoinj.net.discovery.DnsDiscovery) PeerAddress(org.bitcoinj.core.PeerAddress) DownloadProgressTracker(org.bitcoinj.core.listeners.DownloadProgressTracker) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 84 with FutureCallback

use of com.google.common.util.concurrent.FutureCallback in project android_packages_apps_Settings by omnirom.

the class SmartForwardingActivity method disableSmartForwarding.

public void disableSmartForwarding() {
    TelephonyManager tm = getSystemService(TelephonyManager.class);
    SubscriptionManager sm = getSystemService(SubscriptionManager.class);
    boolean[] callWaitingStatus = getAllSlotCallWaitingStatus(this, sm, tm);
    CallForwardingInfo[] callForwardingInfo = getAllSlotCallForwardingStatus(this, sm, tm);
    // Disable feature
    ListenableFuture disableTask = service.submit(new DisableSmartForwardingTask(tm, callWaitingStatus, callForwardingInfo));
    Futures.addCallback(disableTask, new FutureCallback() {

        @Override
        public void onSuccess(Object result) {
            clearAllBackupData(SmartForwardingActivity.this, sm, tm);
        }

        @Override
        public void onFailure(Throwable t) {
            Log.e(TAG, "Disable Feature exception" + t);
        }
    }, ContextCompat.getMainExecutor(this));
}
Also used : CallForwardingInfo(android.telephony.CallForwardingInfo) TelephonyManager(android.telephony.TelephonyManager) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SubscriptionManager(android.telephony.SubscriptionManager) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 85 with FutureCallback

use of com.google.common.util.concurrent.FutureCallback in project thingsboard by thingsboard.

the class EntityViewController method copyLatestFromEntityToEntityView.

private ListenableFuture<List<Void>> copyLatestFromEntityToEntityView(EntityView entityView, SecurityUser user) {
    EntityViewId entityId = entityView.getId();
    List<String> keys = entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null ? entityView.getKeys().getTimeseries() : Collections.emptyList();
    long startTs = entityView.getStartTimeMs();
    long endTs = entityView.getEndTimeMs() == 0 ? Long.MAX_VALUE : entityView.getEndTimeMs();
    ListenableFuture<List<String>> keysFuture;
    if (keys.isEmpty()) {
        keysFuture = Futures.transform(tsService.findAllLatest(user.getTenantId(), entityView.getEntityId()), latest -> latest.stream().map(TsKvEntry::getKey).collect(Collectors.toList()), MoreExecutors.directExecutor());
    } else {
        keysFuture = Futures.immediateFuture(keys);
    }
    ListenableFuture<List<TsKvEntry>> latestFuture = Futures.transformAsync(keysFuture, fetchKeys -> {
        List<ReadTsKvQuery> queries = fetchKeys.stream().filter(key -> !isBlank(key)).map(key -> new BaseReadTsKvQuery(key, startTs, endTs, 1, "DESC")).collect(Collectors.toList());
        if (!queries.isEmpty()) {
            return tsService.findAll(user.getTenantId(), entityView.getEntityId(), queries);
        } else {
            return Futures.immediateFuture(null);
        }
    }, MoreExecutors.directExecutor());
    return Futures.transform(latestFuture, latestValues -> {
        if (latestValues != null && !latestValues.isEmpty()) {
            tsSubService.saveLatestAndNotify(entityView.getTenantId(), entityId, latestValues, new FutureCallback<Void>() {

                @Override
                public void onSuccess(@Nullable Void tmp) {
                }

                @Override
                public void onFailure(Throwable t) {
                }
            });
        }
        return null;
    }, MoreExecutors.directExecutor());
}
Also used : TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH(org.thingsboard.server.controller.ControllerConstants.TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Edge(org.thingsboard.server.common.data.edge.Edge) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) Customer(org.thingsboard.server.common.data.Customer) SORT_ORDER_ALLOWABLE_VALUES(org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_ALLOWABLE_VALUES) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) ENTITY_VIEW_TYPE(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_TYPE) SettableFuture(com.google.common.util.concurrent.SettableFuture) CUSTOMER_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.CUSTOMER_ID_PARAM_DESCRIPTION) TenantId(org.thingsboard.server.common.data.id.TenantId) ApiOperation(io.swagger.annotations.ApiOperation) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) EntityViewInfo(org.thingsboard.server.common.data.EntityViewInfo) EDGE_UNASSIGN_RECEIVE_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_UNASSIGN_RECEIVE_STEP_DESCRIPTION) EntityType(org.thingsboard.server.common.data.EntityType) CUSTOMER_ID(org.thingsboard.server.controller.ControllerConstants.CUSTOMER_ID) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) EdgeId(org.thingsboard.server.common.data.id.EdgeId) PageLink(org.thingsboard.server.common.data.page.PageLink) TENANT_AUTHORITY_PARAGRAPH(org.thingsboard.server.controller.ControllerConstants.TENANT_AUTHORITY_PARAGRAPH) MediaType(org.springframework.http.MediaType) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) Collection(java.util.Collection) PAGE_DATA_PARAMETERS(org.thingsboard.server.controller.ControllerConstants.PAGE_DATA_PARAMETERS) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TimeseriesService(org.thingsboard.server.dao.timeseries.TimeseriesService) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) EdgeEventActionType(org.thingsboard.server.common.data.edge.EdgeEventActionType) EntityView(org.thingsboard.server.common.data.EntityView) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) EntityViewSearchQuery(org.thingsboard.server.common.data.entityview.EntityViewSearchQuery) Operation(org.thingsboard.server.service.security.permission.Operation) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) SORT_ORDER_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.SORT_ORDER_DESCRIPTION) ENTITY_VIEW_TEXT_SEARCH_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_TEXT_SEARCH_DESCRIPTION) PAGE_NUMBER_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.PAGE_NUMBER_DESCRIPTION) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) SORT_PROPERTY_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.SORT_PROPERTY_DESCRIPTION) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ENTITY_VIEW_INFO_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_INFO_DESCRIPTION) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ENTITY_VIEW_INFO_SORT_PROPERTY_ALLOWABLE_VALUES(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_INFO_SORT_PROPERTY_ALLOWABLE_VALUES) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) ENTITY_VIEW_ID_PARAM_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_ID_PARAM_DESCRIPTION) ActionType(org.thingsboard.server.common.data.audit.ActionType) TbCoreComponent(org.thingsboard.server.queue.util.TbCoreComponent) PAGE_SIZE_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.PAGE_SIZE_DESCRIPTION) EntityId(org.thingsboard.server.common.data.id.EntityId) MODEL_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.MODEL_DESCRIPTION) EDGE_ID(org.thingsboard.server.controller.EdgeController.EDGE_ID) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Nullable(javax.annotation.Nullable) DataConstants(org.thingsboard.server.common.data.DataConstants) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) EDGE_ASSIGN_ASYNC_FIRST_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_ASSIGN_ASYNC_FIRST_STEP_DESCRIPTION) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) HttpStatus(org.springframework.http.HttpStatus) Futures(com.google.common.util.concurrent.Futures) EDGE_ASSIGN_RECEIVE_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_ASSIGN_RECEIVE_STEP_DESCRIPTION) EDGE_UNASSIGN_ASYNC_FIRST_STEP_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.EDGE_UNASSIGN_ASYNC_FIRST_STEP_DESCRIPTION) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) PageData(org.thingsboard.server.common.data.page.PageData) Resource(org.thingsboard.server.service.security.permission.Resource) ENTITY_VIEW_DESCRIPTION(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_DESCRIPTION) ENTITY_VIEW_SORT_PROPERTY_ALLOWABLE_VALUES(org.thingsboard.server.controller.ControllerConstants.ENTITY_VIEW_SORT_PROPERTY_ALLOWABLE_VALUES) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) Collections(java.util.Collections) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) EntityViewId(org.thingsboard.server.common.data.id.EntityViewId) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

FutureCallback (com.google.common.util.concurrent.FutureCallback)98 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)56 List (java.util.List)48 Futures (com.google.common.util.concurrent.Futures)43 ArrayList (java.util.ArrayList)41 Nullable (javax.annotation.Nullable)38 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)26 Map (java.util.Map)25 Set (java.util.Set)25 TimeUnit (java.util.concurrent.TimeUnit)24 IOException (java.io.IOException)23 Collectors (java.util.stream.Collectors)23 PostConstruct (javax.annotation.PostConstruct)23 ExecutorService (java.util.concurrent.ExecutorService)22 Function (com.google.common.base.Function)21 Collections (java.util.Collections)21 TenantId (org.thingsboard.server.common.data.id.TenantId)21 PreDestroy (javax.annotation.PreDestroy)20 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19