org.infinispan.commons.util.Util.isOSGiContext()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.infinispan.commons.util.Util.isOSGiContext()方法的一些代码示例,展示了Util.isOSGiContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.isOSGiContext()方法的具体详情如下:
包路径:org.infinispan.commons.util.Util
类名称:Util
方法名:isOSGiContext

Util.isOSGiContext介绍

[英]Tries to determine if the code is running in an OSGi context.
[中]尝试确定代码是否在OSGi上下文中运行。

代码示例

代码示例来源:origin: org.infinispan/infinispan-cachestore-jpa

private static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) {
   if (Util.isOSGiContext()) {
     Bundle thisBundle = FrameworkUtil.getBundle(EntityManagerFactoryRegistry.class);
     BundleContext context = thisBundle.getBundleContext();

     ServiceReference<?> serviceReference = context.getServiceReference(PersistenceProvider.class.getName());
     PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService(serviceReference);

     return persistenceProvider.createEntityManagerFactory(persistenceUnitName, null);
   } else {
     return Persistence.createEntityManagerFactory(persistenceUnitName);
   }
  }
}

代码示例来源:origin: org.infinispan/infinispan-commons

private OsgiClassLoader() {
 // DO NOT use ClassLoader#parent, which is typically the SystemClassLoader for most containers. Instead,
 // allow the ClassNotFoundException to be thrown. ClassLoaderServiceImpl will check the SystemClassLoader
 // later on. This is especially important for embedded OSGi containers, etc.
 super(null);
 if (Util.isOSGiContext()) {
   final BundleContext bundleContext = FrameworkUtil.getBundle(OsgiClassLoader.class).getBundleContext();
   Bundle[] foundBundles = bundleContext.getBundles();
   bundles = new ArrayList<>(foundBundles.length);
   for (Bundle foundBundle : foundBundles) {
    bundles.add(new WeakReference<>(foundBundle));
   }
 } else {
   bundles = Collections.emptyList();
 }
}

代码示例来源:origin: org.infinispan/infinispan-commons

public static ClassLoader[] getClassLoaders(ClassLoader appClassLoader) {
 if (isOSGiContext()) {
   return SecurityActions.getOSGIContextClassLoaders(appClassLoader);
 } else {
   return SecurityActions.getClassLoaders(appClassLoader);
 }
}

代码示例来源:origin: org.infinispan/infinispan-commons

private static <T> void addOsgiServices(Class<T> contract, Map<String, T> services) {
   if (!Util.isOSGiContext()) {
     return;
   }
   final BundleContext bundleContext = FrameworkUtil.getBundle(ServiceFinder.class).getBundleContext();
   final ServiceTracker<T, T> serviceTracker = new ServiceTracker<T, T>(bundleContext, contract.getName(),
      null);
   serviceTracker.open();
   try {
     final Object[] osgiServices = serviceTracker.getServices();
     if (osgiServices != null) {
      for (Object osgiService : osgiServices) {
        if (services.putIfAbsent(osgiService.getClass().getName(), (T) osgiService) == null) {
         LOG.debugf("Loading service impl: %s", osgiService.getClass().getSimpleName());
        } else {
         LOG.debugf("Ignoring already loaded service: %s", osgiService.getClass().getSimpleName());
        }
      }
     }
   } catch (Exception e) {
     // ignore
   }
  }
}

代码示例来源:origin: org.infinispan/infinispan-core

private static void markAsTransactional(boolean transactional, ConfigurationBuilder builder) {
 if (!transactional) {
   builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL);
 } else {
   builder.transaction()
      .transactionMode(TransactionMode.TRANSACTIONAL);
   if (!Util.isOSGiContext()) {
    //automatically change default TM lookup to the desired one but only outside OSGi. In OSGi we need to use GenericTransactionManagerLookup
    builder.transaction().transactionManagerLookup(Util.getInstance(TransactionSetup.getManagerLookup(), TestCacheManagerFactory.class.getClassLoader()));
   }
 }
}

相关文章