Package org.osgi.framework.launch

Examples of org.osgi.framework.launch.Framework


    System.setProperty("karaf.home", home.toString());
    System.setProperty("karaf.data", data.toString());

    main = new Main(args);
    main.launch();
    Framework framework = main.getFramework();
    Bundle[] bundles = framework.getBundleContext().getBundles();
    Assert.assertEquals(3, bundles.length);
   
    // Give the framework some time to start the bundles
    Thread.sleep(1000);

    Bundle bundle1 = framework.getBundleContext().getBundle("mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/1.0.0");
    Assert.assertEquals(Bundle.ACTIVE, bundle1.getState());

    Bundle bundle2 = framework.getBundleContext().getBundle("pax-url-mvn.jar");
    Assert.assertEquals(Bundle.ACTIVE, bundle2.getState());
  }
View Full Code Here


    System.setProperty("karaf.data", data.toString());
        System.setProperty("karaf.framework.factory", "org.apache.felix.framework.FrameworkFactory");

        main = new Main(args);
        main.launch();
        Framework framework = main.getFramework();
        String activatorName = TimeoutShutdownActivator.class.getName().replace('.', '/') + ".class";
        Bundle bundle = framework.getBundleContext().installBundle("foo",
                TinyBundles.bundle()
                    .set( Constants.BUNDLE_ACTIVATOR, TimeoutShutdownActivator.class.getName() )
                    .add( activatorName, getClass().getClassLoader().getResourceAsStream( activatorName ) )
                    .build( withBnd() )
        );
View Full Code Here

            else if (osgidep != null) {
                Bundle bundle = osgidep.getAttachment(Bundle.class);
                BundleAssociation.setBundle(bundle);
                ServiceContainerAssociation.setServiceContainer(serviceContainer);
                ServerDeploymentManagerAssociation.setServerDeploymentManager(deploymentManager);
                Framework framework = awaitActiveOSGiFramework();
                BundleContextAssociation.setBundleContext(framework.getBundleContext());
                testClass = bundle.loadClass(className);
            }

            if (testClass == null)
                throw new ClassNotFoundException(className);
View Full Code Here

            map.put(entry.getKey().toString(), entry.getValue().toString());
        }
        map.put(FelixConstants.LOG_LOGGER_PROP, new FelixLogger());

        // Create the framework instance
        Framework framework = new Felix(map);
        framework.init();
        framework.start();

        syscontext = framework.getBundleContext();
    }
View Full Code Here

            if (key.startsWith("osgi.") || key.startsWith("org.osgi.")) {
                props.put(key, System.getProperty(key));
            }
        }

        Framework framework = null;
       
        // Iterate over frameworks on the classpath to see if one matches. See the
        // Javadoc for org.osgi.framework.launch.FrameworkFactory for information
        // about using ServiceLoader to find the available framework implementations.
        for (FrameworkFactory factory : ServiceLoader.load(FrameworkFactory.class)) {
            framework = factory.newFramework(props);
        }

        if (framework == null) {
            throw new RuntimeException("Cannot find an OSGi framework");
        }
        try {
            framework.start();
        } catch (BundleException e) {
            throw new RuntimeException("Cannot start OSGi framework", e);
        }
       
        BundleContext bc = framework.getBundleContext();

        startOSGIBundles(bc);
        startPlatformBundles(bc);
    }
View Full Code Here

      // Configure PojoSR
      Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
      pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());
     
      // Start PojoSR 'framework'
      Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
      framework.init();
      framework.start();
     
      // Look for indexer and run index generation
      ServiceTracker tracker = new ServiceTracker(framework.getBundleContext(), ResourceIndexer.class.getName(), null);
      tracker.open();
      ResourceIndexer index = (ResourceIndexer) tracker.waitForService(1000);
      if (index == null)
        throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");

      // Process arguments
      Set<File> fileList = new LinkedHashSet<File>();
      Map<String, String> config = new HashMap<String, String>();
      File outputFile = processArgs(args, config, fileList, framework.getBundleContext());
     
      // Run
      if (fileList.isEmpty())
        printUsage();
      else try {
View Full Code Here

      // Configure PojoSR
      Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
      pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());

      // Start PojoSR 'framework'
      Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
      framework.init();
      framework.start();

      // Look for indexer and run index generation
      ServiceTracker tracker = new ServiceTracker(framework.getBundleContext(), ResourceIndexer.class.getName(), null);
      tracker.open();
      ResourceIndexer index = (ResourceIndexer) tracker.waitForService(1000);
      if (index == null)
        throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");

      // Process arguments
      Set<File> fileList = new LinkedHashSet<File>();
      Map<String, String> config = new HashMap<String, String>();
      File outputFile = processArgs(args, System.err, config, fileList, framework.getBundleContext());
      if (outputFile == null) {
        System.exit(1);
      }

      boolean verbose = Boolean.parseBoolean(config.get(ResourceIndexer.VERBOSE));
View Full Code Here

      // Configure PojoSR
      Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
      pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());

      // Start PojoSR 'framework'
      Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
      framework.init();
      framework.start();

      // Look for indexer and run index generation
      ServiceTracker tracker = new ServiceTracker(framework.getBundleContext(), ResourceIndexer.class.getName(), null);
      tracker.open();
      ResourceIndexer index = (ResourceIndexer) tracker.waitForService(1000);
      if (index == null)
        throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");
View Full Code Here

      Properties config = new Properties();
      config.put(Constants.FRAMEWORK_STORAGE, storageDir.getAbsolutePath());
      copyFrameworkConfig(props, config);

      // CREATE FRAMEWORK AND SYNC BUNDLES
      Framework framework = createAndRunFramework(config);
      if(framework == null) return;
      BundleContext fwContext = framework.getBundleContext();

      // CREATE INSTALLER
      Thread installerThread = createInstaller(fwContext, props);
     
      // MAIN THREAD EXECUTOR
      if(framework.getState() == Bundle.ACTIVE) // Check the framework hasn't already shutdown
          createAndRunMainThreadExecutor(fwContext, "main");

      // SHUTDOWN
      try {
        logger.info("Waiting for the framework to stop.");
        framework.waitForStop(0);
        if(installerThread != null)
          installerThread.interrupt();
        logger.info("Framework stopped.");
      } catch (InterruptedException e) {
        // Ignore
View Full Code Here

    if (fwkFactory == null) {
      logger.severe("No FrameworkFactory service providers available.");
      return null;
    }

    Framework framework = fwkFactory.newFramework(config);
    logger.info("Created framework");
    try {
      framework.start();
      logger.info("Started framework");
    } catch (BundleException e) {
      logger.log(Level.SEVERE, "Error starting framework.", e);
      return null;
    }
View Full Code Here

TOP

Related Classes of org.osgi.framework.launch.Framework

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.