Example usage for org.apache.thrift ProcessFunction process

List of usage examples for org.apache.thrift ProcessFunction process

Introduction

In this page you can find the example usage for org.apache.thrift ProcessFunction process.

Prototype

public final void process(int seqid, TProtocol iprot, TProtocol oprot, I iface) throws TException 

Source Link

Usage

From source file:org.apache.hadoop.hive.metastore.TUGIBasedProcessor.java

License:Apache License

@Override
public boolean process(final TProtocol in, final TProtocol out) throws TException {
    setIpAddress(in);//www. j ava 2s .  c om

    final TMessage msg = in.readMessageBegin();
    final ProcessFunction<I, ? extends TBase<?, ?>> fn = functions.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;
    }
    TUGIContainingTransport ugiTrans = (TUGIContainingTransport) in.getTransport();
    // Store ugi in transport if the rpc is set_ugi
    if (msg.name.equalsIgnoreCase("set_ugi")) {
        try {
            handleSetUGI(ugiTrans, fn, msg, in, out);
        } catch (TException e) {
            throw e;
        } catch (Exception e) {
            throw new TException(e.getCause());
        }
        return true;
    }
    UserGroupInformation clientUgi = ugiTrans.getClientUGI();
    if (null == clientUgi) {
        // At this point, transport must contain client ugi, if it doesn't then its an old client.
        fn.process(msg.seqid, in, out, iface);
        return true;
    } else { // Found ugi, perform doAs().
        PrivilegedExceptionAction<Void> pvea = new PrivilegedExceptionAction<Void>() {
            public Void run() {
                try {
                    fn.process(msg.seqid, in, out, iface);
                    return null;
                } catch (TException te) {
                    throw new RuntimeException(te);
                }
            }
        };
        try {
            shim.doAs(clientUgi, pvea);
            return true;
        } catch (RuntimeException rte) {
            if (rte.getCause() instanceof TException) {
                throw (TException) rte.getCause();
            }
            throw rte;
        } catch (InterruptedException ie) {
            throw new RuntimeException(ie); // unexpected!
        } catch (IOException ioe) {
            throw new RuntimeException(ioe); // unexpected!
        } finally {
            shim.closeAllForUGI(clientUgi);
        }
    }
}