@Override public Void run() { try { fn.process(msg.seqid,in, out, iface); return null; } catch (TException te) { throw new RuntimeException(te); } } };
/** * Returns a new empty arguments instance. */ public TBase<?, ?> newArgs() { if (isAsync()) { return asyncFunc().getEmptyArgsInstance(); } else { return syncFunc().getEmptyArgsInstance(); } }
@Nullable private static TBase<?, ?> getResult(ProcessFunction<?, ?> func) { return getResult0(Type.SYNC, func.getClass(), func.getMethodName()); }
public final void process(int seqid, TProtocol iprot, TProtocol oprot, I iface) throws TException { T args = getEmptyArgsInstance(); try { args.read(iprot); iprot.readMessageEnd(); TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.EXCEPTION, seqid)); x.write(oprot); oprot.writeMessageEnd(); result = getResult(iface, args); } catch (TTransportException ex) { LOGGER.error("Transport error while processing " + getMethodName(), ex); throw ex; } catch (TApplicationException ex) { LOGGER.error("Internal application error processing " + getMethodName(), ex); result = ex; msgType = TMessageType.EXCEPTION; } catch (Exception ex) { LOGGER.error("Internal error processing " + getMethodName(), ex); if(rethrowUnhandledExceptions()) throw new RuntimeException(ex.getMessage(), ex); if(!isOneway()) { result = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing " + getMethodName()); msgType = TMessageType.EXCEPTION; if(!isOneway()) { oprot.writeMessageBegin(new TMessage(getMethodName(), msgType, seqid)); result.write(oprot);
private static void invokeSynchronously( ServiceRequestContext ctx, Object impl, ThriftFunction func, TBase<?, ?> args, DefaultRpcResponse reply) { final ProcessFunction<Object, TBase<?, ?>> f = func.syncFunc(); ctx.blockingTaskExecutor().execute(() -> { if (reply.isDone()) { // Closed already most likely due to timeout. return; } try { if (func.isOneWay()) { reply.complete(null); f.getResult(impl, args); } else { final TBase<?, ?> result = f.getResult(impl, args); reply.complete(func.getResult(result)); } } catch (Throwable t) { if (func.isOneWay()) { reply.complete(null); logOneWayFunctionFailure(ctx, t); } else { reply.completeExceptionally(t); } } }); }
private void handleException(int seqid, TProtocol oprot) throws TException { if (!isOneway()) { TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR, "Internal error processing " + getMethodName()); oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.EXCEPTION, seqid)); x.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); } }
private static void invokeSynchronously( ServiceRequestContext ctx, Object impl, ThriftFunction func, TBase<?, ?> args, DefaultRpcResponse reply) { final ProcessFunction<Object, TBase<?, ?>> f = func.syncFunc(); ctx.blockingTaskExecutor().execute(() -> { if (reply.isDone()) { // Closed already most likely due to timeout. return; } try { if (func.isOneWay()) { reply.complete(null); f.getResult(impl, args); } else { final TBase<?, ?> result = f.getResult(impl, args); reply.complete(func.getResult(result)); } } catch (Throwable t) { if (func.isOneWay()) { reply.complete(null); logOneWayFunctionFailure(ctx, t); } else { reply.completeExceptionally(t); } } }); }
if (null == clientUgi){ fn.process(msg.seqid, in, out, iface); return true; } else { // Found ugi, perform doAs().
private static TBase<?, ?> getArgs(ProcessFunction<?, ?> func) { return getArgs0(Type.SYNC, func.getClass(), func.getMethodName()); }
/** * Returns a new empty arguments instance. */ public TBase<?, ?> newArgs() { if (isAsync()) { return asyncFunc().getEmptyArgsInstance(); } else { return syncFunc().getEmptyArgsInstance(); } }
private static void invokeSynchronously( ServiceRequestContext ctx, Object impl, ThriftFunction func, TBase<?, ?> args, DefaultRpcResponse reply) { final ProcessFunction<Object, TBase<?, ?>> f = func.syncFunc(); ctx.blockingTaskExecutor().execute(() -> { if (reply.isDone()) { // Closed already most likely due to timeout. return; } try { if (func.isOneWay()) { reply.complete(null); f.getResult(impl, args); } else { final TBase<?, ?> result = f.getResult(impl, args); reply.complete(func.getResult(result)); } } catch (Throwable t) { if (func.isOneWay()) { reply.complete(null); logOneWayFunctionFailure(ctx, t); } else { reply.completeExceptionally(t); } } }); }
@Override public boolean process(TProtocol in, TProtocol out) throws TException { TMessage msg = in.readMessageBegin(); ProcessFunction fn = processMap.get(msg.name); if (fn == null) { TProtocolUtil.skip(in, TType.STRUCT); in.readMessageEnd(); TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); x.write(out); out.writeMessageEnd(); out.getTransport().flush(); return true; } fn.process(msg.seqid, in, out, iface); return true; } }
private static Class<?>[] getDeclaredExceptions(ProcessFunction<?, ?> func) { return getDeclaredExceptions0(Type.SYNC, func.getClass(), func.getMethodName()); }
/** * Returns a new empty arguments instance. */ public TBase<?, ?> newArgs() { if (isAsync()) { return asyncFunc().getEmptyArgsInstance(); } else { return syncFunc().getEmptyArgsInstance(); } }
private static void invokeSynchronously( ServiceRequestContext ctx, Object impl, ThriftFunction func, TBase<?, ?> args, DefaultRpcResponse reply) { final ProcessFunction<Object, TBase<?, ?>> f = func.syncFunc(); ctx.blockingTaskExecutor().execute(() -> { if (reply.isDone()) { // Closed already most likely due to timeout. return; } try { final TBase<?, ?> result = f.getResult(impl, args); if (func.isOneWay()) { reply.complete(null); } else { reply.complete(func.getResult(result)); } } catch (Throwable t) { reply.completeExceptionally(t); } }); } }
public Void run() { try { fn.process(msg.seqid,in, out, iface); return null; } catch (TException te) { throw new RuntimeException(te); } } };
private static TFieldIdEnum[] getArgFields(ProcessFunction<?, ?> func) { return getArgFields0(Type.SYNC, func.getClass(), func.getMethodName()); }
/** * Returns a new empty arguments instance. */ public TBase<?, ?> newArgs() { if (isAsync()) { return asyncFunc().getEmptyArgsInstance(); } else { return syncFunc().getEmptyArgsInstance(); } }
@Override public Void run() { try { fn.process(msg.seqid,in, out, iface); return null; } catch (TException te) { throw new RuntimeException(te); } } };
ThriftFunction(Class<?> serviceType, ProcessFunction<?, ?> func) throws Exception { this(serviceType, func.getMethodName(), func, Type.SYNC, getArgFields(func), getResult(func), getDeclaredExceptions(func)); }