private void checkForComplete() { // if some nodes (rate defined in config) also sended callback and received packed item (without answer) // callback is deemed complete if (nodesSendCallback.size() >= (int) Math.floor(network.allNodes().size() * config.getRateNodesSendFollowerCallbackToComplete())) complete(); }
if (callback.getState() == ItemState.APPROVED) call = Binder.fromKeysValues( "event", "new", "key", nodeKey.getPublicKey().pack() ); else if (callback.getState() == ItemState.REVOKED) call = Binder.fromKeysValues( "event", "revoke", callback.setItemSended();
/** * 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()); } } }
public void call() { if (ZonedDateTime.now().isAfter(expiresAt)) fail(); // callback failed (expired) else { if (isItemSended) { // callback has already been called and received packed item CallbackNotification.CallbackNotificationType.NOT_RESPONDING, null)); addNodeToSended(myInfo.getNumber()); checkForComplete(); } else { // callback not previously called if ((signature != null) && checkCallbackSignature(signature)) { network.broadcast(myInfo, new CallbackNotification(myInfo, id, CallbackNotification.CallbackNotificationType.COMPLETED, signature)); complete();
public void obtainNotification(CallbackNotification notification) { node.report(DatagramAdapter.VerboseLevel.DETAILED, "Notify callback ", notification.getId().toBase64String(), " type ", notification.getType().name(), " from node ", notification.getFrom().getName()); if (notification.getType() == CallbackNotification.CallbackNotificationType.COMPLETED) { if (checkCallbackSignature(notification.getSignature())) complete(); } else if (notification.getType() == CallbackNotification.CallbackNotificationType.NOT_RESPONDING) { addNodeToSended(notification.getFrom().getNumber()); checkForComplete(); } }