Example usage for java.lang.reflect InvocationTargetException getStackTrace

List of usage examples for java.lang.reflect InvocationTargetException getStackTrace

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.apache.hadoop.hbase.ipc.ScheduleHBaseServer.java

@Override
public Writable call(Writable param, long receivedTime) throws IOException {
    try {/*from  w w  w. j  a  v a 2 s. co  m*/
        Invocation call = (Invocation) param;
        if (call.getMethodName() == null) {
            throw new IOException("Could not find requested method, the usual "
                    + "cause is a version mismatch between client and server.");
        }

        Method method = implementation.getMethod(call.getMethodName(), call.getParameterClasses());

        long startTime = System.currentTimeMillis();

        Object value = method.invoke(instance, call.getParameters());
        /**
         * do with openScanner option, added by ScheduleHBaseServer
         */
        if (call.getMethodName().endsWith("openScanner")) {
            this.initScannerPri(call, value);
        }

        int processingTime = (int) (System.currentTimeMillis() - startTime);
        int qTime = (int) (startTime - receivedTime);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Served: " + call.getMethodName() + " queueTime= " + qTime + " procesingTime= "
                    + processingTime);
        }
        rpcMetrics.rpcQueueTime.inc(qTime);
        rpcMetrics.rpcProcessingTime.inc(processingTime);
        rpcMetrics.inc(call.getMethodName(), processingTime);

        return new HbaseObjectWritable(method.getReturnType(), value);

    } catch (InvocationTargetException e) {
        Throwable target = e.getTargetException();
        if (target instanceof IOException) {
            throw (IOException) target;
        }
        IOException ioe = new IOException(target.toString());
        ioe.setStackTrace(target.getStackTrace());
        throw ioe;
    } catch (Throwable e) {
        IOException ioe = new IOException(e.toString());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
    }
}