/** * Shortcut method: check that record exists and its state returns {@link ItemState#isApproved()}}. Check it to * ensure its meaning. * * @param id is {@link HashId} for checking item * @return true if it is. */ default boolean isApproved(HashId id) { StateRecord r = getRecord(id); return r != null && r.getState().isApproved(); }
/** * Shortcut method: check that record exists and its state returns {@link ItemState#isConsensusFound()}}. Check it to * ensure its meaning. * * @param id is {@link HashId} for checking item * @return true if it is. */ default boolean isConsensusFound(HashId id) { StateRecord r = getRecord(id); return r != null && r.getState().isConsensusFound(); }
public ResyncNotification(NodeInfo from, HashId itemId, ItemState itemState, Boolean hasEnvironment, boolean answerIsRequested) throws IOException { super(from, itemId, new ItemResult(new StateRecord(itemId)), answerIsRequested); this.itemState = itemState; this.hasEnvironment = hasEnvironment ? 1 : 0; }
@Override public String toString() { return "State<"+getId()+"/"+getRecordId()+":"+getState()+":"+getCreatedAt()+"/"+getExpiresAt()+">"; } }
@Override public long removeEnvironment(HashId ncontractHashId) { long envId = getEnvironmentId(ncontractHashId); removeSubscriptionsByEnvId(envId); removeStorageContractsByEnvId(envId); clearExpiredStorageContractBinaries(); return removeEnvironmentEx(ncontractHashId); }
public void markTestRecord() { if(ledger != null) { ledger.markTestRecord(this.getId()); } }
@Override public void removeExpiredStoragesAndSubscriptionsCascade() { clearExpiredSubscriptions(); clearExpiredStorages(); clearExpiredStorageContractBinaries(); }
@Override public boolean countPulse() { if(currentTimeSlot != null && currentTimeSlot.isActive()) { } else { currentTimeSlot = new TimeSlot(limit, period); } return currentTimeSlot.countPulse(); }
@Override public NNameRecord getNameByOrigin (byte[] origin) { return getNameBy("WHERE name_storage.id=(SELECT name_storage_id FROM name_entry WHERE origin=?) ", (statement)-> { try { statement.setBytes(1, origin); } catch (SQLException e) { throw new Failure("getNameByOrigin failed: " + e); } }); }
public void destroy() { checkLedgerExists(); ledger.destroy(this); }
public long millisecondsLeft() { if(currentTimeSlot != null && currentTimeSlot.isActive()) return currentTimeSlot.millisecondsLeft(); return 0; }
private final void setState(ItemState newState) { synchronized (mutex) { record.setState(newState); } }
public ItemState getItemState() { if(record != null) return record.getState(); return ItemState.UNDEFINED; } }
@Override public NImmutableEnvironment getEnvironment(HashId contractId) { Long envId = getEnvironmentIdForSmartContractHashId(contractId); if (envId != null) return getEnvironment(envId); return null; }
public final StateRecord setState(ItemState newState) { if (state != newState) { state = newState; setDirty(); } return this; }
public void save() { if (dirty && ledger != null) { dirty = false; ledger.save(this); } }
@Override public int pulsesLeft() { if(currentTimeSlot != null && currentTimeSlot.isActive()) return currentTimeSlot.limit - currentTimeSlot.currentCount; return limit; }
@Override public void save() { ledger.saveFollowerEnvironment(environmentId, expiresAt, mutedAt, spent, startedCallbacks); } }
public ResyncNotification(NodeInfo from, HashId itemId, boolean answerIsRequested) throws IOException { super(from, itemId, new ItemResult(new StateRecord(itemId)), answerIsRequested); }
@Override public NNameRecord getNameByAddress (String address) { return getNameBy("WHERE name_storage.id=(SELECT name_storage_id FROM name_entry WHERE short_addr=? OR long_addr=? LIMIT 1) ", (statement)-> { try { statement.setString(1, address); statement.setString(2, address); } catch (SQLException e) { throw new Failure("getNameByAddress failed: " + e); } }); }