private Binder inSession(Session s, Implementor processor) { // synchronized (s) { try { s.errors.clear(); return s.answer(processor.apply(s)); } catch (ClientError e) { s.errors.add(e.getErrorRecord()); } catch (Exception e) { s.errors.add(new ErrorRecord(Errors.FAILURE, "", e.getMessage())); } return s.answer(null); // } }
/** * Register contract on the network with parcel (includes payment) * @param packed {@link Parcel} binary * @param millisToWait maximum time to wait for final {@link ItemState} * @return result of registration * @throws ClientError */ @Deprecated public boolean registerParcel(byte[] packed, long millisToWait) throws ClientError { try { registerParcelWithState(packed, millisToWait); return true; } catch (ClientError e) { if (e.getErrorRecord().getError() == Errors.COMMAND_PENDING) return true; else return false; } }
/** * Register contract on the network with parcel (includes payment) * @param packed {@link Parcel} binary * @return result of registration * @throws ClientError */ public boolean registerParcel(byte[] packed) throws ClientError { try { registerParcelWithState(packed, 0); return true; } catch (ClientError e) { if (e.getErrorRecord().getError() == Errors.COMMAND_PENDING) return true; else return false; } }
/** * Register packed binary contract and wait for the consensus. * * @param packedParcel * @param millisToWait wait for the consensus as long as specified time, <= 0 means no wait (returns some pending * state from registering). * @return last item status returned by the network * @throws ClientError */ public boolean registerParcel(byte[] packedParcel, long millisToWait) throws ClientError { try { client.registerParcelWithState(packedParcel, millisToWait); return true; } catch (ClientError e) { if (e.getErrorRecord().getError() == Errors.COMMAND_PENDING) return true; else return false; } }
public Binder command(Binder params) throws ClientError, EncryptionError { // decrypt params and execute command Binder result = null; try { result = Binder.fromKeysValues( "result", executeAuthenticatedCommand( Boss.unpack( sessionKey.decrypt(params.getBinaryOrThrow("params")) ) ) ); } catch (Exception e) { ErrorRecord r = (e instanceof ClientError) ? ((ClientError) e).getErrorRecord() : new ErrorRecord(Errors.COMMAND_FAILED, "", e.getMessage()); result = Binder.fromKeysValues( "error", r ); } // encrypt and return result return Binder.fromKeysValues( "result", sessionKey.encrypt(Boss.pack(result)) ); }