Package org.osgi.framework

Examples of org.osgi.framework.BundleException


        //to: the loading of a driver bundle
        //we fake it, so that it fails
        Mockito.when( m_context.installBundle(
            Mockito.anyString(),
            Mockito.isA( InputStream.class ) ) )
          .thenThrow(new BundleException( "test exception" ) );

        Driver matched = drivers.get( "org.apache.felix.driver-1.0" );

        final CountDownLatch latch = new CountDownLatch( 1 );
View Full Code Here


            {
                arg0.close();
            }
            catch ( IOException ioe )
            {
                throw new BundleException( ioe.getMessage(), ioe );
            }
        }
    }
View Full Code Here

      http.setProcessorName(processorName);
      http.start();
      HttpConnectorActivator.log(LogService.LOG_INFO, "Started JMX Http Connector "+version,null);
    }else {
      throw new BundleException("No JMX Agent found");
    }
  }
View Full Code Here

     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException
    {
        boolean success = false;
        BundleException bundleException = null;
        final String action = WebConsoleUtil.getParameter( req, "action" );
        if ( "refreshPackages".equals( action ) )
        {
            getPackageAdmin().refreshPackages( null );
            success = true;
View Full Code Here

                triggers = (mandatory.isEmpty())
                    ? optional : mandatory;
            }
            triggers = Collections.unmodifiableSet(triggers);

            BundleException rethrow = null;

            // Create resolver hook objects by calling begin() on factory.
            for (ServiceReference<ResolverHookFactory> ref : hookRefs)
            {
                try
                {
                    ResolverHookFactory rhf = m_felix.getService(m_felix, ref, false);
                    if (rhf != null)
                    {
                        ResolverHook hook =
                            Felix.m_secureAction
                                .invokeResolverHookFactory(rhf, triggers);
                        if (hook != null)
                        {
                            hookMap.put(ref, hook);
                        }
                    }
                }
                catch (Throwable ex)
                {
                    rethrow = new BundleException(
                        "Resolver hook exception: " + ex.getMessage(),
                        BundleException.REJECTED_BY_HOOK,
                        ex);
                    // Resolver hook spec: if there is an exception during the resolve operation; abort.
                    // So we break here to make sure that no further resolver hooks are created.
                    break;
                }
            }

            if (rethrow != null)
            {
                for (ResolverHook hook : hookMap.values())
                {
                    try
                    {
                        Felix.m_secureAction.invokeResolverHookEnd(hook);
                    }
                    catch (Exception ex)
                    {
                        rethrow = new BundleException(
                                "Resolver hook exception: " + ex.getMessage(),
                                BundleException.REJECTED_BY_HOOK,
                                ex);
                    }
                }

                throw rethrow;
            }

            // Ask hooks to indicate which revisions should not be resolved.
            whitelist = new ShrinkableCollection<BundleRevision>(getUnresolvedRevisions());
            int originalSize = whitelist.size();
            for (ResolverHook hook : hookMap.values())
            {
                try
                {
                    Felix.m_secureAction
                        .invokeResolverHookResolvable(hook, whitelist);
                }
                catch (Throwable ex)
                {
                    rethrow = new BundleException(
                        "Resolver hook exception: " + ex.getMessage(),
                        BundleException.REJECTED_BY_HOOK,
                        ex);
                    // Resolver hook spec: if there is an exception during the resolve operation; abort.
                    // So we break here to make sure that no further resolver operations are executed.
                    break;
                }
            }

            if (rethrow != null)
            {
                for (ResolverHook hook : hookMap.values())
                {
                    try
                    {
                        Felix.m_secureAction.invokeResolverHookEnd(hook);
                    }
                    catch (Exception ex)
                    {
                        rethrow = new BundleException(
                                "Resolver hook exception: " + ex.getMessage(),
                                BundleException.REJECTED_BY_HOOK,
                                ex);
                    }
                }
View Full Code Here

                }
                m_felix.ungetService(m_felix, ref, null);
            }
            if (invalid)
            {
                throw new BundleException(
                    "Resolver hook service unregistered during resolve.",
                    BundleException.REJECTED_BY_HOOK);
            }
        }
    }
