?? oscar.java
字號:
// Set the start level to zero in order to stop // all bundles in the framework. setStartLevelInternal(0); // Just like initialize() called the system bundle's start() // method, we must call its stop() method here so that it // can perform any necessary clean up. try { getBundle(0).stop(); } catch (Exception ex) { fireFrameworkEvent(FrameworkEvent.ERROR, getBundle(0), ex); Oscar.error("Error stopping system bundle.", ex); } // Loop through all bundles and update any updated bundles. Bundle[] bundles = getBundles(); for (int i = 0; i < bundles.length; i++) { BundleImpl bundle = (BundleImpl) bundles[i]; if (bundle.getInfo().isRemovalPending()) { try { purgeBundle(bundle); } catch (Exception ex) { fireFrameworkEvent(FrameworkEvent.ERROR, bundle, ex); Oscar.error("Oscar: Unable to purge bundle " + bundle.getInfo().getLocation()); } } } // Remove any uninstalled bundles. for (int i = 0; (m_uninstalledBundles != null) && (i < m_uninstalledBundles.length); i++) { try { removeBundle(m_uninstalledBundles[i]); } catch (Exception ex) { Oscar.error("Oscar: Unable to remove " + m_uninstalledBundles[i].getInfo().getLocation()); } } // Shutdown event dispatching queue. DispatchQueue.shutdown(); // Oscar is no longer in a usable state. m_oscarStatus = UNKNOWN_STATUS; } /** * Returns the active start level of the framework; this method * implements functionality for the Start Level service. * @return the active start level of the framework. **/ protected int getStartLevel() { return m_activeStartLevel; } /** * Implements the functionality of the <tt>setStartLevel()</tt> * method for the StartLevel service, but does not do the security or * parameter check. The security and parameter check are done in the * StartLevel service implementation because this method is called on * a separate thread and the caller's thread would already be gone if * we did the checks in this method. * @param requestedLevel the new start level of the framework. **/ protected void setStartLevelInternal(int requestedLevel) { // Determine if we are lowering or raising the // active start level. boolean lowering = (requestedLevel < m_activeStartLevel); // Record new start level. m_activeStartLevel = requestedLevel; // Get exclusion lock to make sure that no one starts // an operation that might affect the bundle list. synchronized (m_adminLock) { // Get array of all installed bundles. Bundle[] bundles = getBundles(); // Sort bundle array by start level either ascending or // descending depending on whether the start level is being // lowered or raised. Comparator comparator = null; if (lowering) { // Sort descending to stop highest start level first. comparator = new Comparator() { public int compare(Object o1, Object o2) { BundleImpl b1 = (BundleImpl) o1; BundleImpl b2 = (BundleImpl) o2; if (b1.getInfo().getStartLevel(getInitialBundleStartLevel()) < b2.getInfo().getStartLevel(getInitialBundleStartLevel())) { return 1; } else if (b1.getInfo().getStartLevel(getInitialBundleStartLevel()) > b2.getInfo().getStartLevel(getInitialBundleStartLevel())) { return -1; } return 0; } }; } else { // Sort ascending to start lowest start level first. comparator = new Comparator() { public int compare(Object o1, Object o2) { BundleImpl b1 = (BundleImpl) o1; BundleImpl b2 = (BundleImpl) o2; if (b1.getInfo().getStartLevel(getInitialBundleStartLevel()) > b2.getInfo().getStartLevel(getInitialBundleStartLevel())) { return 1; } else if (b1.getInfo().getStartLevel(getInitialBundleStartLevel()) < b2.getInfo().getStartLevel(getInitialBundleStartLevel())) { return -1; } return 0; } }; } Arrays.sort(bundles, comparator); // Stop or start the bundles according to the start level. for (int i = 0; (bundles != null) && (i < bundles.length); i++) { BundleImpl impl = (BundleImpl) bundles[i]; // Ignore the system bundle, since its start() and // stop() methods get called explicitly in initialize() // and shutdown(), respectively. if (impl.getInfo().getBundleId() == 0) { continue; } // Start or stop bundle accordingly. if (impl.getInfo().getStartLevel(getInitialBundleStartLevel()) <= m_activeStartLevel) { try { startBundleWithStartLevel(impl); } catch (Throwable th) {th.printStackTrace(); fireFrameworkEvent(FrameworkEvent.ERROR, impl, th); Oscar.error("Oscar: Error starting " + impl.getInfo().getLocation()); } } else if (impl.getInfo().getStartLevel(getInitialBundleStartLevel()) > m_activeStartLevel) { try { stopBundleWithStartLevel(impl); } catch (Throwable th) { fireFrameworkEvent(FrameworkEvent.ERROR, impl, th); Oscar.error("Oscar: Error stopping " + impl.getInfo().getLocation()); } } } } fireFrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, getBundle(0), null); } /** * Returns the start level into which newly installed bundles will * be placed by default; this method implements functionality for * the Start Level service. * @return the default start level for newly installed bundles. **/ protected int getInitialBundleStartLevel() { String s = getConfigProperty(OscarConstants.BUNDLE_STARTLEVEL_PROP); if (s != null) { try { return Integer.parseInt(s); } catch (NumberFormatException ex) { // Ignore and return the default value. } } return OscarConstants.BUNDLE_DEFAULT_STARTLEVEL; } /** * Sets the default start level into which newly installed bundles * will be placed; this method implements functionality for the Start * Level service. * @param startLevel the new default start level for newly installed * bundles. * @throws java.lang.IllegalArgumentException if the specified start * level is not greater than zero. * @throws java.security.SecurityException if the caller does not * have <tt>AdminPermission</tt>. **/ protected void setInitialBundleStartLevel(int startLevel) { if (System.getSecurityManager() != null) { AccessController.checkPermission(m_adminPerm); } if (startLevel <= 0) { throw new IllegalArgumentException( "Initial start level must be greater than zero."); } setConfigProperty( OscarConstants.BUNDLE_STARTLEVEL_PROP, Integer.toString(startLevel)); } /** * Returns the start level for the specified bundle; this method * implements functionality for the Start Level service. * @param bundle the bundle to examine. * @return the start level of the specified bundle. * @throws java.lang.IllegalArgumentException if the specified * bundle has been uninstalled. **/ protected int getBundleStartLevel(Bundle bundle) { if (bundle.getState() == Bundle.UNINSTALLED) { throw new IllegalArgumentException("Bundle is uninstalled."); } return ((BundleImpl) bundle).getInfo().getStartLevel(getInitialBundleStartLevel()); } /** * Sets the start level of the specified bundle; this method * implements functionality for the Start Level service. * @param bundle the bundle whose start level is to be modified. * @param startLevel the new start level of the specified bundle. * @throws java.lang.IllegalArgumentException if the specified * bundle is the system bundle or if the bundle has been * uninstalled. * @throws java.security.SecurityException if the caller does not * have <tt>AdminPermission</tt>. **/ protected void setBundleStartLevel(Bundle bundle, int startLevel) { if (System.getSecurityManager() != null) { AccessController.checkPermission(m_adminPerm); } // Cannot change the system bundle. if (bundle.getBundleId() == 0) { throw new IllegalArgumentException( "Cannot change system bundle start level."); } else if (bundle.getState() == Bundle.UNINSTALLED) { throw new IllegalArgumentException("Bundle is uninstalled."); } if (startLevel >= 1) { BundleImpl impl = (BundleImpl) bundle; impl.getInfo().setStartLevel(startLevel); try { m_cache.getArchive(impl.getBundleId()).setStartLevel(startLevel); } catch (Exception ex) { Oscar.error("Unable to save start level.", ex); } try { // Start or stop the bundle if necessary. if (impl.getInfo().getStartLevel(getInitialBundleStartLevel()) <= getStartLevel()) { startBundleWithStartLevel(impl); } else { stopBundleWithStartLevel(impl); } } catch (Throwable th) { fireFrameworkEvent(FrameworkEvent.ERROR, impl, th); Oscar.error("Error starting/stopping bundle.", th); } } } /** * Returns whether a bundle is persistently started; this is an * method implementation for the Start Level service. * @param bundle the bundle to examine. * @return <tt>true</tt> if the bundle is marked as persistently * started, <tt>false</tt> otherwise. * @throws java.lang.IllegalArgumentException if the specified
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -