本文整理汇总了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.");
}
示例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()]);
}
示例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();
}
}
示例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);
}
}
示例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.");
}
示例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;
}
示例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.");
}
示例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();
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
示例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);
}
示例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();
}
}