當前位置: 首頁>>代碼示例>>Java>>正文


Java ContextClassLoaderBinder類代碼示例

本文整理匯總了Java中org.kuali.rice.core.api.util.ContextClassLoaderBinder的典型用法代碼示例。如果您正苦於以下問題:Java ContextClassLoaderBinder類的具體用法?Java ContextClassLoaderBinder怎麽用?Java ContextClassLoaderBinder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ContextClassLoaderBinder類屬於org.kuali.rice.core.api.util包,在下文中一共展示了ContextClassLoaderBinder類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stop

import org.kuali.rice.core.api.util.ContextClassLoaderBinder; //導入依賴的package包/類
/**
 * Stops the plugin.
 */
public synchronized void stop() {
    if (!started) {
        LOG.info(getLogPrefix()+" has already been stopped.");
        return;
    }
    LOG.info(getLogPrefix()+" Stopping...");
    try {
        ContextClassLoaderBinder.doInContextClassLoader(getClassLoader(), new Callable() {
            @Override
            public Object call() throws Exception {
                started = false;
                stopPluginListeners();
                // stop resource loaders of super class
                Plugin.super.stop();
                return null;
            }
        });
    } catch (Throwable t) {
    	LOG.error(getLogPrefix()+" Failed when attempting to stop the plugin.", t);
    }
    resetPlugin();
    LOG.info(getLogPrefix()+" ...stopped.");
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:27,代碼來源:Plugin.java

示例2: testIsOjbLoadedClass_NoOjbOnClasspath

import org.kuali.rice.core.api.util.ContextClassLoaderBinder; //導入依賴的package包/類
/**
 * Ensures false is returned form isOjbLoadedClass if OJB is not on the classpath.
 */
@Test
public void testIsOjbLoadedClass_NoOjbOnClasspath() throws Exception {
    // set an empty classloader to cause the check to load OJB MetadataManager to fail from inside isOjbLoadedClass
    ContextClassLoaderBinder.doInContextClassLoader(ClassLoader.getSystemClassLoader().getParent(),
            new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    assertFalse(detector.isOjbLoadedClass(DummyDataObjectOjb.class));
                    return null;
                }
            });
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:16,代碼來源:LegacyDetectorTest.java

示例3: start

import org.kuali.rice.core.api.util.ContextClassLoaderBinder; //導入依賴的package包/類
/**
 * Starts the plugin.
 */
public synchronized void start() {
    if (started) {
        LOG.info(getLogPrefix()+" has already been started.");
        return;
    }
    LOG.info(getLogPrefix()+" Starting...");
    try {
        ContextClassLoaderBinder.doInContextClassLoader(getClassLoader(), new Callable() {
            @Override
            public Object call() throws Exception {
                startupFailure = false;
                started = true;
                Plugin.super.start();
                LOG.info("Starting plugin listeners");
                startPluginListeners();
                return null;
            }
        });
        ClassLoader classLoader = getClassLoader();
        LOG.info(getLogPrefix()+" ...started." + (classLoader != null ? classLoader.toString() : ""));
    } catch (Throwable t) {
        LOG.error(getLogPrefix()+" Failure starting plugin.", t);
        startupFailure = true;
        started = true;
        stop();
        if (!suppressStartupFailure) {
        	if (t instanceof Error) {
        		throw (Error)t;
        	} else if (t instanceof RuntimeException) {
        		throw (RuntimeException)t;
        	}
        	throw new WorkflowRuntimeException("Failed to startup plugin.", t);
        }
    }
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:39,代碼來源:Plugin.java

示例4: load

import org.kuali.rice.core.api.util.ContextClassLoaderBinder; //導入依賴的package包/類
/**
 * Loads and creates the Plugin.
 */
public Plugin load() throws Exception {
    final PluginClassLoader classLoader = createPluginClassLoader();
    LOG.info("Created plugin ClassLoader: " + classLoader);
    return ContextClassLoaderBinder.doInContextClassLoader(classLoader, new Callable<Plugin>() {
        public Plugin call() throws IOException {
            return loadWithinContextClassLoader(classLoader);
        }
    });
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:13,代碼來源:BasePluginLoader.java

示例5: testBinding

import org.kuali.rice.core.api.util.ContextClassLoaderBinder; //導入依賴的package包/類
/**
    * @deprecated {@link ContextClassLoaderBinder#doInContextClassLoader(ClassLoader, java.util.concurrent.Callable)} is the safe way to
    * run code under a specific Context ClassLoader that ensures the classloader is always set and unset properly.
    */
   @Deprecated
@Test public void testBinding() {
       try {
           ContextClassLoaderBinder.unbind();
           fail("unbind succeeded without any prior bind");
       } catch (IllegalStateException ise) {
           // expect illegal state
       }

       ClassLoader cl0 = new URLClassLoader(new URL[] {});
       ClassLoader cl1 = new URLClassLoader(new URL[] {});
       ClassLoader cl2 = new URLClassLoader(new URL[] {});

       ClassLoader original = Thread.currentThread().getContextClassLoader();
       ContextClassLoaderBinder.bind(cl0);
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(original, Thread.currentThread().getContextClassLoader());

       ContextClassLoaderBinder.bind(cl0);
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.bind(cl1);
       assertEquals(cl1, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(original, Thread.currentThread().getContextClassLoader());

       ContextClassLoaderBinder.bind(cl0);
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.bind(cl1);
       assertEquals(cl1, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.bind(cl2);
       assertEquals(cl2, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(cl1, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(original, Thread.currentThread().getContextClassLoader());
   }
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:46,代碼來源:ContextClassLoaderBinderTest.java

示例6: testBinding

import org.kuali.rice.core.api.util.ContextClassLoaderBinder; //導入依賴的package包/類
/**
    * @deprecated {@link ContextClassLoaderBinder#doInContextClassLoader(ClassLoader, java.util.concurrent.Callable)} is the safe way to
    * run code under a specific Context ClassLoader that ensures the classloader is always set and unset properly.
    */
@Test public void testBinding() {
       try {
           ContextClassLoaderBinder.unbind();
           fail("unbind succeeded without any prior bind");
       } catch (IllegalStateException ise) {
           // expect illegal state
       }

       ClassLoader cl0 = new URLClassLoader(new URL[] {});
       ClassLoader cl1 = new URLClassLoader(new URL[] {});
       ClassLoader cl2 = new URLClassLoader(new URL[] {});

       ClassLoader original = Thread.currentThread().getContextClassLoader();
       ContextClassLoaderBinder.bind(cl0);
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(original, Thread.currentThread().getContextClassLoader());

       ContextClassLoaderBinder.bind(cl0);
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.bind(cl1);
       assertEquals(cl1, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(original, Thread.currentThread().getContextClassLoader());

       ContextClassLoaderBinder.bind(cl0);
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.bind(cl1);
       assertEquals(cl1, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.bind(cl2);
       assertEquals(cl2, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(cl1, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(cl0, Thread.currentThread().getContextClassLoader());
       ContextClassLoaderBinder.unbind();
       assertEquals(original, Thread.currentThread().getContextClassLoader());
   }
 
開發者ID:kuali,項目名稱:rice,代碼行數:45,代碼來源:ContextClassLoaderBinderTest.java


注:本文中的org.kuali.rice.core.api.util.ContextClassLoaderBinder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。