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); // } }
protected final <T> T protect(Executor<T> e) throws ClientError { try { return e.execute(); } catch (Exception ex) { //ex.printStackTrace(); throw new ClientError(ex); } }
private static void doSetLogLevels() { List<String> sources = new ArrayList<String>((List) options.valuesOf("set-log-levels")); if(sources.size() != 3) { addError(Errors.COMMAND_FAILED.name(),"levels", "specify 3 log levels: node,network,udp"); } try { ItemResult ir = getClientNetwork().client.setVerboseLevel(DatagramAdapter.VerboseLevel.stringToInt(sources.get(0)), DatagramAdapter.VerboseLevel.stringToInt(sources.get(1)), DatagramAdapter.VerboseLevel.stringToInt(sources.get(2))); addErrors(ir.errors); } catch (ClientError clientError) { if (options.has("verbose")) clientError.printStackTrace(); addError(Errors.COMMAND_FAILED.name(),"levels",clientError.getMessage()); } catch (IOException e) { if (options.has("verbose")) e.printStackTrace(); addError(Errors.COMMAND_FAILED.name(),"levels",e.getMessage()); } finish(); }
clientError.printStackTrace();
contractsApproved.set(finalI, true); } catch (ClientError clientError) { clientError.printStackTrace(); fail(clientError.getMessage()); } catch (InterruptedException e) { e.printStackTrace();
clientError.printStackTrace(); clientError.printStackTrace(); clientError.printStackTrace();
clientError.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.out.println("single thread: " + rr + " time: " + ((System.nanoTime() - t) * 1e-9)); } catch (ClientError clientError) { clientError.printStackTrace(); } catch (IOException e) { e.printStackTrace();
/** * 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; } }
throw new ClientError(Errors.COMMAND_FAILED, cmd, e.getMessage()); throw new ClientError(Errors.UNKNOWN_COMMAND, "command", "unknown: " + cmd);
return testSpace.client.queryContract(slotId, originId, null); } catch (ClientError e) { e.printStackTrace(); return null; return testSpace.client.getState(hashId).state == ItemState.APPROVED; } catch (ClientError e) { e.printStackTrace(); 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; } }
if(result instanceof String) { System.out.println(">> registerParcel " + result); throw new ClientError(Errors.FAILURE, "registerParcel", "approveParcel returns: " + result); } else { if (millisToWait > 0) { } catch (InterruptedException e) { e.printStackTrace(); throw new ClientError(e); } catch (Quantiser.QuantiserException e) { throw new ClientError(e); } catch (IOException e) { e.printStackTrace(); throw new ClientError(e); throw new ClientError(Errors.COMMAND_PENDING, "registerParcel", "waiting time is up, please update payload state later");
return testSpace.client.getState(hashId).state == ItemState.APPROVED; } catch (ClientError e) { e.printStackTrace(); return false; return testSpace.client.queryContract(slotId, originId, null); } catch (ClientError e) { e.printStackTrace(); return null;
/** * 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; } }
private Binder onConnect(Binder params) throws ClientError { try { PublicKey clientKey = new PublicKey(params.getBinaryOrThrow("client_key")); return inSession(clientKey, session -> session.connect()); } catch (Exception e) { throw new ClientError(Errors.BAD_CLIENT_KEY, "client_key", "bad client key"); } }
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)) ); }
e.printStackTrace(); } catch (Quantiser.QuantiserException e) { throw new ClientError(e); } catch (IOException e) { e.printStackTrace();