本文整理了Java中org.infinispan.commons.util.Util.isOSGiContext()
方法的一些代码示例,展示了Util.isOSGiContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.isOSGiContext()
方法的具体详情如下:
包路径:org.infinispan.commons.util.Util
类名称: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()));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!