felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <benerit...@googlemail.com>
Subject Using org.osgi.framework.launch in SimpleShape example
Date Wed, 07 Mar 2012 10:34:15 GMT
Hi,

as Richard has suggested in
https://issues.apache.org/jira/browse/FELIX-3375 I'm
about to change the SimpleShape examples to use the OSGi way of launching
an embedded framework. I'd like to discuss, what would be the best way to
accomplish this.

First of all, I think we should not mix up bundle activation with the
application start. So I'd move the static void main from the Activator to
its own class (let's call it Application.java). Looking at what has to be
done to start an embedded framework I can identify three main task, with
some subtasks:

1. create a FrameworkFactory
  a. parse file META-INF/services/org.osgi.framework.launch.FrameworkFactory
  b. find the first valid line
  c. try to get a class with the name of that line
  d. try to instantiate that class
2. create a framework configuration
  a. create a temporary cache dir
  b. add a shutdown hook to delete that dir after system termination
  c create a config map, containing the chache dir as well as some other
config params
3. create the framework
  a. call newFramework() on the framework factory and pass the
configuration to that method
  b. call init()
  c. call start()
  d. wait till the application gets terminated

I've applied this to the extenderbased example, and it works. However I'm
having trouble to get rid of the felix-specific config parameters for auto
bundle activation. What is the non-felix-specific way of starting a
predefined set of bundles?

Another problem I'm seeing is how the bundles are being added to the
configuration. Have a look at
org.apache.felix.example.extenderbased.host.Activator lines 155-163:
        Map<String, Object> configMap = new HashMap<String, Object>();
        configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
            "org.apache.felix.example.extenderbased.host.extension;
version=1.0.0");
        configMap.put(AutoActivator.AUTO_START_PROP + ".1",

"file:../extenderbased.circle/target/extenderbased.circle-1.0.0.jar " +

"file:../extenderbased.square/target/extenderbased.square-1.0.0.jar " +

"file:../extenderbased.triangle/target/extenderbased.triangle-1.0.0.jar");
        configMap.put(FelixConstants.LOG_LEVEL_PROP, "4");
        configMap.put(Constants.FRAMEWORK_STORAGE,
cachedir.getAbsolutePath());

As you can see, this will only work if the example is launched from withing
your IDE, because it assumes that the bundles reside in the target
directory of the other projects. I think this should be made somehow more
flexible, so that the example can be used outside your IDE by just putting
the jars together in one directory. But at the moment I don't know how we
can achieve that, while also keeping the possibility to start from your
workspace.

Another problem is that the embedded framework start of the serverbased
example does not work add all. When I try to run the Activator.java I get
the following:

ERROR: Error starting
file:../servicebased.circle/target/servicebased.circle-1.0.0.jar
(org.osgi.framework.BundleException: Unresolved constraint in bundle 1:
package; (package=javax.swing))
ERROR: Error starting
file:../servicebased.square/target/servicebased.square-1.0.0.jar
(org.osgi.framework.BundleException: Unresolved constraint in bundle 2:
package; (package=javax.swing))
ERROR: Error starting
file:../servicebased.triangle/target/servicebased.triangle-1.0.0.jar
(org.osgi.framework.BundleException: Unresolved constraint in bundle 3:
package; (package=javax.swing))
org.osgi.framework.BundleException: Unresolved constraint in bundle 1:
package; (package=javax.swing)
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3097)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1439)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:984)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:263)
at java.lang.Thread.run(Thread.java:722)
org.osgi.framework.BundleException: Unresolved constraint in bundle 2:
package; (package=javax.swing)
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3097)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1439)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:984)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:263)
at java.lang.Thread.run(Thread.java:722)
org.osgi.framework.BundleException: Unresolved constraint in bundle 3:
package; (package=javax.swing)
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3097)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1439)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:984)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:263)
at java.lang.Thread.run(Thread.java:722)

As you can see, javax.swing can not be resolved. ATM I don't know how to
fix that. Any idea how to fix that?

Regards,
Benedikt

PS: my ICLA has been filed and I've created an account in confluence, so
that you can grant me some karma ;)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message