本文整理汇总了Java中org.osgi.framework.launch.FrameworkFactory.newFramework方法的典型用法代码示例。如果您正苦于以下问题:Java FrameworkFactory.newFramework方法的具体用法?Java FrameworkFactory.newFramework怎么用?Java FrameworkFactory.newFramework使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.framework.launch.FrameworkFactory
的用法示例。
在下文中一共展示了FrameworkFactory.newFramework方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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);
}
示例4: 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();
}
示例5: 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);
}
}
示例6: 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);
}
示例7: start
import org.osgi.framework.launch.FrameworkFactory; //导入方法依赖的package包/类
public void start ( final String[] args ) throws Exception
{
if ( this.started )
{
return;
}
this.started = true;
this.debug = Boolean.getBoolean ( "org.eclipse.scada.utils.osgi.daemon.debug" ); //$NON-NLS-1$
if ( this.debug )
{
this.logger = new Formatter ( System.out );
}
final ServiceLoader<FrameworkFactory> loader = ServiceLoader.load ( FrameworkFactory.class );
final Iterator<FrameworkFactory> i = loader.iterator ();
if ( !i.hasNext () )
{
throw new IllegalStateException ( "No FrameworkFactory found!" );
}
final FrameworkFactory factory = i.next ();
this.properties = new HashMap<String, String> ();
for ( final String arg : args )
{
final String[] toks = arg.split ( "=", 2 );
if ( toks.length >= 2 )
{
this.properties.put ( toks[0], toks[1] );
}
else
{
this.properties.put ( toks[0], null );
}
}
this.properties.put ( Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "4" );
this.framework = factory.newFramework ( this.properties );
this.framework.init ();
try
{
loadStartBundles ( this.framework, this.properties );
}
catch ( final Exception e )
{
this.framework.stop ();
throw e;
}
this.framework.start ();
}
示例8: start
import org.osgi.framework.launch.FrameworkFactory; //导入方法依赖的package包/类
public void start()
{
frame = new SplashFrame();
final SwingWorker<Void, Integer> worker = new SwingWorker<Void, Integer>() {
protected Void doInBackground() throws Exception {
try {
String factoryClass = getFactoryClass();
FrameworkFactory factory = (FrameworkFactory) Class.forName(factoryClass).newInstance();
Framework framework = factory.newFramework(getLaunchProperties());
framework.start();
context = framework.getBundleContext();
BundleLoader loader = new BundleLoader(context);
/* load embedded bundles, i.e. all bundles that are inside pathvisio.jar */
System.out.println("Installing bundles that are embedded in the jar.");
Set<String> jarNames = loader.getResourceListing(PathVisioMain.class);
int cnt = 0;
int total = jarNames.size() + pluginLocations.size();
for (String s : jarNames)
{
String text = (s.length() > 50) ? s.substring(0, 50) : s;
frame.getTextLabel().setText("<html>Install " + text + ".</html>");
frame.repaint();
publish(100 * (++cnt) / total);
loader.installEmbeddedBundle(s);
}
frame.getTextLabel().setText("<html>Install active plugins.</html>");
frame.repaint();
System.out.println("Installing bundles from directories specified on the command-line.");
for(String location : pluginLocations) {
publish(100 * (++cnt) / total);
loader.loadFromParameter(location);
}
startBundles(context, loader.getBundles());
frame.getTextLabel().setText("Start application.");
frame.repaint();
} catch(Exception ex) {
reportException("Startup Error", ex);
ex.printStackTrace();
}
return null;
}
protected void process(List<Integer> chunks) {
for (Integer chunk : chunks) {
frame.getProgressBar().setString("Installing modules..." + chunk + "%");
frame.getProgressBar().setValue(chunk);
frame.repaint();
}
}
protected void done() {
frame.setVisible(false);
}
};
worker.execute();
}
示例9: createFramework
import org.osgi.framework.launch.FrameworkFactory; //导入方法依赖的package包/类
private Framework createFramework() throws IOException {
final ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class);
final Iterator<FrameworkFactory> iterator = factoryLoader.iterator();
final FrameworkFactory next = iterator.next();
return next.newFramework(ConfigUtil.createFrameworkConfiguration());
}
示例10: onCreate
import org.osgi.framework.launch.FrameworkFactory; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if(D) Log.d(TAG, "Setting up a thread for felix.");
Thread felixThread = new Thread() {
@Override
public void run() {
File dexOutputDir = getApplicationContext().getDir("transformationmanager", 0);
// if default bundles were not installed already, install them
File f = new File(dexOutputDir.getAbsolutePath()+"/bundle");
if(!f.isDirectory()) {
if(D) Log.i(TAG, "Installing default bundles...");
unzipBundles(FelixService.this.getResources().openRawResource(R.raw.bundles),
dexOutputDir.getAbsolutePath()+"/");
}
FelixConfig felixConfig = new FelixConfig(dexOutputDir.getAbsolutePath());
Map<String, String> configProperties = felixConfig.getProperties2();
try {
FrameworkFactory frameworkFactory = new org.apache.felix.framework.FrameworkFactory();
felixFramework = frameworkFactory.newFramework(configProperties);
felixFramework.init();
AutoProcessor.process(configProperties,felixFramework.getBundleContext());
felixFramework.start();
// Registering the android context as an osgi service
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("platform", "android");
felixFramework.getBundleContext().registerService(
Context.class.getName(), getApplicationContext(),
properties);
} catch (Exception ex) {
Log.e(TAG, "Felix could not be started", ex);
ex.printStackTrace();
}
}
};
felixThread.setDaemon(true);
felixThread.start();
LocalBroadcastManager.getInstance(this).registerReceiver(downloadReceiver,
new IntentFilter(FELIX_SUCCESSFUL_WEB_REQUEST));
}
示例11: startOSGiContainer
import org.osgi.framework.launch.FrameworkFactory; //导入方法依赖的package包/类
private Framework startOSGiContainer(final String[] bundleLocations,
final String tempDirPath) throws BundleException {
FrameworkFactory frameworkFactory = ServiceLoader
.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
config.put("org.osgi.framework.system.packages", "");
config.put("osgi.configuration.area", tempDirPath);
config.put("osgi.baseConfiguration.area", tempDirPath);
config.put("osgi.sharedConfiguration.area", tempDirPath);
config.put("osgi.instance.area", tempDirPath);
config.put("osgi.user.area", tempDirPath);
config.put("osgi.hook.configurators.exclude",
"org.eclipse.core.runtime.internal.adaptor.EclipseLogHook");
Framework framework = frameworkFactory.newFramework(config);
framework.init();
BundleContext systemBundleContext = framework.getBundleContext();
org.apache.maven.artifact.Artifact equinoxCompatibilityStateArtifact =
pluginArtifactMap.get("org.eclipse.tycho:org.eclipse.osgi.compatibility.state");
URI compatibilityBundleURI = equinoxCompatibilityStateArtifact.getFile().toURI();
systemBundleContext.installBundle("reference:" + compatibilityBundleURI.toString());
framework.start();
for (String bundleLocation : bundleLocations) {
try {
systemBundleContext.installBundle(bundleLocation);
} catch (BundleException e) {
getLog().warn("Could not install bundle " + bundleLocation, e);
}
}
FrameworkWiring frameworkWiring = framework
.adapt(FrameworkWiring.class);
frameworkWiring.resolveBundles(null);
return framework;
}
示例12: initFelixFramework
import org.osgi.framework.launch.FrameworkFactory; //导入方法依赖的package包/类
private static void initFelixFramework() throws IOException, BundleException {
Properties configProps = _loadOsgiConfigProperties();
// configure Felix auto-deploy directory
String sAutoDeployDir = configProps.getProperty(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY);
if (sAutoDeployDir == null) {
throw new RuntimeException("Can not find configuration ["
+ AutoProcessor.AUTO_DEPLOY_DIR_PROPERY + "] in file "
+ OSGiSERVER_OSGI_PROPERTIES.getAbsolutePath());
}
File fAutoDeployDir = new File(OSGiSERVER_HOME, sAutoDeployDir);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY + ": "
+ fAutoDeployDir.getAbsolutePath());
}
configProps.setProperty(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY,
fAutoDeployDir.getAbsolutePath());
// configure Felix temp (storage) directory
String sCacheDir = configProps.getProperty(Constants.FRAMEWORK_STORAGE);
if (sCacheDir == null) {
throw new RuntimeException("Can not find configuration [" + Constants.FRAMEWORK_STORAGE
+ "] in file " + OSGiSERVER_OSGI_PROPERTIES.getAbsolutePath());
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug(Constants.FRAMEWORK_STORAGE + ": " + sCacheDir);
}
File fCacheDir = new File(OSGiSERVER_HOME, sCacheDir);
configProps.setProperty(Constants.FRAMEWORK_STORAGE, fCacheDir.getAbsolutePath());
// configure Felix's File Install watch directory
final String PROP_FELIX_FILE_INSTALL_DIR = "felix.fileinstall.dir";
String sMonitorDir = configProps.getProperty(PROP_FELIX_FILE_INSTALL_DIR);
if (sMonitorDir != null) {
File fMonitorDir = new File(OSGiSERVER_HOME, sMonitorDir);
configProps.setProperty(PROP_FELIX_FILE_INSTALL_DIR, fMonitorDir.getAbsolutePath());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(PROP_FELIX_FILE_INSTALL_DIR + ": " + fMonitorDir.getAbsolutePath());
}
}
// check for Felix's Remote Shell listen IP & Port
if (LOGGER.isDebugEnabled()) {
String remoteShellListenIp = configProps.getProperty("osgi.shell.telnet.ip");
String remoteShellListenPort = configProps.getProperty("osgi.shell.telnet.port");
LOGGER.debug("Remote Shell: " + remoteShellListenIp + ":" + remoteShellListenPort);
}
Map<String, String> config = new HashMap<String, String>();
for (Entry<Object, Object> entry : configProps.entrySet()) {
config.put(entry.getKey().toString(), entry.getValue().toString());
}
FrameworkFactory factory = new org.apache.felix.framework.FrameworkFactory();
framework = factory.newFramework(config);
framework.init();
AutoProcessor.process(configProps, framework.getBundleContext());
_autoDeployBundles(fAutoDeployDir, framework);
framework.start();
}