当前位置: 首页>>代码示例>>Java>>正文


Java FrameworkFactory类代码示例

本文整理汇总了Java中org.osgi.framework.launch.FrameworkFactory的典型用法代码示例。如果您正苦于以下问题:Java FrameworkFactory类的具体用法?Java FrameworkFactory怎么用?Java FrameworkFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FrameworkFactory类属于org.osgi.framework.launch包,在下文中一共展示了FrameworkFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFrameworkFactory

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
/**
 * Simple method to parse META-INF/services file for framework factory.
 * Currently, it assumes the first non-commented line is the class name
 * of the framework factory implementation.
 * @return The created <tt>FrameworkFactory</tt> instance.
 * @throws Exception if any errors occur.
**/
private static FrameworkFactory getFrameworkFactory() throws Exception {
  URL url = Main.class.getClassLoader().getResource(
    "META-INF/services/org.osgi.framework.launch.FrameworkFactory");
  if (url != null) {
    BufferedReader br =
      new BufferedReader(new InputStreamReader(url.openStream()));
    try {
      for (String s = br.readLine(); s != null; s = br.readLine()) {
        s = s.trim();
        // Try to load first non-empty, non-commented line.
        if ((s.length() > 0) && (s.charAt(0) != '#')) {
          return (FrameworkFactory) Class.forName(s).newInstance();
        }
      }
    } finally {
      if (br != null) br.close();
    }
  }

  throw new Exception("Could not find framework factory.");
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:29,代码来源:Main.java

示例2: create

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
@Override
public TestContainer[] create(ExamSystem system) {
    // we use ServiceLoader to load the OSGi Framework Factory
    List<TestContainer> containers = new ArrayList<>();
    Iterator<FrameworkFactory> factories = ServiceLoader.load(FrameworkFactory.class)
            .iterator();
    boolean factoryFound = false;

    while (factories.hasNext()) {
        try {
            containers.add(new MotechNativeTestContainer(system, factories.next()));
            factoryFound = true;
        } catch (IOException e) {
            throw new TestContainerException("Problem initializing container.", e);
        }
    }

    if (!factoryFound) {
        throw new TestContainerException(
                "No service org.osgi.framework.launch.FrameworkFactory found in META-INF/services on classpath");
    }

    return containers.toArray(new TestContainer[containers.size()]);
}
 
开发者ID:motech,项目名称:motech,代码行数:25,代码来源:MotechNativeTestContainerFactory.java

示例3: testGuiceWorksInOSGiContainer

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
public void testGuiceWorksInOSGiContainer() throws Throwable {

    // ask framework to clear cache on startup
    Properties properties = new Properties();
    properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
    properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");

    // test each available OSGi framework in turn
    for (FrameworkFactory frameworkFactory : ServiceLoader.load(FrameworkFactory.class)) {
      Framework framework = frameworkFactory.newFramework(properties);

      framework.start();
      BundleContext systemContext = framework.getBundleContext();

      // load all the necessary bundles and start the OSGi test bundle
      /*if[AOP]*/
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
      /*end[AOP]*/
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
      systemContext.installBundle("reference:file:" + GUICE_JAR);
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();

      framework.stop();
    }
  }
 
开发者ID:google,项目名称:guice,代码行数:27,代码来源:OSGiContainerTest.java

示例4: start

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
@Override
public void start() {
    List<FrameworkFactory> frameworkFactories = IteratorUtils.toList(ServiceLoader.load(FrameworkFactory.class).iterator());

    if (frameworkFactories.size() != 1) {
        throw new RuntimeException("One OSGi framework expected. Got " + frameworkFactories.size() + ": " + frameworkFactories);
    }

    try {
        framework = getFelixFramework(frameworkFactories);
        framework.start();
        registerInternalServices(framework.getBundleContext());
    } catch (BundleException e) {
        throw new RuntimeException("Failed to initialize OSGi framework", e);
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:17,代码来源:FelixGoPluginOSGiFramework.java

示例5: getFrameworkFactory

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
private static FrameworkFactory getFrameworkFactory() throws Exception {
	java.net.URL url = FrameworkRunner.class.getClassLoader().getResource(
			"META-INF/services/org.osgi.framework.launch.FrameworkFactory");
	if (url != null) {
		BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
		try {
			for (String s = br.readLine(); s != null; s = br.readLine()) {
				s = s.trim();
				// Try to load first non-empty, non-commented line.
				if ((s.length() > 0) && (s.charAt(0) != '#')) {
					Debug.message("> FrameworkFactory class name: " + s);
					return (FrameworkFactory) Class.forName(s).newInstance();
				}
			}
		} finally {
			if (br != null)
				br.close();
		}
	}

	throw new Exception("Could not find framework factory.");
}
 
开发者ID:codessentials,项目名称:felinx,代码行数:23,代码来源:FrameworkRunner.java

示例6: OSGiFrameworkWrapper

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public OSGiFrameworkWrapper(File frameworkStorageDirectory, File bootBundlesDirectory, File hotBundlesDirectory) throws IOException {
    Map<String, String> config = new HashMap<>();
    // https://svn.apache.org/repos/asf/felix/releases/org.apache.felix.main-1.2.0/doc/launching-and-embedding-apache-felix.html#LaunchingandEmbeddingApacheFelix-configproperty
    config.put("felix.embedded.execution", "true");
    config.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, "J2SE-1.8");
    config.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    config.put(Constants.FRAMEWORK_STORAGE, frameworkStorageDirectory.getAbsolutePath());
    // not FRAMEWORK_SYSTEMPACKAGES but _EXTRA
    config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, new PackagesBuilder()
            .addPackage("org.slf4j", "1.7")
            .addPackage("ch.vorburger.minecraft.osgi.api")
            .addPackage("ch.vorburger.minecraft.utils")
            .addPackageWithSubPackages("com.google.common", "17.0.0")
            .addPackageWithSubPackages("com.flowpowered.math")
            .addPackageWithSubPackages("org.spongepowered.api")
            .addPackage("javax.inject")
            .addPackageWithSubPackages("com.google.inject")
            .build()
        );

    FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
    framework = frameworkFactory.newFramework(config);

    this.bootBundlesDirectory = bootBundlesDirectory;
    this.hotBundlesDirectory = hotBundlesDirectory;
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:28,代码来源:OSGiFrameworkWrapper.java

示例7: getFrameworkFactory

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
/**
 * Simple method to parse META-INF/services file for framework factory.
 * Currently, it assumes the first non-commented line is the class name
 * of the framework factory implementation.
 * @return The created <tt>FrameworkFactory</tt> instance.
 * @throws Exception if any errors occur.
**/
private static FrameworkFactory getFrameworkFactory() throws Exception
{
    URL url = Main.class.getClassLoader().getResource(
        "META-INF/services/org.osgi.framework.launch.FrameworkFactory");
    if (url != null)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
        try
        {
            for (String s = br.readLine(); s != null; s = br.readLine())
            {
                s = s.trim();
                // Try to load first non-empty, non-commented line.
                if ((s.length() > 0) && (s.charAt(0) != '#'))
                {
                    return (FrameworkFactory) Class.forName(s).newInstance();
                }
            }
        }
        finally
        {
            if (br != null) br.close();
        }
    }

    throw new Exception("Could not find framework factory.");
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:35,代码来源:Main.java

示例8: startOSGiContainer

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
@BeforeClass
public static void startOSGiContainer() throws BundleException, IOException {
	assertNull("OSGi framework is expected to be stopped.", osgiFramework);
	removeStorageDirectory();
	Map<String, String> map = new HashMap<>();
	map.put(Constants.FRAMEWORK_STORAGE, STORAGE_DIRECTORY);
	ServiceLoader<FrameworkFactory> frameworkFactory = ServiceLoader
			.load(FrameworkFactory.class);
	osgiFramework = frameworkFactory.iterator().next().newFramework(map);
	osgiFramework.start();
}
 
开发者ID:PureSolTechnologies,项目名称:Purifinity,代码行数:12,代码来源:AbstractBundleTest.java

示例9: start

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
/**
 * Starts the OSGi framework, installs and starts the bundles.
 *
 * @throws BundleException
 *             if the framework could not be started
 */
public void start() throws BundleException {
	logger.info("Loading the OSGi Framework Factory");
	FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator()
			.next();

	logger.info("Creating the OSGi Framework");
	framework = frameworkFactory.newFramework(frameworkConfiguration);
	logger.info("Starting the OSGi Framework");
	framework.start();

	context = framework.getBundleContext();
	context.addServiceListener(new ServiceListener() {
		public void serviceChanged(ServiceEvent event) {
			ServiceReference serviceReference = event.getServiceReference();
			if (event.getType() == ServiceEvent.REGISTERED) {
				Object property = serviceReference
						.getProperty("org.springframework.context.service.name");
				if (property != null) {
					addStartedSpringContext(property.toString());
				}
			}
			logger.fine((event.getType() == ServiceEvent.REGISTERED ? "Registering : "
					: "Unregistering : ") + serviceReference);
		}
	});

	installedBundles = installBundles(bundlesToInstall);

	List<Bundle> bundlesToStart = new ArrayList<Bundle>();
	for (Bundle bundle : installedBundles) {
		if ("org.springframework.osgi.extender".equals(bundle.getSymbolicName())) {
			springOsgiExtender = bundle;
		} else {
			bundlesToStart.add(bundle);
		}
	}
	startBundles(bundlesToStart);
}
 
开发者ID:apache,项目名称:incubator-taverna-osgi,代码行数:45,代码来源:OsgiLauncher.java

示例10: getFramework

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
protected Framework getFramework()
{
    Iterator<FrameworkFactory> it = ServiceLoader.load(org.osgi.framework.launch.FrameworkFactory.class).iterator();
    assertTrue("No OSGI implementation found in classpath", it.hasNext());
    
    Map<String,String> osgiConfig = new HashMap<String,String>();
    //osgiConfig.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY, "");
    osgiConfig.put("org.osgi.framework.storage", CACHE_FOLDER);
    osgiConfig.put("org.osgi.framework.storage.clean", "onFirstInit");
    Framework fw = it.next().newFramework(osgiConfig);
    
    return fw;
}
 
开发者ID:sensiasoft,项目名称:sensorhub,代码行数:14,代码来源:TestOsgi.java

示例11: initFramework

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
private void initFramework(Properties properties) throws Exception{
	String factoryClass = properties.getProperty(FrameworkFactory.class.getName());
	if(factoryClass == null)
		throw new Exception("No FrameworkFactory available!");
	
	FrameworkFactory frameworkFactory = (FrameworkFactory) Class.forName(factoryClass).newInstance();
	
	Map<String, String> config = new HashMap<String, String>();
	String runproperties = properties.getProperty("-runproperties");
	if(runproperties!=null){
		StringTokenizer st = new StringTokenizer(runproperties, ",");
		while(st.hasMoreTokens()){
			String runproperty = st.nextToken();
			int equalsIndex = runproperty.indexOf('=');
			if(equalsIndex!=-1){
				String key = runproperty.substring(0, equalsIndex);
				String value = runproperty.substring(equalsIndex+1);
				config.put(key, value);
			}
		}
	}
	
	// point storage dir to internal storage
	config.put("org.osgi.framework.storage", (String)properties.getProperty("cacheDir"));
	// add framework exports
	config.put("org.osgi.framework.system.packages.extra", (String)properties.get("-runsystempackages"));
	framework = frameworkFactory.newFramework(config);
	framework.start();
}
 
开发者ID:ibcn-cloudlet,项目名称:androsgi,代码行数:30,代码来源:OSGiRuntime.java

示例12: start

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
/**
 * Starts a Carbon server instance. This method returns only after the server instance stops completely.
 *
 * @throws Exception if error occurred
 */
public void start() throws Exception {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Starting Carbon server instance.");
    }

    // Sets the server start time.
    System.setProperty(CARBON_START_TIME, Long.toString(System.currentTimeMillis()));

    try {
        // Creates an OSGi framework instance.
        ClassLoader fwkClassLoader = createOSGiFwkClassLoader();
        FrameworkFactory fwkFactory = loadOSGiFwkFactory(fwkClassLoader);
        framework = fwkFactory.newFramework(config.getProperties());

        setServerCurrentStatus(ServerStatus.STARTING);
        // Notify Carbon server start.
        dispatchEvent(CarbonServerEvent.STARTING);

        // Initialize and start OSGi framework.
        initAndStartOSGiFramework(framework);

        // Loads initial bundles listed in the launch.properties file.
        loadInitialBundles(framework.getBundleContext());

        setServerCurrentStatus(ServerStatus.STARTED);
        // This thread waits until the OSGi framework comes to a complete shutdown.
        waitForServerStop(framework);

        setServerCurrentStatus(ServerStatus.STOPPING);
        // Notify Carbon server shutdown.
        dispatchEvent(CarbonServerEvent.STOPPING);

    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:wso2,项目名称:carbon-kernel,代码行数:42,代码来源:CarbonServer.java

示例13: loadOSGiFwkFactory

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
/**
 * Creates a new service loader for the given service type and class loader.
 * Load OSGi framework factory for the given class loader.
 *
 * @param classLoader The class loader to be used to load provider-configurations
 * @return framework factory for creating framework instances
 */
private FrameworkFactory loadOSGiFwkFactory(ClassLoader classLoader) {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "Loading OSGi FrameworkFactory implementation class from the classpath.");
    }

    ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class, classLoader);
    if (!loader.iterator().hasNext()) {
        throw new RuntimeException("An implementation of the " + FrameworkFactory.class.getName() +
                " must be available in the classpath");
    }
    return loader.iterator().next();
}
 
