本文整理了Java中org.osgi.framework.Bundle
类的一些代码示例,展示了Bundle
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle
类的具体详情如下:
包路径:org.osgi.framework.Bundle
类名称:Bundle
[英]An installed bundle in the Framework.
A Bundle object is the access point to define the lifecycle of an installed bundle. Each bundle installed in the OSGi environment must have an associated Bundle object.
A bundle must have a unique identity, a long, chosen by the Framework. This identity must not change during the lifecycle of a bundle, even when the bundle is updated. Uninstalling and then reinstalling the bundle must create a new unique identity.
A bundle can be in one of six states:
Values assigned to these states have no specified ordering; they represent bit values that may be ORed together to determine if a bundle is in one of the valid states.
A bundle should only have active threads of execution when its state is one of STARTING, ACTIVE, or STOPPING. An UNINSTALLED bundle can not be set to another state; it is a zombie and can only be reached because references are kept somewhere.
The Framework is the only entity that is allowed to create Bundleobjects, and these objects are only valid within the Framework that created them.
Bundles have a natural ordering such that if two Bundles have the same #getBundleId() they are equal. A Bundle is less than another Bundle if it has a lower #getBundleId() and is greater if it has a higher bundle id.
[中]框架中已安装的捆绑包。
捆绑包对象是定义已安装捆绑包生命周期的访问点。OSGi环境中安装的每个bundle都必须有一个关联的bundle对象。
捆绑包必须具有唯一的标识,一个由框架选择的长标识。此标识在捆绑包的生命周期内不得更改,即使捆绑包已更新。卸载然后重新安装捆绑包必须创建新的唯一标识。
捆绑包可以处于以下六种状态之一:
*#已卸载
*#已安装
*#已解决
*#开始
*#停车
*#活跃
分配给这些状态的值没有指定的顺序;它们表示位值,这些位值可以一起进行或运算,以确定捆绑包是否处于有效状态之一。
当bundle的状态为STARTING、active或STOPPING时,它应该只有活动的执行线程。无法将已卸载的捆绑包设置为其他状态;它是一个僵尸,只有在引用被保存在某个地方时才能联系到它。
框架是唯一允许创建BundleObject的实体,这些对象仅在创建它们的框架内有效。
捆绑包具有自然顺序,因此如果两个捆绑包具有相同的#getBundleId(),则它们相等。如果捆绑包的#getBundleId()较低,则该捆绑包比另一个捆绑包小;如果捆绑包id较高,则该捆绑包比另一个捆绑包大。
代码示例来源:origin: gocd/gocd
@Override
public void start(BundleContext bundleContext) throws Exception {
Bundle bundle = bundleContext.getBundle();
pluginId = bundle.getSymbolicName();
pluginHealthService = bundleContext.getService(bundleContext.getServiceReference(PluginHealthService.class));
LoggingService loggingService = bundleContext.getService(bundleContext.getServiceReference(LoggingService.class));
Logger.initialize(loggingService);
getImplementersAndRegister(bundleContext, bundle);
reportErrorsToHealthService();
}
代码示例来源:origin: wildfly/wildfly
static Xnio doGetOsgiService() {
Bundle bundle = FrameworkUtil.getBundle(Xnio.class);
BundleContext context = bundle.getBundleContext();
if (context == null) {
throw new IllegalStateException("Bundle not started");
}
ServiceReference<Xnio> sr = context.getServiceReference(Xnio.class);
if (sr == null) {
return null;
}
return context.getService(sr);
}
代码示例来源:origin: jersey/jersey
private void register(final Bundle bundle) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "checking bundle {0}", bundle.getBundleId());
}
Map<String, Callable<List<Class<?>>>> map;
lock.writeLock().lock();
try {
map = factories.get(bundle.getBundleId());
if (map == null) {
map = new ConcurrentHashMap<String, Callable<List<Class<?>>>>();
factories.put(bundle.getBundleId(), map);
}
} finally {
lock.writeLock().unlock();
}
final Enumeration<URL> e = findEntries(bundle, "META-INF/services/", "*", false);
if (e != null) {
while (e.hasMoreElements()) {
final URL u = e.nextElement();
final String url = u.toString();
if (url.endsWith("/")) {
continue;
}
final String factoryId = url.substring(url.lastIndexOf("/") + 1);
map.put(factoryId, new BundleSpiProvidersLoader(factoryId, u, bundle));
}
}
}
代码示例来源:origin: org.osgi/org.osgi.core
public Void run() {
map.put("id", new Long(bundle.getBundleId()));
map.put("location", bundle.getLocation());
String name = bundle.getSymbolicName();
if (name != null) {
map.put("name", name);
}
SignerProperty signer = new SignerProperty(bundle);
if (signer.isBundleSigned()) {
map.put("signer", signer);
}
return null;
}
});
代码示例来源:origin: apache/ignite
Class<?> cls = null;
Bundle[] bundles = bundle.getBundleContext().getBundles();
if (b.getState() <= Bundle.RESOLVED || b.getHeaders().get(Constants.FRAGMENT_HOST) != null)
continue;
cls = b.loadClass(name);
break;
代码示例来源:origin: gocd/gocd
public static Bundle bundleWithHeaders(Map headerMap, String symbolicName) {
Bundle bundle = mock(Bundle.class);
Hashtable<String, String> headers = new Hashtable<>();
headers.putAll(headerMap);
when(bundle.getHeaders()).thenReturn(headers);
when(bundle.getSymbolicName()).thenReturn(symbolicName);
return bundle;
}
代码示例来源:origin: jersey/jersey
final List<URL> result = new LinkedList<URL>();
for (final Bundle bundle : bundleContext.getBundles()) {
while (enumeration.hasMoreElements()) {
final URL url = enumeration.nextElement();
final String path = url.getPath();
while (jars.hasMoreElements()) {
final URL jar = jars.nextElement();
final InputStream inputStream = classLoader.getResourceAsStream(jar.getPath());
if (inputStream == null) {
LOGGER.config(LocalizationMessages.OSGI_REGISTRY_ERROR_OPENING_RESOURCE_STREAM(jar));
LOGGER.log(Level.CONFIG, LocalizationMessages.OSGI_REGISTRY_ERROR_PROCESSING_RESOURCE_STREAM(jar), ex);
try {
inputStream.close();
} catch (final IOException e) {
result.add(bundle.getResource(jarEntryName));
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
private void copyJarInJarLoader(File targetFile) throws IOException {
InputStream is= JavaPlugin.getDefault().getBundle().getEntry(FatJarRsrcUrlBuilder.JAR_RSRC_LOADER_ZIP).openStream();
OutputStream os= new FileOutputStream(targetFile);
byte[] buf= new byte[1024];
while (true) {
int cnt= is.read(buf);
if (cnt <= 0)
break;
os.write(buf, 0, cnt);
}
os.close();
is.close();
}
代码示例来源:origin: org.apache.unomi/unomi-salesforce-connector-rest
@GET
@Path("/version")
public Map<String,String> getVersion() {
Map<String,String> versionInfo = new HashMap<>();
Dictionary<String,String> bundleHeaders = bundleContext.getBundle().getHeaders();
Enumeration<String> bundleHeaderKeyEnum = bundleHeaders.keys();
while (bundleHeaderKeyEnum.hasMoreElements()) {
String bundleHeaderKey = bundleHeaderKeyEnum.nextElement();
versionInfo.put(bundleHeaderKey, bundleHeaders.get((bundleHeaderKey)));
}
return versionInfo;
}
代码示例来源:origin: org.glassfish/osgi-javaee-base
public Manifest getManifest() throws IOException {
URL url = b.getEntry(JarFile.MANIFEST_NAME);
if (url != null) {
InputStream is = url.openStream();
try {
return new Manifest(is);
}
finally {
is.close();
}
}
return null;
}
代码示例来源:origin: eclipse/smarthome
@Override
public URL getResource(String name) {
Enumeration<URL> resourceFiles = this.bundle.findEntries(this.path, this.filePattern, true);
while (resourceFiles.hasMoreElements()) {
URL resourceURL = resourceFiles.nextElement();
String resourcePath = resourceURL.getFile();
File resourceFile = new File(resourcePath);
String resourceFileName = resourceFile.getName();
boolean isHostResource = bundle.getEntry(url.getPath()) != null
&& bundle.getEntry(url.getPath()).equals(url);
if (isHostResource) {
continue;
代码示例来源:origin: org.wisdom-framework/resource-controller
private void index() {
LOGGER.debug("Indexing files for WebJar library {}-{} contained in bundle {} [{}]", name, version,
bundle.getSymbolicName(), bundle.getBundleId());
Enumeration<URL> urls = bundle.findEntries(WebJarController.WEBJAR_LOCATION + name + "/" + version, "*", true);
String root = "/" + WebJarController.WEBJAR_LOCATION + name + "/" + version;
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (url.getPath().startsWith(root) && url.getPath().length() > root.length()) {
String path = url.getPath().substring(root.length() + 1);
index.put(path, url);
}
}
}
代码示例来源:origin: org.ops4j.pax.wicket/pax-wicket-service
@SuppressWarnings("unchecked")
public BundleAnalysingComponentInstantiationListener(BundleContext bundleContext, String defaultInjectionSource) {
this.bundleContext = bundleContext;
this.defaultInjectionSource = defaultInjectionSource;
Enumeration<URL> entries = bundleContext.getBundle().findEntries("/", "*.class", true);
if (entries == null) {
// bundle with no .class files (see PAXWICKET-305)
return;
}
while (entries.hasMoreElements()) {
String urlRepresentation = entries.nextElement().toExternalForm().replace("bundle://.+?/", "").replace('/', '.');
LOGGER.trace("Found entry {} in bundle {}", urlRepresentation, bundleContext.getBundle().getSymbolicName());
bundleResources += urlRepresentation;
}
}
代码示例来源:origin: jboss-fuse/fabric8
public static Map<String,Boolean> getResources( Pattern pattern ) {
Bundle bundle = FrameworkUtil.getBundle(ResourceMap.class);
String base = bundle.getResource("META-INF/MANIFEST.MF").toExternalForm();
int prefix = base.indexOf("META-INF/MANIFEST.MF");
Map<String, Boolean> map = new HashMap<String, Boolean>();
for (Enumeration e = bundle.findEntries("", "*", true); e.hasMoreElements();) {
String url = ((URL) e.nextElement()).toExternalForm();
url = url.substring(prefix);
if (pattern.matcher(url).matches()) {
map.put(url, true);
}
}
return map;
}
代码示例来源:origin: org.jabylon/rest.ui
@Override
public ClassLoader load(Integer key) throws Exception {
Bundle bundle = context.getBundle(key);
String bundleName = bundle.getHeaders().get("Bundle-Localisation");
if(bundleName==null)
bundleName = "OSGI-INF/l10n/bundle";
String prefix = "/"+bundleName.substring(0, bundleName.lastIndexOf('/'));
Enumeration<URL> entries = bundle.findEntries(prefix, "*.properties", false);
List<URL> urls = Collections.emptyList();
if(entries!=null) {
urls = new ArrayList<URL>();
while(entries.hasMoreElements()) {
URL url = entries.nextElement();
urls.add(url);
}
}
return new BundleClassloader(prefix,urls);
}
代码示例来源:origin: org.apache.xbean/xbean-blueprint
public XBeanNamespaceHandler(String namespace, String schemaLocation, Bundle bundle, String propertiesLocation) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
URL propertiesUrl = bundle.getResource(propertiesLocation);
InputStream in = propertiesUrl.openStream();
Properties properties = new Properties();
try {
properties.load(in);
} finally {
in.close();
}
this.namespace = namespace;
this.schemaLocation = bundle.getEntry(schemaLocation);
this.managedClasses = managedClassesFromProperties(bundle, properties);
managedClassesByName = mapClasses(managedClasses);
propertyEditors = propertyEditorsFromProperties(bundle, properties);
this.mappingMetaData = new MappingMetaData(properties);
}
代码示例来源:origin: Tirasa/ConnId
public Properties getResourceAsProperties(Bundle loader, String path) throws IOException {
URL resourceUrl = loader.getResource(path);
if (null == resourceUrl) {
return null;
}
InputStream in = resourceUrl.openStream();
try {
Properties rv = new Properties();
rv.load(in);
return rv;
} finally {
if (null != in) {
in.close();
}
}
}
代码示例来源:origin: org.apache.unomi/unomi-services
private void loadPredefinedPropertyMergeStrategies(BundleContext bundleContext) {
Enumeration<URL> predefinedPropertyMergeStrategyEntries = bundleContext.getBundle().findEntries("META-INF/cxs/mergers", "*.json", true);
if (predefinedPropertyMergeStrategyEntries == null) {
return;
}
ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) pluginTypes.get(bundleContext.getBundle().getBundleId());
while (predefinedPropertyMergeStrategyEntries.hasMoreElements()) {
URL predefinedPropertyMergeStrategyURL = predefinedPropertyMergeStrategyEntries.nextElement();
logger.debug("Found predefined property merge strategy type at " + predefinedPropertyMergeStrategyURL + ", loading... ");
try {
PropertyMergeStrategyType propertyMergeStrategyType = CustomObjectMapper.getObjectMapper().readValue(predefinedPropertyMergeStrategyURL, PropertyMergeStrategyType.class);
propertyMergeStrategyType.setPluginId(bundleContext.getBundle().getBundleId());
propertyMergeStrategyTypeById.put(propertyMergeStrategyType.getId(), propertyMergeStrategyType);
pluginTypeArrayList.add(propertyMergeStrategyType);
} catch (Exception e) {
logger.error("Error while loading property type definition " + predefinedPropertyMergeStrategyURL, e);
}
}
}
代码示例来源:origin: org.fusesource.bai/bai-core
protected InputStream requireDataFile(String uri) throws IOException {
URL url = bundleContext.getBundle().getResource(uri);
if (url == null) {
throw new IllegalArgumentException("Could not find file '" + uri + "' on the bundle classpath");
}
return url.openStream();
}
代码示例来源:origin: hawtio/hawtio
@Override
public String getResourceURL(long bundleID, String resource) {
Bundle b = bundleContext.getBundle(bundleID);
if (b == null)
throw new IllegalArgumentException("Not a valid bundle ID: " + bundleID);
URL res = b.getResource(resource);
if (res == null)
return null;
else
return res.toString();
}
}
内容来源于网络,如有侵权,请联系作者删除!