Package org.osgi.service.startlevel

Examples of org.osgi.service.startlevel.StartLevel


    }
  }

  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);
    FrameworkListener listener = new FrameworkListener() {
      public void frameworkEvent(FrameworkEvent event) {
        if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED && startLevel.getStartLevel() == value)
          semaphore.release();
      }
    };
    context.addFrameworkListener(listener);
    startLevel.setStartLevel(value);
    context.ungetService(reference);
    updateSplash(semaphore, listener);
  }
View Full Code Here


        super(BundlesMBean.class);
    }

    public TabularData list() throws Exception {
        ServiceReference startLevelReference = bundleContext.getServiceReference(StartLevel.class.getName());
        StartLevel startLevel = null;
        if (startLevelReference != null) {
            startLevel = (StartLevel) bundleContext.getService(startLevelReference);
        }

        CompositeType bundleType = new CompositeType("Bundle", "OSGi Bundle",
                new String[]{"ID", "Name", "Version", "Start Level", "State"},
                new String[]{"ID of the Bundle", "Name of the Bundle", "Version of the Bundle", "Start Level of the Bundle", "Current State of the Bundle"},
                new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING});
        TabularType tableType = new TabularType("Bundles", "Tables of all Bundles", bundleType, new String[]{"ID"});
        TabularData table = new TabularDataSupport(tableType);

        Bundle[] bundles = bundleContext.getBundles();

        for (int i = 0; i < bundles.length; i++) {
            try {
                int bundleStartLevel = 1;
                if (startLevel != null) {
                    bundleStartLevel = startLevel.getBundleStartLevel(bundles[i]);
                }
                int bundleState = bundles[i].getState();
                String bundleStateString;
                if (bundleState == Bundle.ACTIVE)
                    bundleStateString = "ACTIVE";
View Full Code Here

    public int getStartLevel(String bundleId) throws Exception {
        ServiceReference startLevelReference = bundleContext.getServiceReference(StartLevel.class.getName());
        if (startLevelReference == null) {
            throw new IllegalStateException("StartLevel service is not available");
        }
        StartLevel startLevel = (StartLevel) bundleContext.getService(startLevelReference);
        if (startLevel == null) {
            throw new IllegalStateException("StartLevel service is not available");
        }

        BundlesSelector selector = new BundlesSelector(bundleContext);
        List<Bundle> bundles = selector.selectBundles(bundleId);

        if (bundles.size() != 1) {
            throw new IllegalArgumentException("Provided bundle Id doesn't return any bundle or more than one bundle selected");
        }

        int bundleStartLevel = startLevel.getBundleStartLevel(bundles.get(0));
        bundleContext.ungetService(startLevelReference);
        return bundleStartLevel;
    }
View Full Code Here

    public void setStartLevel(String bundleId, int bundleStartLevel) throws Exception {
        ServiceReference startLevelReference = bundleContext.getServiceReference(StartLevel.class.getName());
        if (startLevelReference == null) {
            throw new IllegalStateException("StartLevel service is not available");
        }
        StartLevel startLevel = (StartLevel) bundleContext.getService(startLevelReference);
        if (startLevel == null) {
            throw new IllegalStateException("StartLevel service is not available");
        }

        BundlesSelector selector = new BundlesSelector(bundleContext);
        List<Bundle> bundles = selector.selectBundles(bundleId);

        for (Bundle bundle : bundles) {
            startLevel.setBundleStartLevel(bundle, bundleStartLevel);
        }

        bundleContext.ungetService(startLevelReference);
    }
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

    private void startBundles(BundleContext context) 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) {
            Bundle bundle = context.installBundle(info.bundleLocation);          
            if (info.startLevel > 0) {
                sl.setBundleStartLevel(bundle, info.startLevel);
            }
            info.bundle = bundle;
        }

        for (BundleInfo info : startList) {
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

    private final Integer getStartLevel( Bundle bundle )
    {
        if ( bundle.getState() != Bundle.UNINSTALLED )
        {
            StartLevel sl = getStartLevel();
            if ( sl != null )
            {
                return new Integer( sl.getBundleStartLevel( bundle ) );
            }
        }

        // bundle has been uninstalled or StartLevel service is not available
        return null;
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.