org.apache.webbeans.spi.SingletonService Java Examples

The following examples show how to use org.apache.webbeans.spi.SingletonService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassLoaderLock.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
public static ClassLoader getUsableContainerLoader() {
    ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
    if (currentCL == null) {
        currentCL = ClassLoaderLock.class.getClassLoader();
    }
    if (Boolean.getBoolean("meecrowave.junit.classloaderlock.off")) { // safeguard for advanced cases
        return currentCL;
    }

    final SingletonService<WebBeansContext> singletonService = WebBeansFinder.getSingletonService();
    synchronized (singletonService) {
        try {
            if (singletonService instanceof DefaultSingletonService) {
                synchronized (singletonService) {
                    ((DefaultSingletonService) singletonService).register(currentCL, null);
                    // all fine, it seems we do not have an OWB container for this ClassLoader yet

                    // let's reset it then ;
                    singletonService.clear(currentCL);
                }
                return currentCL;
            }
        }
        catch (IllegalArgumentException iae) {
            // whoops there is already an OWB container registered for this very ClassLoader
        }

        return new ClassLoader(currentCL) {};
    }
}
 
Example #2
Source File: HammockInitializer.java    From hammock with Apache License 2.0 5 votes vote down vote up
@Override
protected SeContainer newContainer(WebBeansContext context) {
    SingletonService<WebBeansContext> singletonService = WebBeansFinder.getSingletonService();
    if(singletonService instanceof HolderSingletonService) {
        ((HolderSingletonService) singletonService).register(context);
    } else {
        try {
            WebBeansFinder.setSingletonService(new HolderSingletonService(context));
        } catch (Exception e) {
            logger.info("Unable to override OWB SingletonService", e);
        }
    }
    return super.newContainer(context);
}