itemId, " from parcel: ", parcelId, " :: vote " + state + " from " + node + ", state ", processingState, " :: itemState ", getState()), DatagramAdapter.VerboseLevel.BASE); boolean positiveConsensus = false;
" :: created, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE);
private final synchronized void checkItem() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: checkItem, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) {
private void rollbackChanges(ItemState newState) { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: rollbackChanges, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE);
private final void commitCheckedAndStartPolling() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: commitCheckedAndStartPolling, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) {
" :: sendNewConsensusNotification isConsensusReceivedExpired, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.NOTHING);
private final void itemDownloaded() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: itemDownloaded, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) { synchronized (cache) { cache.put(item, getResult()); } synchronized (mutex) { //save item in disk cache ledger.putItem(record, item, Instant.now().plus(config.getMaxDiskCacheAge())); } if(item instanceof Contract) { if(((Contract)item).isLimitedForTestnet()) { markContractTest((Contract) item); } } if(!processingState.isProcessedToConsensus()) { processingState = ItemProcessingState.DOWNLOADED; } if(isCheckingForce) { checkItem(); } downloadedEvent.fire(); } }
private void close() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: close, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) processingState = ItemProcessingState.DONE; stopPoller(); // fire all event to release possible listeners downloadedEvent.fire(); pollingReadyEvent.fire(); doneEvent.fire(); if(processingState.canContinue()) { checkIfAllReceivedConsensus(); if (processingState == ItemProcessingState.DONE) { pulseSendNewConsensus(); } else { removeSelf(); } } else { removeSelf(); } }
/** * Emergency break all processes and remove self. */ private void emergencyBreak() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: emergencyBreak, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); boolean doRollback = !processingState.isDone(); processingState = ItemProcessingState.EMERGENCY_BREAK; stopDownloader(); stopPoller(); stopConsensusReceivedChecker(); for(ResyncingItem ri : resyncingItems.values()) { if(!ri.isCommitFinished()) { ri.closeByTimeout(); } } if(doRollback) rollbackChanges(stateWas); else close(); processingState = ItemProcessingState.FINISHED; }
private final void pulseStartPolling() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: pulseStartPolling, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) { if (!processingState.isProcessedToConsensus()) { // at this point the item is with us, so we can start synchronized (mutex) { if (!processingState.isProcessedToConsensus()) { if (poller == null) { List<Integer> pollTimes = config.getPollTime(); poller = new RunnableWithDynamicPeriod(() -> sendStartPollingNotification(), pollTimes, executorService ); poller.run(); } } } } } }
/** * Start checking if item was downloaded and wait for isCheckingForce flag. * If item hasn't downloaded just set isCheckingForce for true. * @param isCheckingForce */ private void forceChecking(boolean isCheckingForce) { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: forceChecking, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); this.isCheckingForce = isCheckingForce; if(processingState.canContinue()) { if (processingState == ItemProcessingState.DOWNLOADED) { executorService.submit(() -> { checkItem(); }, Node.this.toString() + toString() + " :: forceChecking -> checkItem"); } } }
private final void pulseSendNewConsensus() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: pulseSendNewConsensus, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) { processingState = ItemProcessingState.SENDING_CONSENSUS; synchronized (mutex) { if(consensusReceivedChecker == null) { List<Integer> periodsMillis = config.getConsensusReceivedCheckTime(); consensusReceivedChecker = new RunnableWithDynamicPeriod(() -> sendNewConsensusNotification(), periodsMillis, executorService ); consensusReceivedChecker.run(); } } } }
private final void broadcastMyState() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: broadcastMyState, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) { Notification notification; ParcelNotification.ParcelNotificationType notificationType; if(item.shouldBeU()) { notificationType = ParcelNotification.ParcelNotificationType.PAYMENT; } else { notificationType = ParcelNotification.ParcelNotificationType.PAYLOAD; } notification = new ParcelNotification(myInfo, itemId, parcelId, getResult(), true, notificationType); network.broadcast(myInfo, notification); } }
private final void approveAndCommit() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: approveAndCommit, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canContinue()) { // todo: fix logic to surely copy approving item dependency. e.g. download original or at least dependencies // first we need to flag our state as approved setState(ItemState.APPROVED); executorService.submit(() -> downloadAndCommit(), Node.this.toString() + toString() + " :: approveAndCommit -> downloadAndCommit"); } }
private final void removeSelf() { report(getLabel(), () -> concatReportMessage("item processor for item: ", itemId, " from parcel: ", parcelId, " :: removeSelf, state ", processingState, " itemState: ", getState()), DatagramAdapter.VerboseLevel.BASE); if(processingState.canRemoveSelf()) { forceRemoveSelf(); } }