开发者ID:wso2,项目名称:carbon-kernel,代码行数:20,代码来源:CarbonServer.java

示例14: initialize

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
private void initialize() throws BundleException, URISyntaxException {

        Map<String, String> configMap = loadProperties();
        System.setProperty(LOG_CONFIG_FILE_PROPERTY, configMap.get(LOG_CONFIG_FILE_PROPERTY));
   
        System.out.println("Building OSGi Framework");
        FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
        Framework framework = frameworkFactory.newFramework(configMap);

        framework.init();
        // (9) Use the system bundle context to process the auto-deploy
        // and auto-install/auto-start properties.
        AutoProcessor.process(configMap, framework.getBundleContext());
        // (10) Start the framework.
        System.out.println("Starting OSGi Framework");
        framework.start();
     
        BundleContext context = framework.getBundleContext();
        // declarative services dependency is necessary, otherwise they won't be picked up!
        loadScrBundle(context);

        try {
            framework.waitForStop(0);
        } catch (InterruptedException e) {
        	appendToFile(e);
        	showErrorMessage();
        }
        System.exit(0);
    }
 
开发者ID:burningrain,项目名称:planetBot,代码行数:30,代码来源:Launcher.java

示例15: testGuiceWorksInOSGiContainer

import org.osgi.framework.launch.FrameworkFactory; //导入依赖的package包/类
public void testGuiceWorksInOSGiContainer()
      throws Throwable {

    // ask framework to clear cache on startup
    Properties properties = new Properties();
    properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
    properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");

    // test each available OSGi framework in turn
    Iterator<FrameworkFactory> f = ServiceRegistry.lookupProviders(FrameworkFactory.class);
    while (f.hasNext()) {
      Framework framework = f.next().newFramework(properties);

      framework.start();
      BundleContext systemContext = framework.getBundleContext();

      // load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
      systemContext.installBundle("reference:file:" + GUICE_JAR);
      systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();

      framework.stop();
    }
  }
 
开发者ID:cgruber,项目名称:guice-old,代码行数:29,代码来源:OSGiContainerTest.java


注:本文中的org.osgi.framework.launch.FrameworkFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。