Package org.osgi.service.startlevel

Examples of org.osgi.service.startlevel.StartLevel


        {
            out.println("StartLevel service is unavailable.");
            return;
        }

        StartLevel sl = (StartLevel) m_context.getService(ref);
        if (sl == null)
        {
            out.println("StartLevel service is unavailable.");
            return;
        }

        // Parse command line.
        StringTokenizer st = new StringTokenizer(s, " ");

        // Ignore the command name.
        st.nextToken();

        // If there is only one token, then assume it is
        // a bundle ID for which we must retrieve the bundle
        // level.
        if (st.countTokens() == 1)
        {
            // Get the bundle and display start level.
            Bundle bundle = null;
            String token = null;
            try
            {
                token = st.nextToken();
                long id = Long.parseLong(token);
                bundle = m_context.getBundle(id);
                if (bundle != null)
                {
                    out.println("Bundle " + token + " is level "
                        + sl.getBundleStartLevel(bundle));
                }
                else
                {
                    err.println("Bundle ID " + token + " is invalid.");
                }
            }
            catch (NumberFormatException ex)
            {
                err.println("Unable to parse integer '" + token + "'.");
            }
            catch (Exception ex)
            {
                err.println(ex.toString());
            }
        }
        // If there is more than one token, assume the first
        // token is the new start level and the remaining
        // tokens are the bundle IDs whose start levels should
        // be changed.
        else if (st.countTokens() > 1)
        {
            // Get the bundle.
            Bundle bundle = null;
            String token = null;
            int startLevel = -1;

            token = st.nextToken().trim();

            // If next token is the initial level switch,
            // then set it.
            if (token.equals(INITIAL_LEVEL_SWITCH))
            {
                if (st.countTokens() == 1)
                {
                    try
                    {
                        token = st.nextToken().trim();
                        startLevel = Integer.parseInt(token);
                        sl.setInitialBundleStartLevel(startLevel);
                    }
                    catch (NumberFormatException ex)
                    {
                        err.println("Unable to parse start level '" + token + "'.");
                    }
                }
                else
                {
                    err.println("Incorrect number of arguments.");
                }
            }
            // Otherwise, set the start level for the specified bundles.
            else
            {
                try
                {
                    startLevel = Integer.parseInt(token);
                }
                catch (NumberFormatException ex)
                {
                    err.println("Unable to parse start level '" + token + "'.");
                }

                // Ignore invalid start levels.
                if (startLevel > 0)
                {
                    // Set the start level for each specified bundle.
                    while (st.hasMoreTokens())
                    {
                        try
                        {
                            token = st.nextToken();
                            long id = Long.parseLong(token);
                            bundle = m_context.getBundle(id);
                            if (bundle != null)
                            {
                                sl.setBundleStartLevel(bundle, startLevel);
                            }
                            else
                            {
                                err.println("Bundle ID '" + token + "' is invalid.");
                            }
View Full Code Here


            }
        };
        m_symbolicNameToBundle.put(b.getSymbolicName(), b);
        b.start();
        b.getBundleContext().registerService(StartLevel.class.getName(),
                new StartLevel()
                {

                    public void setStartLevel(int startlevel)
                    {
                        // TODO Auto-generated method stub
View Full Code Here

    private void startBundles(BundleContext context, List<BundleInfo> startList) throws Exception {

        // Retrieve the Start Level service, since it will be needed
        // to set the start level of the installed bundles.
        StartLevel sl = (StartLevel) context.getService(context.getServiceReference(StartLevel.class.getName()));

        // Set the default bundle start level
        int ibsl = Integer.parseInt(configProps.getProperty("karaf.startlevel.bundle", "60"));
        sl.setInitialBundleStartLevel(ibsl);

        for (BundleInfo info : startList) {
            InputStream in = new FileInputStream(info.location);
            Bundle bundle = null;
            try {
                bundle = context.installBundle(info.mvnLocation, in);
            } finally {
                try { in.close(); } catch (Exception e) {}
            }
            if (info.startLevel > 0) {
                sl.setBundleStartLevel(bundle, info.startLevel);
            }

            info.bundle = bundle;
        }
View Full Code Here

            if (INSTALL_ACTION.equals(action)){
                BundleContext bundleContext = getBundleContext(actionRequest);
               
                //get the StartLeval object
                ServiceReference startLevelRef = bundleContext.getServiceReference(StartLevel.class.getCanonicalName());
                StartLevel startLevelService = (StartLevel) bundleContext.getService(startLevelRef);
               
                processInstallAction(actionRequest, bundleContext,startLevelService);
               
                listType = "all";
                searchString = "";
View Full Code Here

                // retrieve bundle infos
                List<ExtendedBundleInfo> bundleInfos = new ArrayList<ExtendedBundleInfo>();
               
                // get the StartLeval object
                ServiceReference startLevelRef = bundleContext.getServiceReference(StartLevel.class.getCanonicalName());
                StartLevel startLevelService = (StartLevel) bundleContext.getService(startLevelRef);
               
                // get configured bundle Ids
                Set<Long> configurationBundleIds = getConfigurationBundleIds();
               
                Bundle[] bundles = bundleContext.getBundles();
                for (Bundle bundle : bundles) {
                   
                    if (searchString != "" && !matchBundle(bundle, searchString)){
                        continue;
                    }
                   
                    // construct the result bundleInfos by listType
                    if ("wab".equals(listType)){
                        if (checkWABBundle(bundle)){
                            ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds);
                            info.addContextPath(getContextPath(bundle));
                            bundleInfos.add(info);
                        }
                    }else if ("blueprint".equals(listType)){
                        if (checkBlueprintBundle(bundle)){
                            ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds);
                           
                            // currently, we try get the the blueprintContainer service to determine if a blueprint bundle is created
                            // TODO A better way is using a BlueprintListener to track all blueprint bundle events
                            String filter = "(&(osgi.blueprint.container.symbolicname=" + bundle.getSymbolicName()
                                            + ")(osgi.blueprint.container.version=" + bundle.getVersion() + "))";
                            ServiceReference[] serviceReferences = null;
                            try {
                                serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(), filter);
                            } catch (InvalidSyntaxException e) {
                                throw new RuntimeException(e);
                            }
                            if (serviceReferences != null && serviceReferences.length > 0){
                                info.setBlueprintState(BlueprintState.CREATED);
                            }
                           
                            bundleInfos.add(info);
                        }
                    }else if ("system".equals(listType)){
                        if (checkSysBundle(bundle,startLevelService)){
                            ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds);
                            bundleInfos.add(info);
                        }
                    }else if ("configuration".equals(listType)){
                        if (checkConfigurationBundle(bundle,configurationBundleIds)){
                            ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds);
                            bundleInfos.add(info);
                        }
                    }else{
                        ExtendedBundleInfo info = createExtendedBundleInfo(bundle, startLevelService, configurationBundleIds);
                        bundleInfos.add(info);
                    }
                }
               
                Collections.sort(bundleInfos, new BundleIdDescComparator());
                renderRequest.setAttribute("extendedBundleInfos", bundleInfos);
               
                // set the values to render attribute
                renderRequest.setAttribute("listTypeValue", listType);
                renderRequest.setAttribute("searchStringValue", searchString);
               
                renderRequest.setAttribute("initStartLevel", startLevelService.getInitialBundleStartLevel());
               
                if (bundleInfos.size() == 0) {
                    addWarningMessage(renderRequest, getLocalizedString(renderRequest, "consolebase.bundlemanager.warn.nobundlesfound"));
                }
               
View Full Code Here

   */
  protected boolean isStartLevelSvcPresent(CommandInterpreter intp) {
    boolean retval = false;
    ServiceReference<?> slSvcRef = context.getServiceReference("org.osgi.service.startlevel.StartLevel"); //$NON-NLS-1$
    if (slSvcRef != null) {
      StartLevel slSvc = (StartLevel) context.getService(slSvcRef);
      if (slSvc != null) {
        retval = true;
      }
    } else {
      intp.println(ConsoleMsg.CONSOLE_CAN_NOT_USE_STARTLEVEL_NO_STARTLEVEL_SVC_ERROR);
View Full Code Here

          // check that the startlevel allows the bundle to be active (111550)
          if (tracker == null) {
            tracker = new ServiceTracker<StartLevel, StartLevel>(context, StartLevel.class.getName(), null);
            tracker.open();
          }
          StartLevel sl = tracker.getService();
          if (sl != null && (sl.getBundleStartLevel(bundles[i]) <= sl.getStartLevel())) {
            log.log(new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, FrameworkLogEntry.ERROR, 0, NLS.bind(EclipseAdaptorMsg.ECLIPSE_STARTUP_ERROR_BUNDLE_NOT_ACTIVE, bundles[i]), 0, null, null));
          }
        }
      }
    } finally {
View Full Code Here

    }
  }

  private static void installBundles(InitialBundle[] initialBundles, Bundle[] curInitBundles, List<Bundle> startBundles, List<Bundle> lazyActivationBundles, List<Bundle> toRefresh) {
    ServiceReference<?> reference = context.getServiceReference(StartLevel.class.getName());
    StartLevel startService = null;
    if (reference != null)
      startService = (StartLevel) context.getService(reference);
    try {
      for (int i = 0; i < initialBundles.length; i++) {
        Bundle osgiBundle = getBundleByLocation(initialBundles[i].locationString, curInitBundles);
        try {
          // don't need to install if it is already installed
          if (osgiBundle == null) {
            InputStream in = initialBundles[i].location.openStream();
            try {
              osgiBundle = context.installBundle(initialBundles[i].locationString, in);
            } catch (BundleException e) {
              StatusException status = e instanceof StatusException ? (StatusException) e : null;
              if (status != null && status.getStatusCode() == StatusException.CODE_OK && status.getStatus() instanceof Bundle) {
                osgiBundle = (Bundle) status.getStatus();
              } else
                throw e;
            }
            // only check for lazy activation header if this is a newly installed bundle and is not marked for persistent start
            if (!initialBundles[i].start && hasLazyActivationPolicy(osgiBundle))
              lazyActivationBundles.add(osgiBundle);
          }
          // always set the startlevel incase it has changed (bug 111549)
          // this is a no-op if the level is the same as previous launch.
          if ((osgiBundle.getState() & Bundle.UNINSTALLED) == 0 && initialBundles[i].level >= 0 && startService != null)
            startService.setBundleStartLevel(osgiBundle, initialBundles[i].level);
          // if this bundle is supposed to be started then add it to the start list
          if (initialBundles[i].start)
            startBundles.add(osgiBundle);
          // include basic bundles in case they were not resolved before
          if ((osgiBundle.getState() & Bundle.INSTALLED) != 0)
View Full Code Here

    }
  }

  private static void setStartLevel(final int value) {
    ServiceReference<?> reference = context.getServiceReference(StartLevel.class.getName());
    final StartLevel startLevel = reference != null ? (StartLevel) context.getService(reference) : null;
    if (startLevel == null)
      return;
    final Semaphore semaphore = new Semaphore(0);
    StartupEventListener listener = new StartupEventListener(semaphore, FrameworkEvent.STARTLEVEL_CHANGED);
    context.addFrameworkListener(listener);
    context.addBundleListener(listener);
    startLevel.setStartLevel(value);
    context.ungetService(reference);
    updateSplash(semaphore, listener);
  }
View Full Code Here

     * Changes the framework start level and waits for the STARTLEVEL_CHANGED event
     * Note, changing the framework start level is an asynchronous operation.
     */
    public static void changeStartLevel(final BundleContext context, final int level, final long timeout, final TimeUnit units) throws InterruptedException, TimeoutException {
        final ServiceReference sref = context.getServiceReference(StartLevel.class.getName());
        final StartLevel startLevel = (StartLevel) context.getService(sref);
        if (level != startLevel.getStartLevel()) {
            final CountDownLatch latch = new CountDownLatch(1);
            context.addFrameworkListener(new FrameworkListener() {
                public void frameworkEvent(FrameworkEvent event) {
                    if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED && level == startLevel.getStartLevel()) {
                        latch.countDown();
                    }
                }
            });
            startLevel.setStartLevel(level);
            if (latch.await(timeout, units) == false)
                throw new TimeoutException("Timeout changing start level");
        }
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.startlevel.StartLevel

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.