@Override public Object request(String messageName, Object request) throws IOException { try { return super.request(messageName, request); } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException)e; if (e instanceof IOException) throw (IOException)e; throw new AvroRemoteException(e); } }
@Override public Exception readError(Schema writer, Schema reader, Decoder in) throws IOException { Object error = new GenericDatumReader<>(writer, reader, data) .read(null,in); if (error instanceof CharSequence) return new AvroRuntimeException(error.toString()); // system error return new AvroRemoteException(error); }
@Override public <T> void request(String messageName, Object request, Callback<T> callback) throws IOException { try { super.request(messageName, request, callback); } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException)e; if (e instanceof IOException) throw (IOException)e; throw new AvroRemoteException(e); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return invokeUnaryMethod(method, args); } catch (RuntimeException re) { //rethrow any runtime exception throw re; } catch (Exception e) { //throw any of the declared exceptions for (Class<?> exceptionClass : method.getExceptionTypes()) { if (exceptionClass.isInstance(e)) { throw e; } } //wrap all other exceptions throw new AvroRemoteException(e); } }
private Object unaryRequest(String methodName, Object[] args) throws Exception { CallFuture<Object> callFuture = new CallFuture<>(); unaryRequest(methodName, args, callFuture); try { return callFuture.get(); } catch (Exception e) { if (e.getCause() instanceof Exception) { throw (Exception)e.getCause(); } throw new AvroRemoteException(e.getCause()); } }
@Override public Status appendBatch(List<AvroFlumeEvent> events) throws AvroRemoteException { logger.info("Throwing: Received {} events from appendBatch()", events.size()); throw new AvroRemoteException("Handler smash!"); } }
@Override public Object respond(Message message, Object request) throws AvroRemoteException { try { Thread.sleep((Long)((GenericRecord)request).get("millis")); } catch (InterruptedException e) { throw new AvroRemoteException(e); } return null; } }
throw new AvroRemoteException(e);
@Override public Status append(AvroFlumeEvent event) throws AvroRemoteException { logger.info("Throwing: Received event from append(): {}", new String(event.getBody().array(), Charset.forName("UTF8"))); throw new AvroRemoteException("Handler smash!"); }
/** Writes a request message and reads a response or error message. */ public Object request(String messageName, Object request) throws Exception { // Initialize request Request rpcRequest = new Request(messageName, request, new RPCContext()); CallFuture<Object> future = /* only need a Future for two-way messages */ rpcRequest.getMessage().isOneWay() ? null : new CallFuture<>(); // Send request request(rpcRequest, future); if (future == null) // the message is one-way, so return immediately return null; try { // the message is two-way, wait for the result return future.get(); } catch (ExecutionException e) { if (e.getCause() instanceof Exception) { throw (Exception)e.getCause(); } else { throw new AvroRemoteException(e.getCause()); } } }
public Object respond(Message message, Object request) throws AvroRemoteException { GenericRecord params = (GenericRecord)request; if ("hello".equals(message.getName())) { LOG.info("hello: "+params.get("greeting")); return new Utf8("goodbye"); } if ("echo".equals(message.getName())) { Object record = params.get("record"); LOG.info("echo: "+record); return record; } if ("echoBytes".equals(message.getName())) { Object data = params.get("data"); LOG.info("echoBytes: "+data); return data; } if ("error".equals(message.getName())) { if (throwUndeclaredError) throw new RuntimeException("foo"); GenericRecord error = new GenericData.Record(PROTOCOL.getType("TestError")); error.put("message", new Utf8("an error")); throw new AvroRemoteException(error); } throw new AvroRuntimeException("unexpected message: "+message.getName()); }
throw (Exception) error; } else { throw new AvroRemoteException(error);
@Override public boolean executeJob(AvroJob avroJob, AvroJobInput jobInput) throws AvroRemoteException { try { return genericExecuteJob(avroJob,jobInput); } catch (JobException e) { throw new AvroRemoteException(e); } }
@Override public Exception readError(Schema writer, Schema reader, Decoder in) throws IOException { Object error = new GenericDatumReader<Object>(writer, reader, data) .read(null,in); if (error instanceof CharSequence) return new AvroRuntimeException(error.toString()); // system error return new AvroRemoteException(error); }
@Override public AvroWorkflowCondition getConditionById(String conditionId) throws AvroRemoteException { try { WorkflowCondition c = repo.getWorkflowConditionById(conditionId); return AvroTypeFactory.getAvroWorkflowCondition(c); } catch (Exception e) { logger.error("Error when getting condition by ID: {} - {}", conditionId, e.getMessage()); throw new AvroRemoteException("Exception getting condition by id: Message: " + e.getMessage()); } }
@Override public boolean setProductTransferStatus(AvroProduct product) throws AvroRemoteException { try { return this.fileManager.setProductTransferStatus(AvroTypeFactory.getProduct(product)); } catch (CatalogException e) { throw new AvroRemoteException(e); } }
@Override public List<AvroProduct> getTopNProducts(int n) throws AvroRemoteException { List<AvroProduct> avroProducts = new ArrayList<AvroProduct>(); try { for (Product p : this.fileManager.getTopNProducts(n)){ avroProducts.add(AvroTypeFactory.getAvroProduct(p)); } } catch (CatalogException e) { throw new AvroRemoteException(e.getMessage()); } return avroProducts; }
@Override public List<AvroProduct> query(AvroQuery avroQuery, AvroProductType avroProductType) throws AvroRemoteException { List<AvroProduct> avroProducts = new ArrayList<AvroProduct>(); try { for (Product p : this.fileManager.query(AvroTypeFactory.getQuery(avroQuery), AvroTypeFactory.getProductType(avroProductType))){ avroProducts.add(AvroTypeFactory.getAvroProduct(p)); } return avroProducts; } catch (CatalogException e) { throw new AvroRemoteException(e.getMessage()); } }
@Override public AvroProductType getProductTypeById(String productTypeId) throws AvroRemoteException { try { return AvroTypeFactory.getAvroProductType(this.fileManager.getProductTypeById(productTypeId)); } catch (RepositoryManagerException e) { throw new AvroRemoteException(e.getMessage()); } }
@Override public boolean addProductReferences(AvroProduct product) throws AvroRemoteException { try { return this.fileManager.addProductReferences(AvroTypeFactory.getProduct(product)); } catch (CatalogException e) { throw new AvroRemoteException(e.getMessage()); } }