Java Code Examples for org.osgi.framework.BundleEvent#STARTED
The following examples show how to use
org.osgi.framework.BundleEvent#STARTED .
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: ManagementPermissionsAdder.java From carbon-identity with Apache License 2.0 | 6 votes |
@Override public void bundleChanged(BundleEvent event) { Bundle bundle = event.getBundle(); try { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); if (event.getType() == BundleEvent.STARTED) { addUIPermissionFromBundle(bundle); } } catch (Exception e) { log.error("Error occured when processing component xml in bundle " + bundle.getSymbolicName(), e); } }
Example 2
Source File: BundleImpl.java From ACDD with MIT License | 6 votes |
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); } } }
Example 3
Source File: SCR.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Process bundle components when it starts. */ public void bundleChanged(BundleEvent event) { postponeCheckin(); try { final Bundle bundle = event.getBundle(); switch (event.getType()) { case BundleEvent.LAZY_ACTIVATION: lazy.add(bundle); processBundle(bundle); break; case BundleEvent.STARTED: if (!lazy.remove(bundle)) { processBundle(bundle); } break; case BundleEvent.STOPPING: lazy.remove(bundle); removeBundle(bundle, ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED); break; } } finally { postponeCheckout(); } }
Example 4
Source File: ManagementPermissionsAdder.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Override public void bundleChanged(BundleEvent event) { Bundle bundle = event.getBundle(); try { PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); if (event.getType() == BundleEvent.STARTED) { addUIPermissionFromBundle(bundle); } } catch (Exception e) { log.error("Error occured when processing component xml in bundle " + bundle.getSymbolicName(), e); } }
Example 5
Source File: Extender.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void bundleChanged(BundleEvent event) { Bundle bundle = event.getBundle(); if (event.getType() == BundleEvent.RESOLVED) { checkBundle(bundle); } else if (event.getType() == BundleEvent.STARTED) { checkBundleScriptEngines(bundle); } }
Example 6
Source File: Framework.java From ACDD with MIT License | 5 votes |
@Override public void setBundleStartLevel(Bundle bundle, int level) { if (bundle == this) { throw new IllegalArgumentException("Cannot set the start level for the system bundle."); } BundleImpl bundleImpl = (BundleImpl) bundle; if (bundleImpl.state == BundleEvent.INSTALLED) { throw new IllegalArgumentException("Bundle " + bundle + " has been uninstalled"); } else if (level <= 0) { throw new IllegalArgumentException("Start level " + level + " is not Component valid level"); } else { bundleImpl.currentStartlevel = level; bundleImpl.updateMetadata(); if (level <= Framework.startlevel && bundle.getState() != BundleEvent.RESOLVED && bundleImpl.persistently) { try { bundleImpl.startBundle(); } catch (Throwable e) { e.printStackTrace(); Framework.notifyFrameworkListeners(BundleEvent.STARTED, bundle, e); } } else if (level <= Framework.startlevel) { } else { if (bundle.getState() != BundleEvent.STOPPED || bundle.getState() != BundleEvent.STARTED) { try { bundleImpl.stopBundle(); } catch (Throwable e2) { Framework.notifyFrameworkListeners(BundleEvent.STARTED, bundle, e2); } } } } }
Example 7
Source File: AutomationResourceBundlesTracker.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private BundleEvent initializeEvent(Bundle bundle) { switch (bundle.getState()) { case Bundle.INSTALLED: return new BundleEvent(BundleEvent.INSTALLED, bundle); case Bundle.RESOLVED: return new BundleEvent(BundleEvent.RESOLVED, bundle); default: return new BundleEvent(BundleEvent.STARTED, bundle); } }
Example 8
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static String bundleEventName(int type) { switch (type) { case BundleEvent.INSTALLED: return "installed"; case BundleEvent.STARTED: return "started"; case BundleEvent.STOPPED: return "stopped"; case BundleEvent.UNINSTALLED: return "uninstalled"; case BundleEvent.UPDATED: return "updated"; case BundleEvent.RESOLVED: return "resolved"; case BundleEvent.UNRESOLVED: return "unresolved"; case BundleEvent.STARTING: return "starting"; case BundleEvent.STOPPING: return "stopping"; case BundleEvent.LAZY_ACTIVATION: return "lazyActivation"; default: return "<" + type + ">"; } }
Example 9
Source File: OSGiActivator.java From sis with Apache License 2.0 | 5 votes |
/** * Invoked when an other module has been installed or un-installed. * This method notifies the Apache SIS library that the classpath may have changed. * * @param event the event that describe the life-cycle change. */ @Override public void bundleChanged(final BundleEvent event) { switch (event.getType()) { case BundleEvent.STARTED: { SystemListener.fireClasspathChanged(); break; } case BundleEvent.STOPPED: { SystemListener.fireClasspathChanged(); SystemListener.removeModule(event.getBundle().getSymbolicName()); break; } } }
Example 10
Source File: LogFrameworkListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * The bundle event callback method inserts all bundle events into the * log. Events are all assigned the log level info. * * @param be * the bundle event that has occured. */ public void bundleChanged(BundleEvent be) { String msg = null; switch (be.getType()) { case BundleEvent.INSTALLED: msg = "BundleEvent INSTALLED"; break; case BundleEvent.STARTED: msg = "BundleEvent STARTED"; break; case BundleEvent.STOPPED: msg = "BundleEvent STOPPED"; break; case BundleEvent.UNINSTALLED: msg = "BundleEvent UNINSTALLED"; break; case BundleEvent.UPDATED: msg = "BundleEvent UPDATED"; break; case BundleEvent.RESOLVED: msg = "BundleEvent RESOLVED"; break; case BundleEvent.UNRESOLVED: msg = "BundleEvent UNRESOLVED"; break; /* case BundleEvent.STARTING: msg = "BundleEvent STARTING"; break; case BundleEvent.STOPPING: msg = "BundleEvent STOPPING"; break; */ } lrsf.log(new LogEntryImpl(be.getBundle(), LogService.LOG_INFO, msg)); }
Example 11
Source File: JRxmlFileBundleListener.java From carbon-commons with Apache License 2.0 | 5 votes |
public void bundleChanged(BundleEvent bundleEvent) { Bundle bundle = bundleEvent.getBundle(); try { if (bundleEvent.getType() == BundleEvent.STARTED) { addJrXmlToRegistry(bundle); } } catch (Exception e) { log.error("Error occurred when putting jrXml file to registry in bundle " + bundle.getSymbolicName(), e); } }
Example 12
Source File: Extender.java From flowable-engine with Apache License 2.0 | 5 votes |
public void bundleChanged(BundleEvent event) { Bundle bundle = event.getBundle(); if (event.getType() == BundleEvent.RESOLVED) { checkBundle(bundle); } else if (event.getType() == BundleEvent.STARTED) { checkBundleScriptEngines(bundle); } }
Example 13
Source File: SiddhiExtensionLoader.java From siddhi with Apache License 2.0 | 5 votes |
@Override public void bundleChanged(BundleEvent bundleEvent) { if (bundleEvent.getType() == BundleEvent.STARTED) { addExtensions(bundleEvent.getBundle()); } else { removeExtensions(bundleEvent.getBundle()); } }
Example 14
Source File: OSGIServiceLoader.java From incubator-tamaya with Apache License 2.0 | 5 votes |
@Override public void bundleChanged(BundleEvent bundleEvent) { // Parse and createObject metadata when installed Bundle bundle = bundleEvent.getBundle(); if (bundleEvent.getType() == BundleEvent.STARTED) { checkAndLoadBundle(bundle); } else if (bundleEvent.getType() == BundleEvent.STOPPED) { checkAndUnloadBundle(bundle); } }
Example 15
Source File: MultiListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * A listener for events sent by bundles * @param bundleEvent The event sent by the bundle * @author Johnny Baveras */ public void bundleChanged(BundleEvent bundleEvent) { String topic = null; boolean knownMessageType = true; switch (bundleEvent.getType()) { case BundleEvent.INSTALLED: topic = INSTALLED_TOPIC; break; case BundleEvent.STARTED: topic = STARTED_TOPIC; break; case BundleEvent.STOPPED: topic = STOPPED_TOPIC; break; case BundleEvent.UPDATED: topic = UPDATED_TOPIC; break; case BundleEvent.UNINSTALLED: topic = UNINSTALLED_TOPIC; break; case BundleEvent.RESOLVED: topic = RESOLVED_TOPIC; break; case BundleEvent.UNRESOLVED: topic = UNRESOLVED_TOPIC; break; default: /* Setting the boolean to false if an unknown event arrives */ knownMessageType = false; break; } /* Stores the properties of the event in the dictionary, if the event is known */ if (knownMessageType) { if(!Activator.handlerTracker.anyHandlersMatching(topic)) { return; } Map<String,Object> props = new HashMap<String,Object>(); Bundle bundle = bundleEvent.getBundle(); putProp(props, EventConstants.EVENT, bundleEvent); putProp(props, "bundle.id", new Long(bundle.getBundleId())); putProp(props, EventConstants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName()); putProp(props, "bundle", bundle); /* Tries posting the event once the properties are set */ try { Activator.eventAdmin.postEvent(new Event(topic, props)); } catch (Exception e) { Activator.log.error("EXCEPTION in bundleChanged()", e); } } else { /* Logs an error if the event, which arrived, were of an unknown type */ Activator.log.error("Recieved unknown bundle event message (type=" +bundleEvent.getType() +"), discarding"); } // } }
Example 16
Source File: BundleLifecycleHandler.java From ACDD with MIT License | 4 votes |
@Override @SuppressLint({"NewApi"}) public void bundleChanged(BundleEvent bundleEvent) { switch (bundleEvent.getType()) { case BundleEvent.LOADED: loaded(bundleEvent.getBundle()); break; case BundleEvent.INSTALLED: installed(bundleEvent.getBundle()); break; case BundleEvent.STARTED: if (isLewaOS()) { if (Looper.myLooper() == null) { Looper.prepare(); } started(bundleEvent.getBundle()); } else if (Framework.isFrameworkStartupShutdown()) { BundleStartTask bundleStartTask = new BundleStartTask(); if (VERSION.SDK_INT > 11) { bundleStartTask.executeOnExecutor( AsyncTask.THREAD_POOL_EXECUTOR, bundleEvent.getBundle()); return; } bundleStartTask .execute(bundleEvent.getBundle()); } else { started(bundleEvent.getBundle()); } break; case BundleEvent.STOPPED: stopped(bundleEvent.getBundle()); break; case BundleEvent.UPDATED: updated(bundleEvent.getBundle()); break; case BundleEvent.UNINSTALLED: { uninstalled(bundleEvent.getBundle()); break; } default: } }
Example 17
Source File: BundleImpl.java From ACDD with MIT License | 4 votes |
BundleImpl(File bundleDir, String location, InputStream archiveInputStream, File archiveFile, boolean isInstall) throws BundleException, IOException { this.persistently = false; this.domain = null; this.registeredFrameworkListeners = null; this.registeredBundleListeners = null; long currentTimeMillis = System.currentTimeMillis(); this.location = location; this.currentStartlevel = Framework.startlevel; this.bundleDir = bundleDir; if (archiveInputStream != null) { // try { this.archive = new BundleArchive(location, bundleDir, archiveInputStream); // } catch (Throwable e) { // Framework.deleteDirectory(bundleDir); // throw new BundleException("Could not install bundle " + location, e); // } } else if (archiveFile != null) { try { this.archive = new BundleArchive(location, bundleDir, archiveFile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } this.state = BundleEvent.STARTED; updateMetadata(); if (isInstall) { Framework.bundles.put(location, this); resolveBundle(false); Framework.notifyBundleListeners(BundleEvent.INSTALLED, this); } if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) { log.info("Framework: Bundle " + toString() + " created. " + (System.currentTimeMillis() - currentTimeMillis) + " ms"); } }
Example 18
Source File: ModelAdapterFactoryUtil.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 4 votes |
/** * Scan classpaths for given package name (and sub packages) to scan for and * register all classes with @Model annotation. */ public static void addModelsForPackage(BundleContext bundleContext, Class... classes) { Bundle bundle = new ModelsPackageBundle(classes, Bundle.ACTIVE, bundleContext); BundleEvent event = new BundleEvent(BundleEvent.STARTED, bundle); MockOsgi.sendBundleEvent(bundleContext, event); }
Example 19
Source File: Netigso.java From netbeans with Apache License 2.0 | 4 votes |
final void notifyBundleChange(final String symbolicName, final Version version, final int action) { final Exception stack = Netigso.LOG.isLoggable(Level.FINER) ? new Exception("StackTrace") : null; final Runnable doLog = new Runnable() { @Override public void run() { if (isEnabled(symbolicName)) { return; } final Mutex mutex = Main.getModuleSystem().getManager().mutex(); if (!mutex.isReadAccess()) { mutex.postReadRequest(this); return; } String type = "" + action; Level notify = Level.INFO; switch (action) { case BundleEvent.INSTALLED: return; // no message for installed case BundleEvent.RESOLVED: type = "resolved"; break; case BundleEvent.STARTED: type = "started"; break; case BundleEvent.STOPPED: type = "stopped"; break; case BundleEvent.UNINSTALLED: return; // nothing for uninstalled case BundleEvent.LAZY_ACTIVATION: type = "lazy"; notify = Level.FINEST; break; case BundleEvent.STARTING: type = "starting"; notify = Level.FINEST; break; } Netigso.LOG.log(notify, "bundle {0}@{2} {1}", new Object[]{ symbolicName, type, version }); if (stack != null) { Netigso.LOG.log(Level.FINER, null, stack); } } }; RP.post(doLog); }
Example 20
Source File: BundleCheckActivator.java From micro-integrator with Apache License 2.0 | 4 votes |
public void start(final BundleContext bundleContext) throws Exception { /* * Check for the services that should be deployed before this if there * are any. * if there are such services we wait for such bundles to deploy and * gets the notification * through a service listener. */ // first check whether there are such services and they have already // deployed. String pendingBundleName = null; final List<Bundle> pendingBundles = new ArrayList<Bundle>(); for (Bundle bundle : bundleContext.getBundles()) { pendingBundleName = (String) bundle.getHeaders().get(DEPLOY_BEFORE); if ((pendingBundleName != null) && (pendingBundleName.equals(getName())) && (bundle.getState() != Bundle.ACTIVE)) { // i.e this bundle should be started before the user manager but // yet has not started pendingBundles.add(bundle); } } if (pendingBundles.isEmpty()) { startDeploy(bundleContext); } else { BundleListener bundleListener = new BundleListener() { public void bundleChanged(BundleEvent bundleEvent) { synchronized (pendingBundles) { if (bundleEvent.getType() == BundleEvent.STARTED) { pendingBundles.remove(bundleEvent.getBundle()); if (pendingBundles.isEmpty()) { // now start the user manager deployment bundleContext.removeBundleListener(this); try { startDeploy(bundleContext); } catch (Exception e) { log.error("Can not start the bundle ", e); } } } } } }; bundleContext.addBundleListener(bundleListener); } }