@Override public ItemResult deserialize(Binder binder, BiDeserializer deserializer) { return new ItemResult(binder); }
@Override public Binder serialize(Object object, BiSerializer serializer) { return ((ItemResult) object).toBinder(); }
private static void doResync() throws IOException { List<String> sources = new ArrayList<String>((List) options.valuesOf("resync")); List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments()); for (String opt : nonOptions) { sources.addAll(asList(opt.split(","))); } cleanNonOptionalArguments(sources); for (int s = 0; s < sources.size(); s++) { String source = sources.get(s); ItemResult ir = getClientNetwork().resync(source); report("Node has reported the state:"); report(ir.toString()); } finish(); }
@Test public void bossSerialization() throws Exception { ItemResult r1 = new ItemResult(APPROVED, false, ZonedDateTime.now(), inFuture(300)); r1.lockedById = HashId.createRandom(); ItemResult r2 = new ItemResult(Boss.unpack(Boss.pack(r1.toBinder()))); assertEquals(r1.state, r2.state); assertEquals(r1.lockedById, r2.lockedById); assertEquals(r1.haveCopy, r2.haveCopy); assertAlmostSame(r1.createdAt, r2.createdAt); assertAlmostSame(r1.expiresAt, r2.expiresAt); assertEquals(r1, r2); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ItemNotification that = (ItemNotification) o; NodeInfo from = getFrom(); if (requestResult != that.requestResult) return false; if (!from.equals(that.getFrom())) return false; if (!itemId.equals(that.itemId)) return false; return itemResult.equals(that.itemResult); }
@Override protected void writeTo(Boss.Writer bw) throws IOException { bw.writeObject(itemId.getDigest()); itemResult.writeTo(bw); bw.writeObject(requestResult); }
@Test public void toBinder() throws Exception { ItemResult r1 = new ItemResult(REVOKED, false, ZonedDateTime.now(), inFuture(300)); r1.extraDataBinder.set("someString", "90314tughiouqehmtcy34ntcn8341tgfesgfwerh"); r1.extraDataBinder.set("someInteger", 42); ItemResult r2 = new ItemResult(r1.toBinder()); assertEquals(r1.state, r2.state); assertEquals(r1.haveCopy, r2.haveCopy); assertEquals(r1.createdAt, r2.createdAt); assertEquals(r1.expiresAt, r2.expiresAt); assertEquals(r1.extraDataBinder.getStringOrThrow("someString"), r2.extraDataBinder.getStringOrThrow("someString")); assertEquals(r1.extraDataBinder.getIntOrThrow("someInteger"), r2.extraDataBinder.getIntOrThrow("someInteger")); assertEquals(r1, r2); }
public ItemResult getResult() { ItemResult result = new ItemResult(ItemState.PENDING, false, ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(5)); result.extraDataBinder = new Binder(); result.errors = new ArrayList<>(); return result; }
try { ItemResult r1 = clientNetworks.get(index).register(c.getPackedTransaction()); System.out.println("result from thread (" + index + "): " + r1.toString()); } catch (IOException e) { if (e.getCause() instanceof SocketTimeoutException) {
public @NonNull ItemResult getResult() { ItemResult result = new ItemResult(record, item != null); result.extraDataBinder = extraResult; if (item != null) result.errors = new ArrayList<>(item.getErrors()); return result; }
/** * Register a specified contract. * * @param contract must be a sealed binary. * @param waitTime - wait time for responce. * @param fromPackedTransaction - register contract with Contract.getPackedTransaction() */ @Deprecated public static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction) throws IOException { // checkContract(contract); List<ErrorRecord> errors = contract.getErrors(); if (errors.size() > 0) { report("contract has errors and can't be submitted for registration"); report("contract id: " + contract.getId().toBase64String()); addErrors(errors); } else { // contract.seal(); ItemResult r; if (fromPackedTransaction) { r = getClientNetwork().register(contract.getPackedTransaction(), waitTime); } else { r = getClientNetwork().register(contract.getLastSealedBinary(), waitTime); } report("submitted with result:"); report(r.toString()); } }
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; }
/** * Register a specified parcel. * @param parcel must be ready for register * @param waitTime wait time for responce. * @return ItemResult for parcel's payload * @throws IOException */ public static ItemResult registerParcel(Parcel parcel, int waitTime) throws IOException { getClientNetwork().registerParcel(parcel.pack(), waitTime); ItemResult r = getClientNetwork().check(parcel.getPayloadContract().getId()); report("paid contract " + parcel.getPayloadContract().getId() + " submitted with result: " + r.toString()); report("payment became " + parcel.getPaymentContract().getId()); report("payment rev 1 " + parcel.getPaymentContract().getRevoking().get(0).getId()); return r; }
public ResyncNotification(NodeInfo from, HashId itemId, boolean answerIsRequested) throws IOException { super(from, itemId, new ItemResult(new StateRecord(itemId)), answerIsRequested); }
@Override protected void readFrom(Boss.Reader br) throws IOException { itemId = HashId.withDigest(br.readBinary()); itemResult = new ItemResult(br); requestResult = br.read(); }
private ItemResult itemResultOfError(Errors error, String object, String message) { Binder binder = new Binder(); binder.put("state",ItemState.UNDEFINED.name()); binder.put("haveCopy",false); binder.put("createdAt", new Date()); binder.put("expiresAt", new Date()); ArrayList<ErrorRecord> errorRecords = new ArrayList<>(); errorRecords.add(new ErrorRecord(error,object,message)); binder.put("errors",errorRecords); return new ItemResult(binder); }
this.record = newRecord; synchronized (cache) { cache.update(newRecord.getId(), new ItemResult(newRecord));
r.save(); synchronized (cache) { cache.update(r.getId(), new ItemResult(r));
@Test public void bossFormatter() throws Exception { ItemResult r1 = new ItemResult(APPROVED, false, ZonedDateTime.now(), inFuture(300)); ItemResult r2 = Boss.load(Boss.pack(r1)); assertEquals(r1, r2); } }
record.save(); synchronized (cache) { cache.update(record.getId(), new ItemResult(record));