/** * Runs callback processor for one callback. Adds callback record to ledger, runs callback processing thread and * checks and obtains deferred callback notifications. * * @param updatingItem is new revision of following contract * @param contract is follower contract * @param me is environment */ public void startCallbackProcessor(Contract updatingItem, ItemState state, NSmartContract contract, NMutableEnvironment me) { // initialize callback processor CallbackProcessor callback = new CallbackProcessor(updatingItem, state, contract, me.getId(), this); // add callback record to DB CallbackRecord.addCallbackRecordToLedger(callback.getId(), me.getId(), config, network.getNodesCount(), ledger); // run callback processor int startDelay = callback.getDelay(); int repeatDelay = (int) config.getFollowerCallbackDelay().toMillis() * (network.getNodesCount() + 2); callback.setExecutor(executorService.scheduleWithFixedDelay(() -> callback.call(), startDelay, repeatDelay, TimeUnit.MILLISECONDS)); synchronized (callbackProcessors) { callbackProcessors.put(callback.getId(), callback); node.report(DatagramAdapter.VerboseLevel.DETAILED, "notifyFollowerSubscribers: put callback ", callback.getId().toBase64String()); CallbackNotification deferredNotification = deferredCallbackNotifications.get(callback.getId()); if (deferredNotification != null) { // do deferred notification callback.obtainNotification(deferredNotification); deferredCallbackNotifications.remove(callback.getId()); node.report(DatagramAdapter.VerboseLevel.DETAILED, "notifyFollowerSubscribers: remove deferred notification for callback ", callback.getId().toBase64String()); } } }