Example usage for java.lang Thread setContextClassLoader

List of usage examples for java.lang Thread setContextClassLoader

Introduction

In this page you can find the example usage for java.lang Thread setContextClassLoader.

Prototype

public void setContextClassLoader(ClassLoader cl) 

Source Link

Document

Sets the context ClassLoader for this Thread.

Usage

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

/**
 * @param scan the Scan specification//from   w  w w  . j  a v a2s.com
 * @param s the scanner
 * @return the scanner instance to use
 * @exception IOException Exception
 */
public RegionScanner postScannerOpen(final Scan scan, RegionScanner s) throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                s = ((RegionObserver) env.getInstance()).postScannerOpen(ctx, scan, s);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return s;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

/**
 * @param info//from w ww.ja v  a2 s  .  c  om
 * @param logKey
 * @param logEdit
 * @throws IOException
 */
public void postWALRestore(final HRegionInfo info, final HLogKey logKey, final WALEdit logEdit)
        throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                ((RegionObserver) env.getInstance()).postWALRestore(ctx, info, logKey, logEdit);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

public void postEndpointInvocation(final Service service, final String methodName, final Message request,
        final Message.Builder responseBuilder) throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof EndpointObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                ((EndpointObserver) env.getInstance()).postEndpointInvocation(ctx, service, methodName, request,
                        responseBuilder);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }/*w w w .jav a2s . c om*/
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

public boolean preSplitBeforePONR(final byte[] splitKey, final List<Mutation> metaEntries) throws IOException {
    boolean bypass = false;
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                ((RegionObserver) env.getInstance()).preSplitBeforePONR(ctx, splitKey, metaEntries);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }/*from w w  w  .ja  v a 2  s. co  m*/
            bypass |= ctx.shouldBypass();
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return bypass;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

/**
 * @param s the scanner/*from   w w w . ja  v  a  2s .c om*/
 * @param results the result set returned by the region server
 * @param limit the maximum number of results to return
 * @param hasMore
 * @return 'has more' indication to give to client
 * @exception IOException Exception
 */
public boolean postScannerNext(final InternalScanner s, final List<Result> results, final int limit,
        boolean hasMore) throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                hasMore = ((RegionObserver) env.getInstance()).postScannerNext(ctx, s, results, limit, hasMore);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return hasMore;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

/**
 * @param familyPaths pairs of { CF, file path } submitted for bulk load
 * @param hasLoaded whether load was successful or not
 * @return the possibly modified value of hasLoaded
 * @throws IOException/*from w w  w. j  a v a2s .  c  o  m*/
 */
public boolean postBulkLoadHFile(final List<Pair<byte[], String>> familyPaths, boolean hasLoaded)
        throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                hasLoaded = ((RegionObserver) env.getInstance()).postBulkLoadHFile(ctx, familyPaths, hasLoaded);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return hasLoaded;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

public Cell postMutationBeforeWAL(final MutationType opType, final Mutation mutation, final Cell oldCell,
        Cell newCell) throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                newCell = ((RegionObserver) env.getInstance()).postMutationBeforeWAL(ctx, opType, mutation,
                        oldCell, newCell);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }//w  ww . j  a va2  s  . co m
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return newCell;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

public Message preEndpointInvocation(final Service service, final String methodName, Message request)
        throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof EndpointObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                request = ((EndpointObserver) env.getInstance()).preEndpointInvocation(ctx, service, methodName,
                        request);//from w  w w  .ja va2 s  .  co  m
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return request;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

/**
 * See//from  www  .  ja va 2  s  .c om
 * {@link RegionObserver#preFlushScannerOpen(ObserverContext,
 *    Store, KeyValueScanner, InternalScanner)}
 */
public InternalScanner preFlushScannerOpen(final Store store, final KeyValueScanner memstoreScanner)
        throws IOException {
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    InternalScanner s = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                s = ((RegionObserver) env.getInstance()).preFlushScannerOpen(ctx, store, memstoreScanner, s);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return s;
}

From source file:org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.java

/**
 * @param get the Get request/*from  ww w.jav  a2s  . c  om*/
 * @return true if default processing should be bypassed
 * @exception IOException Exception
 */
public boolean preGet(final Get get, final List<Cell> results) throws IOException {
    boolean bypass = false;
    ObserverContext<RegionCoprocessorEnvironment> ctx = null;
    for (RegionEnvironment env : coprocessors) {
        if (env.getInstance() instanceof RegionObserver) {
            ctx = ObserverContext.createAndPrepare(env, ctx);
            Thread currentThread = Thread.currentThread();
            ClassLoader cl = currentThread.getContextClassLoader();
            try {
                currentThread.setContextClassLoader(env.getClassLoader());
                ((RegionObserver) env.getInstance()).preGetOp(ctx, get, results);
            } catch (Throwable e) {
                handleCoprocessorThrowable(env, e);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            bypass |= ctx.shouldBypass();
            if (ctx.shouldComplete()) {
                break;
            }
        }
    }
    return bypass;
}