本文整理汇总了Java中org.osgi.framework.BundleEvent类的典型用法代码示例。如果您正苦于以下问题:Java BundleEvent类的具体用法?Java BundleEvent怎么用?Java BundleEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BundleEvent类属于org.osgi.framework包,在下文中一共展示了BundleEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bundleChanged
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
public @Override void bundleChanged(BundleEvent event) {
Bundle bundle = event.getBundle();
switch (event.getType()) {
case BundleEvent.STARTED:
// System.err.println("started " + bundle.getSymbolicName());
Dictionary<?,?> headers = bundle.getHeaders();
load(queue.offer(bundle, provides(headers), requires(headers), needs(headers)));
break;
case BundleEvent.STOPPED:
// System.err.println("stopped " + bundle.getSymbolicName());
if (framework.getState() == Bundle.STOPPING) {
// System.err.println("fwork stopping during " + bundle.getSymbolicName());
// ActiveQueue.stop();
} else {
unload(queue.retract(bundle));
}
break;
}
}
示例2: BundleImpl
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
/**
* create a new bundle object from InputStream. This is used when a new bundle is installed.
*
* @param location the bundle location.
* @param stream the input stream.
* @throws BundleException if something goes wrong.
* @throws IOException
*/
BundleImpl(final File bundleDir, final String location, final InputStream stream,
final File file, String unique_tag, boolean installForCurrentVersion, long dexPatchVersion) throws BundleException, IOException{
this.location = location;
this.bundleDir = bundleDir;
if(installForCurrentVersion) {
Framework.notifyBundleListeners(BundleEvent.BEFORE_INSTALL, this);
}
if (stream != null) {
this.archive = new BundleArchive(location,bundleDir, stream,unique_tag, dexPatchVersion);
} else if (file != null) {
this.archive = new BundleArchive(location,bundleDir, file,unique_tag, dexPatchVersion);
}
this.state = INSTALLED;
if (installForCurrentVersion) {
resolveBundle();
Framework.bundles.put(location, this);
// notify the listeners
Framework.notifyBundleListeners(BundleEvent.INSTALLED, this);
}
}
示例3: startBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
/**
* the actual starting happens here.
*
* @throws BundleException if the bundle cannot be resolved or the Activator throws an exception.
*/
public synchronized void startBundle() {
if (state == UNINSTALLED) {
throw new IllegalStateException("Cannot start uninstalled bundle " + toString());
}
if (state == ACTIVE) {
return;
}
if (state == INSTALLED) {
throw new RuntimeException("can not start bundle which is not resolved");
}
state = STARTING;
Framework.notifyBundleListeners(BundleEvent.BEFORE_STARTED, this);
Framework.notifyBundleListeners(BundleEvent.STARTED, this);
if (Framework.DEBUG_BUNDLES) {
Log.i("Framework","Bundle " + toString() + " started.");
}
}
示例4: uninstall
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
/**
* uninstall the bundle.
*
* @throws BundleException if bundle is already uninstalled
* @see org.osgi.framework.Bundle#uninstall()
* @category Bundle
*/
public synchronized void uninstall() throws BundleException {
if (state == UNINSTALLED) {
throw new IllegalStateException("Bundle " + toString() + " is already uninstalled.");
}
if (state == ACTIVE) {
try {
stop();
} catch (Throwable t) {
Framework.notifyFrameworkListeners(FrameworkEvent.ERROR, this, t);
}
}
state = UNINSTALLED;
classloader.cleanup(true);
classloader = null;
Framework.bundles.remove(getLocation());
Framework.notifyBundleListeners(BundleEvent.UNINSTALLED, this);
}
示例5: notifyBundleListeners
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
/**
* notify all bundle listeners.
*
* @param state the new state.
* @param bundle the bundle.
*/
static void notifyBundleListeners(final int state, final Bundle bundle) {
if (syncBundleListeners.isEmpty() && bundleListeners.isEmpty()) {
return;
}
final BundleEvent event = new BundleEvent(state, bundle);
// inform the synchrounous bundle listeners first ...
final BundleListener[] syncs = (BundleListener[]) syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]);
for (int i = 0; i < syncs.length; i++) {
syncs[i].bundleChanged(event);
}
if (bundleListeners.isEmpty()) {
return;
}
final BundleListener[] asyncs = (BundleListener[]) bundleListeners.toArray(new BundleListener[bundleListeners.size()]);
for (int i = 0; i < asyncs.length; i++) {
asyncs[i].bundleChanged(event);
}
}
示例6: activate
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
@Activate
void activate(BundleContext ctx) {
this.base = new File("").toURI();
// Find the resolved vaadin bundle
this.vaadinResourceBundles = new BundleTracker<Bundle>(ctx, Bundle.RESOLVED |
Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING,
new BundleTrackerCustomizer<Bundle>() {
@Override
public Bundle addingBundle(Bundle bundle, BundleEvent event) {
return VAADIN_SERVER_BUNDLE.equals(bundle.getSymbolicName()) ?
bundle : null;
}
@Override
public void modifiedBundle(Bundle bundle, BundleEvent event, Bundle object) {
}
@Override
public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) {
}
});
this.vaadinResourceBundles.open();
}
示例7: bundleChanged
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
/**
* A bundle has been started, stopped, resolved, or unresolved. This method is a synchronous callback, do not do
* any long-running work in this thread.
*
* @see org.osgi.framework.SynchronousBundleListener#bundleChanged
*/
public void bundleChanged(BundleEvent event) {
boolean trace = log.isTraceEnabled();
// check if the listener is still alive
if (isClosed) {
if (trace)
log.trace("Listener is closed; events are being ignored");
return;
}
if (trace) {
log.trace("Processing bundle event [" + OsgiStringUtils.nullSafeToString(event) + "] for bundle ["
+ OsgiStringUtils.nullSafeSymbolicName(event.getBundle()) + "]");
}
try {
handleEvent(event);
} catch (Exception ex) {
/* log exceptions before swallowing */
log.warn("Got exception while handling event " + event, ex);
}
}
示例8: removedBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
@Override
@SuppressWarnings("IllegalCatch")
public void removedBundle(final Bundle bundle, final BundleEvent event,
final Collection<ObjectRegistration<YangModuleInfo>> regs) {
if (regs == null) {
return;
}
for (ObjectRegistration<YangModuleInfo> reg : regs) {
try {
reg.close();
} catch (final Exception e) {
LOG.error("Unable to unregister YangModuleInfo {}", reg.getInstance(), e);
}
}
}
示例9: addingBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
@Override
public Boolean addingBundle(final Bundle bundle, final BundleEvent event) {
URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}", bundle, resource, event);
if (resource != null) {
try {
for (String factoryClassName : Resources.readLines(resource, StandardCharsets.UTF_8)) {
registerFactory(factoryClassName, bundle);
}
return Boolean.TRUE;
} catch (final IOException e) {
LOG.error("Error while reading {}", resource, e);
throw new RuntimeException(e);
}
}
return Boolean.FALSE;
}
示例10: removedBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
@Override
public void removedBundle(final Bundle bundle, final BundleEvent event, final Future<T> object) {
if (!object.isDone() && object.cancel(false)) {
// We canceled adding event before it was processed
// so it is safe to return
LOG.trace("Adding Bundle event for {} was cancelled. No additional work required.", bundle);
return;
}
try {
LOG.trace("Invoking removedBundle event for {}", bundle);
primaryTracker.removedBundle(bundle, event, object.get());
forEachAdditionalBundle(tracker -> tracker.removedBundle(bundle, event, null));
LOG.trace("Removed bundle event for {} finished successfully.", bundle);
} catch (final ExecutionException | InterruptedException e) {
LOG.error("Failed to remove bundle {}", bundle, e);
}
}
示例11: modifiedBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
/**
* Implemented from BundleTrackerCustomizer.
*/
@Override
public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Bundle object) {
if (shuttingDown) {
return;
}
if (bundle.getState() == Bundle.ACTIVE) {
List<Object> paths = findBlueprintPaths(bundle);
if (!paths.isEmpty()) {
LOG.info("Creating blueprint container for bundle {} with paths {}", bundle, paths);
blueprintExtenderService.createContainer(bundle, paths);
}
}
}
示例12: BundleImpl
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
BundleImpl(File file) throws Exception {
long currentTimeMillis = System.currentTimeMillis();
DataInputStream dataInputStream = new DataInputStream(new FileInputStream(new File(file, "meta")));
this.location = dataInputStream.readUTF();
this.currentStartlevel = dataInputStream.readInt();
this.persistently = dataInputStream.readBoolean();
dataInputStream.close();
this.bundleDir = file;
this.state = BundleEvent.STARTED;
try {
this.archive = new BundleArchive(this.location, file);
resolveBundle(false);
Framework.bundles.put(this.location, this);
Framework.notifyBundleListeners(BundleEvent.INSTALLED, this);
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " loaded. " + (System.currentTimeMillis() - currentTimeMillis) + " ms");
}
} catch (Exception e) {
throw new BundleException("Could not load bundle " + this.location, e.getCause());
}
}
示例13: startBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
public synchronized void startBundle() throws BundleException {
if (this.state == BundleEvent.INSTALLED) {
throw new IllegalStateException("Cannot start uninstalled bundle "
+ toString());
} else if (this.state != BundleEvent.RESOLVED) {
if (this.state == BundleEvent.STARTED) {
resolveBundle(true);
}
this.state = BundleEvent.UPDATED;
try {
isValid = true;
this.state = BundleEvent.RESOLVED;
Framework.notifyBundleListeners(BundleEvent.STARTED, this);
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " started.");
}
} catch (Throwable th) {
Framework.clearBundleTrace(this);
this.state = BundleEvent.STOPPED;
String msg = "Error starting bundle " + toString();
log.error(msg,th);
}
}
}
示例14: stopBundle
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
public synchronized void stopBundle() throws BundleException {
if (this.state == BundleEvent.INSTALLED) {
throw new IllegalStateException("Cannot stop uninstalled bundle "
+ toString());
} else if (this.state == BundleEvent.RESOLVED) {
this.state = BundleEvent.UNINSTALLED;
try {
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " stopped.");
}
Framework.clearBundleTrace(this);
this.state = BundleEvent.STOPPED;
Framework.notifyBundleListeners(BundleEvent.STOPPED, this);
isValid = false;
} catch (Throwable th) {
Framework.clearBundleTrace(this);
this.state = BundleEvent.STOPPED;
Framework.notifyBundleListeners(BundleEvent.STOPPED, this);
isValid = false;
}
}
}
示例15: uninstall
import org.osgi.framework.BundleEvent; //导入依赖的package包/类
@Override
public synchronized void uninstall() throws BundleException {
if (this.state == BundleEvent.INSTALLED) {
throw new IllegalStateException("Bundle " + toString() + " is already uninstalled.");
}
if (this.state == BundleEvent.RESOLVED) {
try {
stopBundle();
} catch (Throwable th) {
Framework.notifyFrameworkListeners(BundleEvent.STARTED, this, th);
}
}
this.state = BundleEvent.INSTALLED;
new File(this.bundleDir, "meta").delete();
this.classloader.cleanup(true);
this.classloader = null;
Framework.bundles.remove(this);
Framework.notifyBundleListeners(BundleEvent.UNINSTALLED, this);
isValid = false;
}