View Full Code Here

                    Felix.m_secureAction
                        .invokeResolverHookSingleton(hook, entry.getKey(), entry.getValue());
                }
                catch (Throwable ex)
                {
                    throw new BundleException(
                        "Resolver hook exception: " + ex.getMessage(),
                        BundleException.REJECTED_BY_HOOK,
                        ex);
                }
            }
View Full Code Here

                           m_cache = new BundleCache(m_logger, m_configMap);
                       }
                       catch (Exception ex)
                       {
                           m_logger.log(Logger.LOG_ERROR, "Error creating bundle cache.", ex);
                           throw new BundleException("Error creating bundle cache.", ex);
                       }
                }

                // If this is the first time init is called, check to see if
                // we need to flush the bundle cache.
                if (getState() == Bundle.INSTALLED)
                {
                    String clean = (String) m_configMap.get(Constants.FRAMEWORK_STORAGE_CLEAN);
                    if ((clean != null)
                        && clean.equalsIgnoreCase(Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT))
                    {
                        try
                        {
                            m_cache.delete();
                        }
                        catch (Exception ex)
                        {
                            throw new BundleException("Unable to flush bundle cache.", ex);
                        }
                    }
                }

                // Initialize installed bundle data structures.
                Map[] maps = new Map[] {
                    new HashMap<String, BundleImpl>(1),
                    new TreeMap<Long, BundleImpl>()
                };
                m_uninstalledBundles = new ArrayList<BundleImpl>(0);

                // Add the system bundle to the set of installed bundles.
                maps[LOCATION_MAP_IDX].put(_getLocation(), this);
                maps[IDENTIFIER_MAP_IDX].put(new Long(0), this);
                m_installedBundles = maps;

                // Manually resolve the system bundle, which will cause its
                // state to be set to RESOLVED.
                try
                {
                    m_resolver.resolve(
                        Collections.singleton(adapt(BundleRevision.class)),
                        Collections.EMPTY_SET);
                }
                catch (ResolveException ex)
                {
                    // This should never happen.
                    throw new BundleException(
                        "Unresolved constraint in System Bundle:"
                        + ex.getRequirement());
                }

                // Reload the cached bundles before creating and starting the
                // system bundle, since we want all cached bundles to be reloaded
                // when we activate the system bundle and any subsequent system
                // bundle activators passed into the framework constructor.
                BundleArchive[] archives = null;

                // First get cached bundle identifiers.
                try
                {
                    archives = m_cache.getArchives();
                }
                catch (Exception ex)
                {
                    m_logger.log(Logger.LOG_ERROR, "Unable to list saved bundles.", ex);
                    archives = null;
                }

                // Create system bundle activator and bundle context so we can activate it.
                setActivator(new SystemBundleActivator());
                setBundleContext(new BundleContextImpl(m_logger, this, this));

                // Now load all cached bundles.
                for (int i = 0; (archives != null) && (i < archives.length); i++)
                {
                    try
                    {
                        // Keep track of the max bundle ID currently in use since we
                        // will need to use this as our next bundle ID value if the
                        // persisted value cannot be read.
                        m_nextId = Math.max(m_nextId, archives[i].getId() + 1);

                        // It is possible that a bundle in the cache was previously
                        // uninstalled, but not completely deleted (perhaps because
                        // of a crash or a locked file), so if we see an archive
                        // with an UNINSTALLED persistent state, then try to remove
                        // it now.
                        if (archives[i].getPersistentState() == Bundle.UNINSTALLED)
                        {
                            archives[i].closeAndDelete();
                        }
                        // Otherwise re-install the cached bundle.
                        else
                        {
                            // Install the cached bundle.
                            reloadBundle(archives[i]);
                        }
                    }
                    catch (Exception ex)
                    {
                        fireFrameworkEvent(FrameworkEvent.ERROR, this, ex);
                        try
                        {
                            m_logger.log(
                                Logger.LOG_ERROR,
                                "Unable to re-install " + archives[i].getLocation(),
                                ex);
                        }
                        catch (Exception ex2)
                        {
                            m_logger.log(
                                Logger.LOG_ERROR,
                                "Unable to re-install cached bundle.",
                                ex);
                        }
                        // TODO: FRAMEWORK - Perhaps we should remove the cached bundle?
                    }
                }

                // Now that we have loaded all cached bundles and have determined the
                // max bundle ID of cached bundles, we need to try to load the next
                // bundle ID from persistent storage. In case of failure, we should
                // keep the max value.
                m_nextId = Math.max(m_nextId, loadNextId());

                // The framework is now in its startup sequence.
                setBundleStateAndNotify(this, Bundle.STARTING);

                // Now it is possible for threads to wait for the framework to stop,
                // so create a gate for that purpose.
                m_shutdownGate = new ThreadGate();

                // Start services
                m_fwkWiring.start();
                m_fwkStartLevel.start();

                try
                {
                    Felix.m_secureAction.startActivator(
                        getActivator(), _getBundleContext());
                }
                catch (Throwable ex)
                {
                    m_dispatcher.stopDispatching();
                    m_logger.log(Logger.LOG_ERROR, "Unable to start system bundle.", ex);
                    throw new RuntimeException("Unable to start system bundle.");
                }

                // Now that the system bundle is successfully created we can give
                // its bundle context to the logger so that it can track log services.
                m_logger.setSystemBundleContext(_getBundleContext());

                // We have to check with the security provider (if there is one).
                // This is to avoid having bundles in the cache that have been tampered with
                SecurityProvider sp = getFramework().getSecurityProvider();
                if ((sp != null) && (System.getSecurityManager() != null))
                {
                    boolean locked = acquireGlobalLock();
                    if (!locked)
                    {
                        throw new BundleException(
                            "Unable to acquire the global lock to check the bundle.");
                    }
                    try
                    {
                        for (Object bundle : m_installedBundles[IDENTIFIER_MAP_IDX].values())
View Full Code Here

    }

    @Override
    public void uninstall() throws BundleException
    {
        throw new BundleException("Cannot uninstall the system bundle.");
    }
View Full Code Here

            {
                throw new IllegalStateException("Cannot start an uninstalled bundle.");
            }
            else
            {
                throw new BundleException(
                    "Bundle " + bundle
                    + " cannot be started, since it is either starting or stopping.");
            }
        }

        // Record whether the bundle is using its declared activation policy.
        boolean wasDeferred = bundle.isDeclaredActivationPolicyUsed()
            && (((BundleRevisionImpl) bundle.adapt(BundleRevision.class))
                .getDeclaredActivationPolicy() == BundleRevisionImpl.LAZY_ACTIVATION);
        bundle.setDeclaredActivationPolicyUsed(
            (options & Bundle.START_ACTIVATION_POLICY) != 0);

        BundleException rethrow = null;
        try
        {
            // The spec doesn't say whether it is possible to start an extension
            // We just do nothing
            if (bundle.isExtension())
            {
                return;
            }

            // As per the OSGi spec, fragment bundles can not be started and must
            // throw a BundleException when there is an attempt to start one.
            if (Util.isFragment(bundle.adapt(BundleRevision.class)))
            {
                throw new BundleException("Fragment bundles can not be started.");
            }

            // Set and save the bundle's persistent state to active
            // if we are supposed to record state change.
            if (!isTransient)
            {
                if ((options & Bundle.START_ACTIVATION_POLICY) != 0)
                {
                    bundle.setPersistentStateStarting();
                }
                else
                {
                    bundle.setPersistentStateActive();
                }
            }

            // Check to see if the bundle's start level is greater than the
            // the framework's target start level and if so just return. For
            // transient starts we compare their start level to the current
            // active start level, since we never process transient starts
            // asynchronously (i.e., they are either satisfied and process
            // synchronously here or they throw an exception).
            int bundleLevel = bundle.getStartLevel(getInitialBundleStartLevel());
            if (isTransient && (bundleLevel > m_activeStartLevel))
            {
                // Throw an exception for transient starts.
                throw new BundleException(
                    "Cannot start bundle " + bundle + " because its start level is "
                    + bundleLevel
                    + ", which is greater than the framework's start level of "
                    + m_activeStartLevel + ".", BundleException.START_TRANSIENT_ERROR);
            }
            else if (bundleLevel > m_targetStartLevel)
            {
                // Ignore persistent starts that are not satisfied.
                return;
            }

            // Check to see if there is a start level change in progress and if
            // so queue this bundle to the start level bundle queue for the start
            // level thread and return, except for transient starts which are
            // queued but processed synchronously.
            // Note: Don't queue starts from the start level thread, otherwise
            // we'd never get anything started.
            if (!Thread.currentThread().getName().equals(FrameworkStartLevelImpl.THREAD_NAME))
            {
                synchronized (m_startLevelBundles)
                {
                    // Since we have the start level queue lock, we know the
                    // active start level cannot change. For transient starts
                    // we now need to double check and make sure we can still
                    // start them since technically the active start level could
                    // have changed.
                    if (isTransient && (bundleLevel > m_activeStartLevel))
                    {
                        throw new BundleException(
                            "Cannot start bundle " + bundle + " because its start level is "
                            + bundleLevel
                            + ", which is greater than the framework's start level of "
                            + m_activeStartLevel + ".", BundleException.START_TRANSIENT_ERROR);
                    }

                    // If the start level bundle queue is not empty, then we know
                    // there is a start level operation ongoing. We know that the
                    // bundle being started is satisfied by the target start level
                    // otherwise we wouldn't be here. In most cases we simply want
                    // to queue the bundle; however, if the bundle level is lower
                    // than the current active start level, then we want to handle
                    // it synchronously. This is because the start level thread
                    // ignores bundles that it should have already processed.
                    // So queue the bundle if its bundle start level is greater
                    // or equal to the active start level and then simply return
                    // since it will be processed asynchronously.
                    if (!m_startLevelBundles.isEmpty()
                        && (bundleLevel >= m_activeStartLevel))
                    {
                        // Only add the bundle to the start level bundles
                        // being process if it is not already there.
                        boolean found = false;
                        for (StartLevelTuple tuple : m_startLevelBundles)
                        {
                            if (tuple.m_bundle == bundle)
                            {
                                found = true;
                            }
                        }

                        if (!found)
                        {
                            m_startLevelBundles.add(new StartLevelTuple(bundle, bundleLevel));
                        }

                        // Note that although we queued the transiently started
                        // bundle, we don't return here because we handle all
                        // transient bundles synchronously. The reason why we
                        // queue it anyway is for the case where the start level
                        // is lowering, since the transiently started bundle may
                        // have already been processed by the start level thread
                        // and we will start it briefly here synchronously, but
                        // we want the start level thread to process it again
                        // so it gets another chance to stop it. This is not an
                        // issue when the start level is raising because the
                        // start level thread ignores non-persistently started
                        // bundles or if it is also persistently started it will
                        // be a no-op.
                        if (!isTransient)
                        {
                            return;
                        }
                    }
                }
            }

            switch (bundle.getState())
            {
                case Bundle.UNINSTALLED:
                    throw new IllegalStateException("Cannot start an uninstalled bundle.");
                case Bundle.STARTING:
                    if (!wasDeferred)
                    {
                        throw new BundleException(
                            "Bundle " + bundle
                            + " cannot be started, since it is starting.");
                    }
                    break;
                case Bundle.STOPPING:
                    throw new BundleException(
                        "Bundle " + bundle
                        + " cannot be started, since it is stopping.");
                case Bundle.ACTIVE:
                    return;
                case Bundle.INSTALLED:
View Full Code Here

TOP

Related Classes of org.osgi.framework.BundleException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.