Class Felix

All Implemented Interfaces:
Comparable<Bundle>, Bundle, BundleReference, Framework, BundleRevisions

public class Felix extends BundleImpl implements Framework
  • Field Details

    • m_secureAction

      static final SecureAction m_secureAction
    • m_extensionManager

      private final ExtensionManager m_extensionManager
    • m_fwkWiring

      private final FrameworkWiringImpl m_fwkWiring
    • m_fwkStartLevel

      private final FrameworkStartLevelImpl m_fwkStartLevel
    • m_logger

      private final Logger m_logger
    • m_configMap

      private final Map m_configMap
    • m_configMutableMap

      private final Map m_configMutableMap
    • m_resolver

      private final StatefulResolver m_resolver
    • m_bundleLock

      private final Object[] m_bundleLock
    • m_globalLockWaitersList

      private final List m_globalLockWaitersList
    • m_globalLockThread

      private Thread m_globalLockThread
    • m_globalLockCount

      private int m_globalLockCount
    • m_installRequestMap

      private final Map m_installRequestMap
    • m_installRequestLock_Priority1

      private final Object[] m_installRequestLock_Priority1
    • m_installedBundles

      private volatile Map[] m_installedBundles
    • LOCATION_MAP_IDX

      private static final int LOCATION_MAP_IDX
      See Also:
    • IDENTIFIER_MAP_IDX

      private static final int IDENTIFIER_MAP_IDX
      See Also:
    • m_uninstalledBundles

      private volatile List<BundleImpl> m_uninstalledBundles
    • m_dependencies

      private final BundleRevisionDependencies m_dependencies
    • m_activeStartLevel

      private volatile int m_activeStartLevel
    • m_targetStartLevel

      private volatile int m_targetStartLevel
    • m_startLevelBundles

      private final SortedSet<Felix.StartLevelTuple> m_startLevelBundles
    • m_cache

      private BundleCache m_cache
    • m_activatorList

      List m_activatorList
    • m_nextId

      private long m_nextId
    • m_nextIdLock

      private final Object m_nextIdLock
    • m_registry

      private final ServiceRegistry m_registry
    • m_dispatcher

      private final EventDispatcher m_dispatcher
    • m_bundleStreamHandler

      private final URLStreamHandler m_bundleStreamHandler
    • m_bootPkgs

      private final String[] m_bootPkgs
    • m_bootPkgWildcards

      private final boolean[] m_bootPkgWildcards
    • m_shutdownGate

      private volatile ThreadGate m_shutdownGate
    • m_securityManager

      private SecurityManager m_securityManager
    • m_securityDefaultPolicy

      private volatile boolean m_securityDefaultPolicy
    • m_systemBundleClassCache

      private final Map<Class,Boolean> m_systemBundleClassCache
    • m_securityProvider

      private volatile SecurityProvider m_securityProvider
    • m_urlHandlersActivator

      private volatile URLHandlersActivator m_urlHandlersActivator
  • Constructor Details

    • Felix

      public Felix(Map configMap)

      This constructor creates a framework instance with a specified Map of configuration properties. Configuration properties are used internally by the framework to alter its default behavior. The configuration properties should have a String key and an Object value. The passed in Map is copied by the framework and all keys are converted to Strings.

      Configuration properties are generally the sole means to configure the framework's default behavior; the framework does not typically refer to any system properties for configuration information. If a Map is supplied to this method for configuration properties, then the framework will consult the Map instance for any and all configuration properties. It is possible to specify a null for the configuration property map, in which case the framework will use its default behavior in all cases.

      The following configuration properties can be specified (properties starting with "felix" are specific to Felix, while those starting with "org.osgi" are standard OSGi properties):

      • org.osgi.framework.storage - Sets the directory to use as the bundle cache; by default bundle cache directory is felix-cache in the current working directory. The value should be a valid directory name. The directory name can be either absolute or relative. Relative directory names are relative to the current working directory. The specified directory will be created if it does not exist.
      • org.osgi.framework.storage.clean - Determines whether the bundle cache is flushed. The value can either be "none" or "onFirstInit", where "none" does not flush the bundle cache and "onFirstInit" flushes the bundle cache when the framework instance is first initialized. The default value is "none".
      • felix.cache.rootdir - Sets the root directory to use to calculate the bundle cache directory for relative directory names. If org.osgi.framework.storage is set to a relative name, by default it is relative to the current working directory. If this property is set, then it will be calculated as being relative to the specified root directory.
      • felix.cache.filelimit - The integer value of this string sets an upper limit on how many files the cache will open. The default value is zero, which means there is no limit.
      • felix.cache.locking - Enables or disables bundle cache locking, which is used to prevent concurrent access to the bundle cache. This is enabled by default, but on older/smaller JVMs file channel locking is not available; set this property to false to disable it.
      • felix.cache.bufsize - Sets the buffer size to be used by the cache; the default value is 4096. The integer value of this string provides control over the size of the internal buffer of the disk cache for performance reasons.
      • org.osgi.framework.system.packages - Specifies a comma-delimited list of packages that should be exported via the System Bundle from the parent class loader. The framework will set this to a reasonable default. If the value is specified, it replaces any default value.
      • org.osgi.framework.system.packages.extra - Specifies a comma-delimited list of packages that should be exported via the System Bundle from the parent class loader in addition to the packages in org.osgi.framework.system.packages. The default value is empty. If a value is specified, it is appended to the list of default or specified packages in org.osgi.framework.system.packages.
      • org.osgi.framework.bootdelegation - Specifies a comma-delimited list of packages that should be made implicitly available to all bundles from the parent class loader. It is recommended not to use this property since it breaks modularity. The default value is empty.
      • felix.systembundle.activators - A List of BundleActivator instances that are started/stopped when the System Bundle is started/stopped. The specified instances will receive the System Bundle's BundleContext when invoked.
      • felix.log.logger - An instance of Logger that the framework uses as its default logger.
      • felix.log.level - An integer value indicating the degree of logging reported by the framework; the higher the value the more logging is reported. If zero ('0') is specified, then logging is turned off completely. The log levels match those specified in the OSGi Log Service (i.e., 1 = error, 2 = warning, 3 = information, and 4 = debug). The default value is 1.
      • org.osgi.framework.startlevel.beginning - The initial start level of the framework once it starts execution; the default value is 1.
      • felix.startlevel.bundle - The default start level for newly installed bundles; the default value is 1.
      • felix.service.urlhandlers - Flag to indicate whether to activate the URL Handlers service for the framework instance; the default value is "true". Activating the URL Handlers service will result in the URL.setURLStreamHandlerFactory() and URLConnection.setContentHandlerFactory() being called.
      • felix.fragment.validation - Determines if installing unsupported fragment bundles throws an exception or logs a warning. Possible values are "exception" or "warning". The default value is "exception".
      • felix.security.defaultpolicy - Flag to indicate whether to consult the default java securtiy policy if no security extension is present. The default value is "false".

      The Main class implements some functionality for default property file handling, which makes it possible to specify configuration properties and framework properties in files that are automatically loaded when starting the framework. If you plan to create your own framework instance, you may be able to take advantage of the features it provides; refer to its class documentation for more information.

      The framework is not actually started until the start() method is called.

      Parameters:
      configMap - A map for obtaining configuration properties, may be null.
  • Method Details

    • getLogger

      Logger getLogger()
    • getConfig

      Map getConfig()
    • getResolver

      StatefulResolver getResolver()
    • getDependencies

      BundleRevisionDependencies getDependencies()
    • getBundleStreamHandler

      URLStreamHandler getBundleStreamHandler()
    • getBootPackages

      String[] getBootPackages()
    • getBootPackageWildcards

      boolean[] getBootPackageWildcards()
    • createUnmodifiableMap

      private Map createUnmodifiableMap(Map mutableMap)
    • close

      void close()
      Overrides:
      close in class BundleImpl
    • getFramework

      Felix getFramework()
      Overrides:
      getFramework in class BundleImpl
    • adapt

      public <A> A adapt(Class<A> type)
      Description copied from interface: Bundle
      Adapt this bundle to the specified type.

      Adapting this bundle to the specified type may require certain checks, including security checks, to succeed. If a check does not succeed, then this bundle cannot be adapted and null is returned.

      Specified by:
      adapt in interface Bundle
      Specified by:
      adapt in interface Framework
      Overrides:
      adapt in class BundleImpl
      Type Parameters:
      A - The type to which this bundle is to be adapted.
      Parameters:
      type - Class object for the type to which this bundle is to be adapted.
      Returns:
      The object, of the specified type, to which this bundle has been adapted or null if this bundle cannot be adapted to the specified type.
    • getBundleId

      public long getBundleId()
      Description copied from interface: Bundle
      Returns this bundle's unique identifier. This bundle is assigned a unique identifier by the Framework when it was installed in the OSGi environment.

      A bundle's unique identifier has the following attributes:

      • Is unique and persistent.
      • Is a long.
      • Its value is not reused for another bundle, even after a bundle is uninstalled.
      • Does not change while a bundle remains installed.
      • Does not change when a bundle is updated.

      This method must continue to return this bundle's unique identifier while this bundle is in the UNINSTALLED state.

      Specified by:
      getBundleId in interface Bundle
      Specified by:
      getBundleId in interface Framework
      Overrides:
      getBundleId in class BundleImpl
      Returns:
      The unique identifier of this bundle.
      See Also:
    • getLastModified

      public long getLastModified()
      Description copied from interface: Bundle
      Returns the time when this bundle was last modified. A bundle is considered to be modified when it is installed, updated or uninstalled.

      The time value is the number of milliseconds since January 1, 1970, 00:00:00 UTC.

      Specified by:
      getLastModified in interface Bundle
      Specified by:
      getLastModified in interface Framework
      Overrides:
      getLastModified in class BundleImpl
      Returns:
      The time when this bundle was last modified.
    • setLastModified

      void setLastModified(long l)
      Overrides:
      setLastModified in class BundleImpl
    • _getLocation

      String _getLocation()
      Overrides:
      _getLocation in class BundleImpl
    • getPersistentState

      public int getPersistentState()
      Overrides:
      getPersistentState in class BundleImpl
    • setPersistentStateInactive

      public void setPersistentStateInactive()
      Overrides:
      setPersistentStateInactive in class BundleImpl
    • setPersistentStateActive

      public void setPersistentStateActive()
      Overrides:
      setPersistentStateActive in class BundleImpl
    • setPersistentStateUninstalled

      public void setPersistentStateUninstalled()
      Overrides:
      setPersistentStateUninstalled in class BundleImpl
    • getStartLevel

      int getStartLevel(int defaultLevel)
      Overrides standard BundleImpl.getStartLevel() behavior to always return zero for the system bundle.
      Overrides:
      getStartLevel in class BundleImpl
      Parameters:
      defaultLevel - This parameter is ignored by the system bundle.
      Returns:
      Always returns zero.
    • setStartLevel

      void setStartLevel(int level)
      Overrides standard BundleImpl.setStartLevel() behavior to always throw an exception since the system bundle's start level cannot be changed.
      Overrides:
      setStartLevel in class BundleImpl
      Parameters:
      level - This parameter is ignored by the system bundle.
      Throws:
      IllegalArgumentException - Always throws exception since system bundle's start level cannot be changed.
    • hasPermission

      public boolean hasPermission(Object obj)
      Description copied from interface: Bundle
      Determines if this bundle has the specified permissions.

      If the Java Runtime Environment does not support permissions, this method always returns true.

      permission is of type Object to avoid referencing the java.security.Permission class directly. This is to allow the Framework to be implemented in Java environments which do not support permissions.

      If the Java Runtime Environment does support permissions, this bundle and all its resources including embedded JAR files, belong to the same java.security.ProtectionDomain; that is, they must share the same set of permissions.

      Specified by:
      hasPermission in interface Bundle
      Overrides:
      hasPermission in class BundleImpl
      Parameters:
      obj - The permission to verify.
      Returns:
      true if this bundle has the specified permission or the permissions possessed by this bundle imply the specified permission; false if this bundle does not have the specified permission or permission is not an instanceof java.security.Permission.
    • init

      public void init() throws BundleException
      Description copied from interface: Framework
      Initialize this Framework.

      This method performs the same function as calling Framework.init(FrameworkListener...) with no framework listeners.

      Specified by:
      init in interface Framework
      Throws:
      BundleException - If this Framework could not be initialized.
      See Also:
    • init

      public void init(FrameworkListener... listeners) throws BundleException
      Description copied from interface: Framework
      Initialize this Framework. After calling this method, this Framework must:
      • Have generated a new framework UUID.
      • Be in the Bundle.STARTING state.
      • Have a valid Bundle Context.
      • Be at start level 0.
      • Have event handling enabled.
      • Have reified Bundle objects for all installed bundles.
      • Have registered any framework services. For example, ConditionalPermissionAdmin.
      • Be adaptable to the OSGi defined types to which a system bundle can be adapted.
      • Have called the start method of the extension bundle activator for all resolved extension bundles.

      This Framework will not actually be started until start is called.

      This method does nothing if called when this Framework is in the Bundle.STARTING, Bundle.ACTIVE or Bundle.STOPPING states.

      All framework events fired by this method method are also delivered to the specified FrameworkListeners in the order they are specified before returning from this method. After returning from this method the specified listeners are no longer notified of framework events.

      Specified by:
      init in interface Framework
      Parameters:
      listeners - Zero or more listeners to be notified when framework events occur while initializing the framework. The specified listeners do not need to be otherwise registered with the framework. If a specified listener is registered with the framework, it will be notified twice for each framework event.
      Throws:
      BundleException - If this Framework could not be initialized.
      See Also:
    • setBundleProtectionDomain

      void setBundleProtectionDomain(BundleImpl bundleImpl, BundleRevisionImpl revisionImpl) throws Exception
      Throws:
      Exception
    • start

      public void start() throws BundleException
      This method starts the framework instance, which will transition the framework from start level 0 to its active start level as specified in its configuration properties (1 by default). If the init() was not explicitly invoked before calling this method, then it will be implicitly invoked before starting the framework.
      Specified by:
      start in interface Bundle
      Specified by:
      start in interface Framework
      Overrides:
      start in class BundleImpl
      Throws:
      BundleException - if any error occurs.
      See Also:
    • start

      public void start(int options) throws BundleException
      Description copied from interface: Bundle
      Starts this bundle.

      If this bundle's state is UNINSTALLED then an IllegalStateException is thrown.

      If the current start level is less than this bundle's start level:

      • If the Bundle.START_TRANSIENT option is set, then a BundleException is thrown indicating this bundle cannot be started due to the Framework's current start level.
      • Otherwise, the Framework must set this bundle's persistent autostart setting to Started with declared activation if the Bundle.START_ACTIVATION_POLICY option is set or Started with eager activation if not set.

      When the Framework's current start level becomes equal to or more than this bundle's start level, this bundle will be started.

      Otherwise, the following steps are required to start this bundle:

      1. If this bundle is in the process of being activated or deactivated then this method must wait for activation or deactivation to complete before continuing. If this does not occur in a reasonable time, a BundleException is thrown to indicate this bundle was unable to be started.
      2. If the Bundle.START_TRANSIENT option is not set then set this bundle's autostart setting to Started with declared activation if the Bundle.START_ACTIVATION_POLICY option is set or Started with eager activation if not set. When the Framework is restarted and this bundle's autostart setting is not Stopped, this bundle must be automatically started.
      3. If this bundle's state is ACTIVE then this method returns immediately.
      4. If this bundle's state is not RESOLVED, an attempt is made to resolve this bundle. If the Framework cannot resolve this bundle, a BundleException is thrown.
      5. If the Bundle.START_ACTIVATION_POLICY option is set and this bundle's declared activation policy is lazy then:
        • If this bundle's state is STARTING then this method returns immediately.
        • This bundle's state is set to STARTING.
        • A bundle event of type BundleEvent.LAZY_ACTIVATION is fired.
        • This method returns immediately and the remaining steps will be followed when this bundle's activation is later triggered.
      6. This bundle's state is set to STARTING.
      7. A bundle event of type BundleEvent.STARTING is fired.
      8. The BundleActivator.start(BundleContext) method of this bundle's BundleActivator, if one is specified, is called. If the BundleActivator is invalid or throws an exception then:
        • This bundle's state is set to STOPPING.
        • A bundle event of type BundleEvent.STOPPING is fired.
        • Any services registered by this bundle must be unregistered.
        • Any services used by this bundle must be released.
        • Any listeners registered by this bundle must be removed.
        • This bundle's state is set to RESOLVED.
        • A bundle event of type BundleEvent.STOPPED is fired.
        • A BundleException is then thrown.
      9. This bundle's state is set to ACTIVE.
      10. A bundle event of type BundleEvent.STARTED is fired.
      Preconditions
      • getState() in { INSTALLED, RESOLVED } or { INSTALLED, RESOLVED, STARTING } if this bundle has a lazy activation policy.
      Postconditions, no exceptions thrown
      • Bundle autostart setting is modified unless the Bundle.START_TRANSIENT option was set.
      • getState() in { ACTIVE } unless the lazy activation policy was used.
      • BundleActivator.start() has been called and did not throw an exception unless the lazy activation policy was used.
      Postconditions, when an exception is thrown
      • Depending on when the exception occurred, bundle autostart setting is modified unless the Bundle.START_TRANSIENT option was set.
      • getState() not in { STARTING, ACTIVE }.
      Specified by:
      start in interface Bundle
      Specified by:
      start in interface Framework
      Overrides:
      start in class BundleImpl
      Parameters:
      options - The options for starting this bundle. See Bundle.START_TRANSIENT and Bundle.START_ACTIVATION_POLICY. The Framework must ignore unrecognized options.
      Throws:
      BundleException - If this bundle could not be started. BundleException types thrown by this method include: BundleException.START_TRANSIENT_ERROR, BundleException.NATIVECODE_ERROR, BundleException.RESOLVE_ERROR, BundleException.STATECHANGE_ERROR, and BundleException.ACTIVATOR_ERROR.
      See Also:
    • stop

      public void stop() throws BundleException
      This method asynchronously shuts down the framework, it must be called at the end of a session in order to shutdown all active bundles.
      Specified by:
      stop in interface Bundle
      Specified by:
      stop in interface Framework
      Overrides:
      stop in class BundleImpl
      Throws:
      BundleException - BundleException types thrown by this method include: BundleException.STATECHANGE_ERROR and BundleException.ACTIVATOR_ERROR.
      See Also:
    • stop

      public void stop(int options) throws BundleException
      Description copied from interface: Bundle
      Stops this bundle.

      The following steps are required to stop a bundle:

      1. If this bundle's state is UNINSTALLED then an IllegalStateException is thrown.
      2. If this bundle is in the process of being activated or deactivated then this method must wait for activation or deactivation to complete before continuing. If this does not occur in a reasonable time, a BundleException is thrown to indicate this bundle was unable to be stopped.
      3. If the Bundle.STOP_TRANSIENT option is not set then then set this bundle's persistent autostart setting to to Stopped. When the Framework is restarted and this bundle's autostart setting is Stopped, this bundle must not be automatically started.
      4. If this bundle's state is not STARTING or ACTIVE then this method returns immediately.
      5. This bundle's state is set to STOPPING.
      6. A bundle event of type BundleEvent.STOPPING is fired.
      7. If this bundle's state was ACTIVE prior to setting the state to STOPPING, the BundleActivator.stop(BundleContext) method of this bundle's BundleActivator, if one is specified, is called. If that method throws an exception, this method must continue to stop this bundle and a BundleException must be thrown after completion of the remaining steps.
      8. Any services registered by this bundle must be unregistered.
      9. Any services used by this bundle must be released.
      10. Any listeners registered by this bundle must be removed.
      11. If this bundle's state is UNINSTALLED, because this bundle was uninstalled while the BundleActivator.stop method was running, a BundleException must be thrown.
      12. This bundle's state is set to RESOLVED.
      13. A bundle event of type BundleEvent.STOPPED is fired.
      Preconditions
      • getState() in { ACTIVE }.
      Postconditions, no exceptions thrown
      • Bundle autostart setting is modified unless the Bundle.STOP_TRANSIENT option was set.
      • getState() not in { ACTIVE, STOPPING }.
      • BundleActivator.stop has been called and did not throw an exception.
      Postconditions, when an exception is thrown
      Specified by:
      stop in interface Bundle
      Specified by:
      stop in interface Framework
      Overrides:
      stop in class BundleImpl
      Parameters:
      options - The options for stopping this bundle. See Bundle.STOP_TRANSIENT. The Framework must ignore unrecognized options.
      Throws:
      BundleException - BundleException types thrown by this method include: BundleException.STATECHANGE_ERROR and BundleException.ACTIVATOR_ERROR.
      See Also:
    • waitForStop

      public FrameworkEvent waitForStop(long timeout) throws InterruptedException
      This method will cause the calling thread to block until the framework shuts down.
      Specified by:
      waitForStop in interface Framework
      Parameters:
      timeout - A timeout value.
      Returns:
      A Framework Event indicating the reason this method returned. The following FrameworkEvent types may be returned by this method.
      • STOPPED - This Framework has been stopped.
      • STOPPED_UPDATE - This Framework has been updated which has shutdown and will now restart.
      • STOPPED_BOOTCLASSPATH_MODIFIED - This Framework has been stopped and a bootclasspath extension bundle has been installed or updated. The VM must be restarted in order for the changed boot class path to take effect.
      • ERROR - The Framework encountered an error while shutting down or an error has occurred which forced the framework to shutdown.
      • WAIT_TIMEDOUT - This method has timed out and returned before this Framework has stopped.
      Throws:
      InterruptedException - If the thread was interrupted.
    • uninstall

      public void uninstall() throws BundleException
      Description copied from interface: Bundle
      Uninstalls this bundle.

      This method causes the Framework to notify other bundles that this bundle is being uninstalled, and then puts this bundle into the UNINSTALLED state. The Framework must remove any resources related to this bundle that it is able to remove.

      If this bundle has exported any packages, the Framework must continue to make these packages available to their importing bundles until the FrameworkWiring.refreshBundles method has been called or the Framework is relaunched.

      The following steps are required to uninstall a bundle:

      1. If this bundle's state is UNINSTALLED then an IllegalStateException is thrown.
      2. If this bundle's state is ACTIVE, STARTING or STOPPING, this bundle is stopped as described in the Bundle.stop method. If Bundle.stop throws an exception, a Framework event of type FrameworkEvent.ERROR is fired containing the exception.
      3. This bundle's state is set to UNINSTALLED.
      4. A bundle event of type BundleEvent.UNINSTALLED is fired.
      5. This bundle and any persistent storage area provided for this bundle by the Framework are removed.
      Preconditions
      • getState() not in { UNINSTALLED }.
      Postconditions, no exceptions thrown
      • getState() in { UNINSTALLED }.
      • This bundle has been uninstalled.
      Postconditions, when an exception is thrown
      • getState() not in { UNINSTALLED }.
      • This Bundle has not been uninstalled.
      Specified by:
      uninstall in interface Bundle
      Specified by:
      uninstall in interface Framework
      Overrides:
      uninstall in class BundleImpl
      Throws:
      BundleException - If the uninstall failed. This can occur if another thread is attempting to change this bundle's state and does not complete in a timely manner. BundleException types thrown by this method include: BundleException.STATECHANGE_ERROR
      See Also:
    • update

      public void update() throws BundleException
      Description copied from interface: Bundle
      Updates this bundle.

      This method performs the same function as calling Bundle.update(InputStream) with a null InputStream.

      Specified by:
      update in interface Bundle
      Specified by:
      update in interface Framework
      Overrides:
      update in class BundleImpl
      Throws:
      BundleException - If this bundle could not be updated. BundleException types thrown by this method include: BundleException.READ_ERROR, BundleException.DUPLICATE_BUNDLE_ERROR, BundleException.MANIFEST_ERROR, BundleException.NATIVECODE_ERROR, BundleException.RESOLVE_ERROR, BundleException.STATECHANGE_ERROR, and BundleException.ACTIVATOR_ERROR.
      See Also:
    • update

      public void update(InputStream is) throws BundleException
      Description copied from interface: Bundle
      Updates this bundle from an InputStream.

      If the specified InputStream is null, the Framework must create the InputStream from which to read the updated bundle by interpreting, in an implementation dependent manner, this bundle's Bundle-UpdateLocation Manifest header, if present, or this bundle's original location.

      If this bundle's state is ACTIVE, it must be stopped before the update and started after the update successfully completes.

      If this bundle has exported any packages that are imported by another bundle, these packages must remain exported until the FrameworkWiring.refreshBundles method has been has been called or the Framework is relaunched.

      The following steps are required to update a bundle:

      1. If this bundle's state is UNINSTALLED then an IllegalStateException is thrown.
      2. If this bundle's state is ACTIVE, STARTING or STOPPING, this bundle is stopped as described in the Bundle.stop method. If Bundle.stop throws an exception, the exception is rethrown terminating the update.
      3. The updated version of this bundle is read from the input stream and installed. If the Framework is unable to install the updated version of this bundle, the original version of this bundle must be restored and a BundleException must be thrown after completion of the remaining steps.
      4. This bundle's state is set to INSTALLED.
      5. If the updated version of this bundle was successfully installed, a bundle event of type BundleEvent.UPDATED is fired.
      6. If this bundle's state was originally ACTIVE, the updated bundle is started as described in the Bundle.start method. If Bundle.start throws an exception, a Framework event of type FrameworkEvent.ERROR is fired containing the exception.
      Preconditions
      • getState() not in { UNINSTALLED }.
      Postconditions, no exceptions thrown
      • getState() in { INSTALLED, RESOLVED, ACTIVE }.
      • This bundle has been updated.
      Postconditions, when an exception is thrown
      • getState() in { INSTALLED, RESOLVED, ACTIVE }.
      • Original bundle is still used; no update occurred.
      Specified by:
      update in interface Bundle
      Specified by:
      update in interface Framework
      Overrides:
      update in class BundleImpl
      Parameters:
      is - The InputStream from which to read the new bundle or null to indicate the Framework must create the input stream from this bundle's Bundle-UpdateLocation Manifest header, if present, or this bundle's original location. The input stream must always be closed when this method completes, even if an exception is thrown.
      Throws:
      BundleException - If this bundle could not be updated. BundleException types thrown by this method include: BundleException.READ_ERROR, BundleException.DUPLICATE_BUNDLE_ERROR, BundleException.MANIFEST_ERROR, BundleException.NATIVECODE_ERROR, BundleException.RESOLVE_ERROR, BundleException.STATECHANGE_ERROR, and BundleException.ACTIVATOR_ERROR.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class BundleImpl
    • getActiveStartLevel

      int getActiveStartLevel()
      Returns the active start level of the framework; this method implements functionality for the Start Level service.
      Returns:
      The active start level of the framework.
    • setActiveStartLevel

      void setActiveStartLevel(int requestedLevel, FrameworkListener[] listeners)
      Implements the functionality of the setStartLevel() 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. This method should not be called directly.
      Parameters:
      requestedLevel - The new start level of the framework.
    • getInitialBundleStartLevel

      int getInitialBundleStartLevel()
      Returns the start level into which newly installed bundles will be placed by default; this method implements functionality for the Start Level service.
      Returns:
      The default start level for newly installed bundles.
    • setInitialBundleStartLevel

      void setInitialBundleStartLevel(int startLevel)
      Sets the default start level into which newly installed bundles will be placed; this method implements functionality for the Start Level service.
      Parameters:
      startLevel - The new default start level for newly installed bundles.
    • getBundleStartLevel

      int getBundleStartLevel(Bundle bundle)
      Returns the start level for the specified bundle; this method implements functionality for the Start Level service.
      Parameters:
      bundle - The bundle to examine.
      Returns:
      The start level of the specified bundle.
      Throws:
      IllegalArgumentException - If the specified bundle has been uninstalled.
    • setBundleStartLevel

      void setBundleStartLevel(Bundle bundle, int startLevel)
      Sets the start level of the specified bundle; this method implements functionality for the Start Level service.
      Parameters:
      bundle - The bundle whose start level is to be modified.
      startLevel - The new start level of the specified bundle.
    • isBundlePersistentlyStarted

      boolean isBundlePersistentlyStarted(Bundle bundle)
      Returns whether a bundle is persistently started; this is an method implementation for the Start Level service.
      Parameters:
      bundle - The bundle to examine.
      Returns:
      true if the bundle is marked as persistently started, false otherwise.
      Throws:
      IllegalArgumentException - If the specified bundle has been uninstalled.
    • isBundleActivationPolicyUsed

      boolean isBundleActivationPolicyUsed(Bundle bundle)
      Returns whether the bundle is using its declared activation policy; this is an method implementation for the Start Level service.
      Parameters:
      bundle - The bundle to examine.
      Returns:
      true if the bundle is using its declared activation policy, false otherwise.
      Throws:
      IllegalArgumentException - If the specified bundle has been uninstalled.
    • getBundleHeaders

      Dictionary getBundleHeaders(BundleImpl bundle, String locale)
      Get bundle headers and resolve any localized strings from resource bundles.
      Parameters:
      bundle -
      locale -
      Returns:
      localized bundle headers dictionary.
    • getBundleResource

      URL getBundleResource(BundleImpl bundle, String name)
      Implementation for Bundle.getResource().
    • getBundleResources

      Enumeration getBundleResources(BundleImpl bundle, String name)
      Implementation for Bundle.getResources().
    • getBundleEntry

      URL getBundleEntry(BundleImpl bundle, String name)
      Implementation for Bundle.getEntry().
    • getBundleEntryPaths

      Enumeration getBundleEntryPaths(BundleImpl bundle, String path)
      Implementation for Bundle.getEntryPaths().
    • findBundleEntries

      Enumeration findBundleEntries(BundleImpl bundle, String path, String filePattern, boolean recurse)
      Implementation for Bundle.findEntries().
    • findBundleEntries

      Enumeration findBundleEntries(BundleRevision revision, String path, String filePattern, boolean recurse)
      Implementation for BundleWiring.findEntries().
    • getBundleRegisteredServices

      ServiceReference[] getBundleRegisteredServices(BundleImpl bundle)
    • getBundleServicesInUse

      ServiceReference[] getBundleServicesInUse(Bundle bundle)
    • bundleHasPermission

      boolean bundleHasPermission(BundleImpl bundle, Object obj)
    • loadBundleClass

      Class loadBundleClass(BundleImpl bundle, String name) throws ClassNotFoundException
      Implementation for Bundle.loadClass().
      Throws:
      ClassNotFoundException
    • startBundle

      void startBundle(BundleImpl bundle, int options) throws BundleException
      Implementation for Bundle.start().
      Throws:
      BundleException
    • activateBundle

      void activateBundle(BundleImpl bundle, boolean fireEvent) throws BundleException
      Throws:
      BundleException
    • updateBundle

      void updateBundle(BundleImpl bundle, InputStream is) throws BundleException
      Throws:
      BundleException
    • stopBundle

      void stopBundle(BundleImpl bundle, boolean record) throws BundleException
      Throws:
      BundleException
    • uninstallBundle

      void uninstallBundle(BundleImpl bundle) throws BundleException
      Throws:
      BundleException
    • getProperty

      String getProperty(String key)
      Implementation for BundleContext.getProperty(). Returns environment property associated with the framework.
      Parameters:
      key - The name of the property to retrieve.
      Returns:
      The value of the specified property or null.
    • reloadBundle

      private Bundle reloadBundle(BundleArchive ba) throws BundleException
      Throws:
      BundleException
    • installBundle

      Bundle installBundle(Bundle origin, String location, InputStream is) throws BundleException
      Throws:
      BundleException
    • getBundle

      Bundle getBundle(String location)
      Retrieves a bundle from its location.
      Parameters:
      location - The location of the bundle to retrieve.
      Returns:
      The bundle associated with the location or null if there is no bundle associated with the location.
    • getBundle

      Bundle getBundle(BundleContext bc, long id)
      Implementation for BundleContext.getBundle(). Retrieves a bundle from its identifier.
      Parameters:
      id - The identifier of the bundle to retrieve.
      Returns:
      The bundle associated with the identifier or null if there is no bundle associated with the identifier.
    • getBundle

      Bundle getBundle(long id)
      Retrieves a bundle by its identifier and avoids bundles hooks.
      Returns:
      The bundle associated with the identifier or null.
    • getBundles

      Bundle[] getBundles(BundleContext bc)
      Implementation for BundleContext.getBundles(). Retrieves all installed bundles.
      Returns:
      An array containing all installed bundles or null if there are no installed bundles.
    • getBundles

      Bundle[] getBundles()
      Retrieves all installed bundles and avoids bundles hooks.
      Returns:
      An array containing all installed bundles or null if there are no installed bundles.
    • addBundleListener

      void addBundleListener(BundleImpl bundle, BundleListener l)
    • removeBundleListener

      void removeBundleListener(BundleImpl bundle, BundleListener l)
    • addServiceListener

      void addServiceListener(BundleImpl bundle, ServiceListener l, String f) throws InvalidSyntaxException
      Implementation for BundleContext.addServiceListener(). Adds service listener to the listener list so that is can listen for ServiceEvents.
      Parameters:
      bundle - The bundle that registered the listener.
      l - The service listener to add to the listener list.
      f - The filter for the listener; may be null.
      Throws:
      InvalidSyntaxException
    • removeServiceListener

      void removeServiceListener(BundleImpl bundle, ServiceListener l)
      Implementation for BundleContext.removeServiceListener(). Removes service listeners from the listener list.
      Parameters:
      bundle - The context bundle of the listener
      l - The service listener to remove from the listener list.
    • addFrameworkListener

      void addFrameworkListener(BundleImpl bundle, FrameworkListener l)
    • removeFrameworkListener

      void removeFrameworkListener(BundleImpl bundle, FrameworkListener l)
    • registerService

      ServiceRegistration registerService(BundleContextImpl context, String[] classNames, Object svcObj, Dictionary dict)
      Implementation for BundleContext.registerService(). Registers a service for the specified bundle bundle.
      Parameters:
      classNames - A string array containing the names of the classes under which the new service is available.
      svcObj - The service object or ServiceFactory.
      dict - A dictionary of properties that further describe the service or null.
      Returns:
      A ServiceRegistration object or null.
    • getServiceReferences

      ServiceReference[] getServiceReferences(BundleImpl bundle, String className, String expr, boolean checkAssignable) throws InvalidSyntaxException
      Retrieves an array of ServiceReference objects based on calling bundle, service class name, and filter expression. Optionally checks for isAssignable to make sure that the service can be cast to the
      Parameters:
      bundle - Calling Bundle
      className - Service Classname or null for all
      expr - Filter Criteria or null
      Returns:
      Array of ServiceReference objects that meet the criteria
      Throws:
      InvalidSyntaxException
    • getAllowedServiceReferences

      ServiceReference[] getAllowedServiceReferences(BundleImpl bundle, String className, String expr, boolean checkAssignable) throws InvalidSyntaxException
      Retrieves Array of ServiceReference objects based on calling bundle, service class name, optional filter expression, and optionally filters further on the version. If running under a SecurityManager, checks that the calling bundle has permissions to see the service references and removes references that aren't.
      Parameters:
      bundle - Calling Bundle
      className - Service Classname or null for all
      expr - Filter Criteria or null
      checkAssignable - true to check for isAssignable, false to return all versions
      Returns:
      Array of ServiceReference objects that meet the criteria
      Throws:
      InvalidSyntaxException
    • getService

      <S> S getService(Bundle bundle, ServiceReference<S> ref, boolean isPrototype)
    • ungetService

      boolean ungetService(Bundle bundle, ServiceReference ref, Object srvObj)
    • getDataFile

      File getDataFile(BundleImpl bundle, String s)
    • isHookBlackListed

      boolean isHookBlackListed(ServiceReference sr)
    • blackListHook

      void blackListHook(ServiceReference sr)
    • getHooks

      public <S> Set<ServiceReference<S>> getHooks(Class<S> hookClass)
    • getBundle

      Bundle getBundle(Class clazz)
      This method returns the bundle associated with the specified class if the class was loaded from a bundle from this framework instance. If the class was not loaded from a bundle or was loaded by a bundle in another framework instance, then null is returned.
      Parameters:
      clazz - the class for which to find its associated bundle.
      Returns:
      the bundle associated with the specified class or null if the class was not loaded by a bundle or its associated bundle belongs to a different framework instance.
    • getExportedPackages

      ExportedPackage[] getExportedPackages(String pkgName)
      Returns the exported packages associated with the specified package name. This is used by the PackageAdmin service implementation.
      Parameters:
      pkgName - The name of the exported package to find.
      Returns:
      The exported package or null if no matching package was found.
    • getExportedPackages

      ExportedPackage[] getExportedPackages(Bundle b)
      Returns an array of all actively exported packages from the specified bundle or if the specified bundle is null an array containing all actively exported packages by all bundles.
      Parameters:
      b - The bundle whose exported packages are to be retrieved or null if the exported packages of all bundles are to be retrieved.
      Returns:
      An array of exported packages.
    • getExportedPackages

      private void getExportedPackages(Bundle bundle, List list)
      Adds any current active exported packages from the specified bundle to the passed in list.
      Parameters:
      bundle - The bundle from which to retrieve exported packages.
      list - The list to which the exported packages are added
    • getImportingBundles

      Set<Bundle> getImportingBundles(BundleImpl exporter, BundleCapability cap)
    • getRequiringBundles

      Set<Bundle> getRequiringBundles(BundleImpl bundle)
    • resolveBundles

      boolean resolveBundles(Collection<Bundle> targets)
    • resolveBundleRevision

      private void resolveBundleRevision(BundleRevision revision) throws BundleException
      Throws:
      BundleException
    • refreshPackages

      void refreshPackages(Collection<Bundle> targets, FrameworkListener[] listeners)
    • getDependencyClosure

      Collection<Bundle> getDependencyClosure(Collection<Bundle> targets)
    • populateDependentGraph

      private void populateDependentGraph(BundleImpl exporter, Set<Bundle> set)
    • getRemovalPendingBundles

      Collection<Bundle> getRemovalPendingBundles()
    • getSecurityProvider

      SecurityProvider getSecurityProvider()
    • setSecurityProvider

      void setSecurityProvider(SecurityProvider securityProvider)
    • getSignerMatcher

      Object getSignerMatcher(BundleImpl bundle, int signersType)
    • impliesBundlePermission

      boolean impliesBundlePermission(BundleProtectionDomain bundleProtectionDomain, Permission permission, boolean direct)
    • createBundleActivator

      private BundleActivator createBundleActivator(Bundle impl) throws Exception
      Throws:
      Exception
    • refreshBundle

      private void refreshBundle(BundleImpl bundle) throws Exception
      Throws:
      Exception
    • fireFrameworkEvent

      void fireFrameworkEvent(int type, Bundle bundle, Throwable throwable)
      Fires bundle events.
    • fireBundleEvent

      void fireBundleEvent(int type, Bundle bundle)
      Fires bundle events.
      Parameters:
      type - The type of bundle event to fire.
      bundle - The bundle associated with the event.
    • fireBundleEvent

      void fireBundleEvent(int type, Bundle bundle, Bundle origin)
    • fireServiceEvent

      private void fireServiceEvent(ServiceEvent event, Dictionary oldProps)
      Fires service events.
      Parameters:
      event - The service event to fire.
      reg - The service registration associated with the service object.
    • initializeFrameworkProperties

      private void initializeFrameworkProperties()
    • loadFromDefaultIfNotDefined

      private void loadFromDefaultIfNotDefined(Properties defaultProperties, String propertyName)
    • loadPrefixFromDefaultIfNotDefined

      private void loadPrefixFromDefaultIfNotDefined(Map configMap, Properties defaultProperties, String prefix)
    • getFrameworkVersion

      private static String getFrameworkVersion()
      Read the framework version from the property file.
      Returns:
      the framework version as a string.
    • cleanMavenVersion

      private static String cleanMavenVersion(StringBuffer sb)
      The main purpose of this method is to turn a.b.c-SNAPSHOT into a.b.c.SNAPSHOT it can also deal with a.b-SNAPSHOT and turns it into a.b.0.SNAPSHOT and will leave the dash in a.b.c.something-else, as it's valid in that last example. In short this method attempts to map a Maven version to an OSGi version as well as possible.
      Parameters:
      sb - The version to be cleaned
      Returns:
      The cleaned version
    • loadNextId

      private long loadNextId()
      Generated the next valid bundle identifier.
    • getNextId

      private long getNextId()
    • rememberUninstalledBundle

      private void rememberUninstalledBundle(BundleImpl bundle)
    • forgetUninstalledBundle

      private void forgetUninstalledBundle(BundleImpl bundle)
    • acquireInstallLock

      void acquireInstallLock(String location) throws BundleException
      Throws:
      BundleException
    • releaseInstallLock

      void releaseInstallLock(String location)
    • setBundleStateAndNotify

      void setBundleStateAndNotify(BundleImpl bundle, int state)
    • acquireBundleLock

      void acquireBundleLock(BundleImpl bundle, int desiredStates) throws IllegalStateException
      This method acquires the lock for the specified bundle as long as the bundle is in one of the specified states. If it is not, an exception is thrown. Bundle state changes will be monitored to avoid deadlocks.
      Parameters:
      bundle - The bundle to lock.
      desiredStates - Logically OR'ed desired bundle states.
      Throws:
      IllegalStateException - If the bundle is not in one of the specified desired states.
    • releaseBundleLock

      void releaseBundleLock(BundleImpl bundle)
      Releases the bundle's lock.
      Parameters:
      bundle - The bundle whose lock is to be released.
      Throws:
      IllegalStateException - If the calling thread does not own the bundle lock.
    • acquireGlobalLock

      boolean acquireGlobalLock()
      Attempts to acquire the global lock. Will also promote a bundle lock to the global lock, if the calling thread already holds a bundle lock. Since it is possible to deadlock when trying to acquire the global lock while holding a bundle lock, this method may fail if a potential deadlock is detected. If the calling thread does not hold a bundle lock, then it will wait indefinitely to acquire the global.
      Returns:
      true if the global lock was successfully acquired, false otherwise.
    • releaseGlobalLock

      void releaseGlobalLock()
      Releases the global lock.
      Throws:
      IllegalStateException - If the calling thread does not own the global lock.
    • setURLHandlersActivator

      void setURLHandlersActivator(URLHandlersActivator urlHandlersActivator)
    • getStreamHandlerService

      Object getStreamHandlerService(String protocol)
    • getContentHandlerService

      Object getContentHandlerService(String mimeType)
    • findProviders

      Collection<BundleCapability> findProviders(Requirement requirement)