Package org.osgi.service.startlevel

Examples of org.osgi.service.startlevel.StartLevel


     * @return true if the bundle has start level minor than 50
     */
    public static boolean isASystemBundle(BundleContext bundleContext, Bundle bundle) {
        ServiceReference ref = bundleContext.getServiceReference(StartLevel.class.getName());
        if (ref != null) {
            StartLevel sl = (StartLevel) bundleContext.getService(ref);
            if (sl != null) {
                int level = sl.getBundleStartLevel(bundle);
                int sbsl = 49;
                final String sbslProp = bundleContext.getProperty( "karaf.systemBundlesStartLevel" );
                if (sbslProp != null) {
                    try {
                       sbsl = Integer.valueOf( sbslProp );
View Full Code Here


        this.bundleStateListenerFactories = bundleStateListenerFactories;
    }

    protected Object doExecute() throws Exception {
        ServiceReference ref = getBundleContext().getServiceReference(StartLevel.class.getName());
        StartLevel sl = null;
        if (ref != null) {
            sl = (StartLevel) getBundleContext().getService(ref);
        }
        if (sl == null) {
            System.out.println("StartLevel service is unavailable.");
        }

        ServiceReference pkgref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
        PackageAdmin admin = null;
        if (pkgref != null) {
            admin = (PackageAdmin) getBundleContext().getService(pkgref);
            if (admin == null) {
                System.out.println("PackageAdmin service is unavailable.");
            }
        }

        Bundle[] bundles = getBundleContext().getBundles();
        if (bundles != null) {
            // Determine threshold
            final String sbslProp = bundleContext.getProperty("karaf.systemBundlesStartLevel");
            if (sbslProp != null) {
                try {
                   if (bundleLevelThreshold < 0) {
                       bundleLevelThreshold = Integer.valueOf( sbslProp );
                   }
                }
                catch( Exception ignore ) {
                   // ignore
                }
            }
            // Display active start level.
            if (sl != null) {
                System.out.println("START LEVEL " + sl.getStartLevel() +
                                   " , List Threshold: " + bundleLevelThreshold);
            }

            // Print column headers.
            String msg = " Name";
            if (showLoc) {
               msg = " Location";
            }
            else if (showSymbolic) {
               msg = " Symbolic name";
            }
            else if (showUpdate) {
               msg = " Update location";
            }
            String level = (sl == null) ? "" : "  Level ";
            String headers = "   ID   State       ";
            for (BundleStateListener.Factory factory : bundleStateListenerFactories) {
                BundleStateListener listener = factory.getListener();
                if (listener != null) {
                    headers += "  " + listener.getName() + " ";
                }
            }
            headers += level + msg;
            System.out.println(headers);
            for (int i = 0; i < bundles.length; i++) {
              if (sl.getBundleStartLevel(bundles[i]) >= bundleLevelThreshold) {
                  // Get the bundle name or location.
                  String name = (String) bundles[i].getHeaders().get(Constants.BUNDLE_NAME);
                  // If there is no name, then default to symbolic name.
                  name = (name == null) ? bundles[i].getSymbolicName() : name;
                  // If there is no symbolic name, resort to location.
                  name = (name == null) ? bundles[i].getLocation() : name;
 
                  // Overwrite the default value is the user specifically
                  // requested to display one or the other.
                  if (showLoc) {
                      name = bundles[i].getLocation();
                  }
                  else if (showSymbolic) {
                      name = bundles[i].getSymbolicName();
                      name = (name == null) ? "<no symbolic name>" : name;
                  }
                  else if (showUpdate) {
                      name = (String) bundles[i].getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
                      name = (name == null) ? bundles[i].getLocation() : name;
                  }
                  // Show bundle version if not showing location.
                  String version = (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION);
                  name = (!showLoc && !showUpdate && (version != null)) ? name + " (" + version + ")" : name;
                  long l = bundles[i].getBundleId();
                  String id = String.valueOf(l);
                  if (sl == null) {
                      level = "1";
                  }
                  else {
                      level = String.valueOf(sl.getBundleStartLevel(bundles[i]));
                  }
                  while (level.length() < 5) {
                      level = " " + level;
                  }
                  while (id.length() < 4) {
View Full Code Here

        ServiceReference ref = getBundleContext().getServiceReference(StartLevel.class.getName());
        if (ref == null) {
            System.out.println("StartLevel service is unavailable.");
            return;
        }
        StartLevel sl = getService(StartLevel.class, ref);
        if (sl == null) {
            System.out.println("StartLevel service is unavailable.");
            return;
        }

        if (level == null) {
            System.out.println("Level " + sl.getBundleStartLevel(bundle));
        }
        else if ((level < 50) && (sl.getBundleStartLevel(bundle) > 50) && !force){
            for (;;) {
                ConsoleReader reader = (ConsoleReader) session.get(".jline.reader");
                String msg = "You are about to designate bundle as a system bundle.  Do you wish to continue (yes/no): ";
                String str = reader.readLine(msg);
                if ("yes".equalsIgnoreCase(str)) {
                    sl.setBundleStartLevel(bundle, level);
                    break;
                } else if ("no".equalsIgnoreCase(str)) {
                    break;
                }
            }
        } else {
            sl.setBundleStartLevel(bundle, level);
        }
    }
View Full Code Here

        // Check if we want to convert URLs to maven style
        boolean convertToMavenUrls = Boolean.parseBoolean(configProps.getProperty(PROPERTY_CONVERT_TO_MAVEN_URL, "true"));

        // 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(org.osgi.service.startlevel.StartLevel.class.getName()));

        // Set the default bundle start level
        int ibsl = 60;
        try {
            String str = configProps.getProperty("karaf.startlevel.bundle");
            if (str != null) {
                ibsl = Integer.parseInt(str);
            }
        } catch (Throwable t) {
        }
        sl.setInitialBundleStartLevel(ibsl);

        // If we have a clean state, install everything
        if (framework.getBundleContext().getBundles().length == 1) {
            // The auto-install property specifies a space-delimited list of
            // bundle URLs to be automatically installed into each new profile;
View Full Code Here

    }

    protected void setStartLevel(int level) throws Exception {
        BundleContext ctx = framework.getBundleContext();
        ServiceReference[] refs = ctx.getServiceReferences(StartLevel.class.getName(), null);
        StartLevel sl = (StartLevel) ctx.getService(refs[0]);
        sl.setStartLevel(level);
    }
View Full Code Here

  @Override
  public void start(BundleContext context) throws Exception {
    System.out.println("starting platform launcher");
    ServiceReference startLevelRef =
        context.getServiceReference(StartLevel.class.getName());
    StartLevel startLevel = (StartLevel) context.getService(startLevelRef);
    final int currentBundleStartLevel =
        startLevel.getBundleStartLevel(context.getBundle());
    startLevel.setStartLevel(currentBundleStartLevel);
    final int originalStartLevel = startLevel.getStartLevel();
    int nextLevel = currentBundleStartLevel + 1;
    Enumeration<URL> bundleJars =
        context.getBundle().findEntries("platform-bundles", "*.jar", true);
    Set<MavenArtifactDesc> artDescs = new HashSet<MavenArtifactDesc>();

    while (bundleJars.hasMoreElements()) {
      MavenArtifactDesc artDesc =
          MavenArtifactDesc.parseFromURL(bundleJars.nextElement());
      artDescs.add(artDesc);
    }
    ClerezzaApp.installBundles(context, artDescs, nextLevel);

    final int newStartLevel =
        originalStartLevel > nextLevel + 1 ? originalStartLevel : nextLevel + 1;
    startLevel.setStartLevel(newStartLevel);
    if (startLevel.getInitialBundleStartLevel() < nextLevel + 1) {
      startLevel.setInitialBundleStartLevel(nextLevel + 1);
    }
    System.out.println("uninstalling platform launcher");
    context.getBundle().uninstall();
  }
View Full Code Here

      }
    }

    ServiceReference startLevelRef =
        context.getServiceReference(StartLevel.class.getName());
    StartLevel startLevel = (StartLevel) context.getService(startLevelRef);
    for (Bundle bundle : installedBundles) {
      startLevel.setBundleStartLevel(bundle, nextLevel);
    }
    return installedBundles;
  }
View Full Code Here

      }
    }

    ServiceReference startLevelRef =
        bundleContext.getServiceReference(StartLevel.class.getName());
    StartLevel startLevelService = (StartLevel) bundleContext.getService(startLevelRef);
    startLevelService.setInitialBundleStartLevel(startLevel + 1);
    startLevelService.setStartLevel(startLevel + 20);
  }
View Full Code Here

    if (level == 0 || bundle == null)
      return;
    // Set the start level of the bundle if we are able.
    ServiceReference startref = bundleContext.getServiceReference(StartLevel.class.getName());
    if (startref != null) {
      StartLevel start = (StartLevel) bundleContext.getService(startref);
      if (start != null) {
        start.setBundleStartLevel(bundle, level);
      }
      bundleContext.ungetService(startref);
    }
  }
View Full Code Here

        ServiceReference packageAdminRef = mock(ServiceReference.class);
        PackageAdmin packageAdmin = mock(PackageAdmin.class);
        when(context.getServiceReference(PackageAdmin.class.getName())).thenReturn(packageAdminRef);
        when(context.getService(packageAdminRef)).thenReturn(packageAdmin);
        ServiceReference startLevelRef = mock(ServiceReference.class);
        StartLevel startLevel = mock(StartLevel.class);
        when(context.getServiceReference(StartLevel.class.getName())).thenReturn(startLevelRef);
        when(context.getService(startLevelRef)).thenReturn(startLevel);

        BundleStateMBeanHandler handler = new BundleStateMBeanHandler(context, logger);
        handler.open();
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.