static public void init() { registerClass(CODE_CALLBACK_NOTIFICATION, CallbackNotification.class); } }
notification.getId().toBase64String(), " type ", notification.getType().name()); if (notification.getType() == CallbackNotification.CallbackNotificationType.GET_STATE) { network.deliver(notification.getFrom(), new CallbackNotification(myInfo, notification.getId(), CallbackNotification.CallbackNotificationType.RETURN_STATE, null, ledger.getFollowerCallbackStateById(notification.getId()))); } else if (notification.getType() == CallbackNotification.CallbackNotificationType.RETURN_STATE) { synchronized (callbackProcessors) { CallbackRecord record = callbacksToSynchronize.get(notification.getId()); if ((record != null) && record.synchronizeState(notification.getState(), ledger, node)) { callbacksToSynchronize.remove(notification.getId()); notification.getId().toBase64String(), " synchronized with state ", notification.getState().name()); callback = callbackProcessors.get(notification.getId()); if (callback == null) { node.report(DatagramAdapter.VerboseLevel.BASE, "obtainCallbackNotification not found callback ", notification.getId().toBase64String()); deferredCallbackNotifications.put(notification.getId(), notification); return;
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(); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CallbackNotification that = (CallbackNotification) o; NodeInfo from = getFrom(); if (!from.equals(that.getFrom())) return false; if (!id.equals(that.id)) return false; if (!type.equals(that.type)) return false; if (!state.equals(that.state)) return false; return Arrays.equals(signature, that.signature); }
private synchronized void startSynchronizeFollowerCallbacks(Collection<CallbackRecord> callbackRecords, int nodesCount) { ZonedDateTime expiresAt = ZonedDateTime.now().plusSeconds(20); callbackRecords.forEach(r -> { if (!callbacksToSynchronize.containsKey(r.getId())) { // init record to synchronization r.setExpiresAt(expiresAt); r.setConsensusAndLimit(nodesCount); callbacksToSynchronize.put(r.getId(), r); // request callback state from all nodes network.broadcast(myInfo, new CallbackNotification(myInfo, r.getId(), CallbackNotification.CallbackNotificationType.GET_STATE, null)); } }); executorService.schedule(() -> endSynchronizeFollowerCallbacks(), 20, TimeUnit.SECONDS); }
@Override public int hashCode() { NodeInfo from = getFrom(); int result = from.hashCode(); result = 31 * result + id.hashCode(); result = 31 * result + Arrays.hashCode(signature); result = 31 * result + type.hashCode(); result = 31 * result + state.hashCode(); return result; }
if (isItemSended) { // callback has already been called and received packed item network.broadcast(myInfo, new CallbackNotification(myInfo, id, CallbackNotification.CallbackNotificationType.NOT_RESPONDING, null)); network.broadcast(myInfo, new CallbackNotification(myInfo, id, CallbackNotification.CallbackNotificationType.COMPLETED, signature)); complete();