You should read:

http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html

It gives some pointers to running with an embedded framework instance. In short, your app and all bundles should go through the class path (i.e., system bundle) for any packages shared between the host app and the bundles.

To make sure this happens, you could actually put the host/bundle shared packages on the boot class path property to make sure everyone gets the same ones, no matter how the bundles are wired internally. This at least has the benefit that your bundles will work properly when not used in the embedded situation.

I knew there was more than what met the eye here. :-)

Embedded mode is alluring to a lot of people coming to OSGi, but there are lots of hidden issues with it, so better to avoid it if you can.

-> richard

On 7/14/09 1:53 PM, Markus Michel wrote:
You are right. If I remove that line, I'm able to load the event admin
service. But the problem is that I cannot remove it, because other parts of
my program depends on that information: My "vehiclePushService" is mostly
implemented (and started) within the host application but some parts are
implemented within the bundle. If I do not add "vehiclePushService" to that
line, I'm getting the class loading exception

java.lang.ClassCastException:
osgiServices.vehiclePushService.VehiclePushServiceImpl cannot be cast to
osgiServices.vehiclePushService.VehiclePushService

, when the bundle tries to use the service. Maybe I have to add the event
admin service to that line, too?!?

BR,

Markus

-----

Markus,

Yes, I believe your embedded configuration is the issue. Why are you doing
this:

        configMap.put(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"osgiServices.vehicleCommunicationService; osgiServices.vehiclePushService;
vehiclePushService; vehicleCommunicationService");

?

It seems like this is incorrect, since your bundle contains these packages.
Try removing this and see what happens.

Hi Richard!

Here's the bundle which tries to use the felix event admin service. If you
wish I can provide you the sources of the bundle, too.

If you want to use the bundle, you have to load the following bundles:

org.apache.felix.shell-1.2.0.jar
org.apache.felix.shell.tui-1.2.0.jar
org.apache.felix.eventadmin-1.0.0.jar
VehiclePushService_1.0.0.jar

Some minutes ago I noticed that the bundle can be loaded successfully if you
run it directly from a command-line-based felix instance. The error only
occures if you try to run it
as an embedded version. Very confusing.

Maybe there's something wrong with the configuration of my felix instance:

     private void initialize()
     {
         // create new map for storing the felix configuration properties
         configMap = new HashMap<String, Object>();

         // export the host provided service interface package
         configMap.put(FelixConstants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"osgiServices.vehicleCommunicationService; osgiServices.vehiclePushService;
vehiclePushService; vehicleCommunicationService");

         // add autoactivator that specifies all services that shall be
loaded together with the system bundle
         List<Object>  list = new ArrayList<Object>();
         list.add(new AutoActivator(configMap));

         // create service activators
         vehicleCommunicationServiceActivator = new
VehicleCommunicationServiceActivator(connection);
         list.add(vehicleCommunicationServiceActivator);

         vehiclePushServiceActivator = new VehiclePushServiceActivator();
         list.add(vehiclePushServiceActivator);

         // add service activators to felix instance
         configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);

         // set felix-cache folder
         configMap.put("org.osgi.framework.storage", "felix-cache/" + id);
     }


BR,

Markus

-------

2009/7/14 Richard S. Hall<[email protected]>

I don't see anything that immediately looks incorrect. If you want to send
me your bundle (privately) with the steps to reproduce, I will look at it.

->  richard


On 7/14/09 4:20 AM, Markus Michel wrote:

Hi Richard!

Of course I can provide more informations. The manifest file of the bundle
looks like this:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: VehiclePushService
Bundle-SymbolicName: VehiclePushService
Bundle-Version: 1.0.0
Bundle-Activator: vehiclePushService.Activator
Import-Package: org.osgi.framework;version="1.3.0",
  org.osgi.service.event;version="1.1.0",
  vehiclePushService
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .,
  vehiclePushService.jar
Export-Package:
  osgiServices.vehiclePushService,
  vehiclePushService

The content of the bundle looks as follows:

META-INF/
META-INF/MANIFEST.MF
hostApplication/
hostApplication/vehiclePushService/
osgiFramework/
osgiFramework/vehiclePushService/
vehiclePushService/
META-INF/.classpath
META-INF/.project
vehiclePushService.jar
vehiclePushService/Activator.class
vehiclePushService/OSGiPosition2D.class
vehiclePushService/OSGiVehicle.class
vehiclePushService/OSGiVehiclePushService.class
vehiclePushService/VehicleListener.class
vehiclePushService/VehiclePushEvent.class
vehiclePushService/VehiclePushServiceHandler.class

Because inside the plug-in dependencies org.eclipse.services is referenced
I
think that the bundles currently uses the equinox implementation of the
eventadmin service. Later on I will try to load the equinox eventadmin
service instead
of the felix eventadmin service. Maybe it's then possible to start my
bundle
...

BR,

Markus


2009/7/13 Richard S. Hall<[email protected]>



On 7/13/09 2:47 PM, Markus Michel wrote:



Hi there!

Today I wanted to add the eventadmin service to my OSGi environment.
Therefore I extended the import block of my bundle, which is created
within
an eclipse equinox project,  with org.osgi.service.event. After loading
the
service I tried to access it by running the following command:

         // get service reference to event admin service
         serviceReference =
bundleContext.getServiceReference(EventAdmin.class.getName());

         // check if service reference is valid
         if (serviceReference != null)
         {
             eventAdmin = (EventAdmin)
bundleContext.getService(serviceReference);
         }

But inside the if-loop I'm getting an error:

java.lang.ClassCastException:
org.apache.felix.eventadmin.impl.security.EventAdminSecurityDecorator
cannot
be cast to org.osgi.service.event.EventAdmin

I'm a little bit confused now, because I thought that the Apache Felix
framework is fully compatible to the OSGi specifications?!?



While the Felix framework isn't yet 100% compliant, it is very close and
getting closer every release.

  Isn't it


possible to mix equinox components (my bundle) with felix components
(the
eventadmin service)?

Does anybody has an idea how I can solve my problem?




Such a scenario should work, but you didn't provide enough information to
say why it isn't. Perhaps you could show us your bundle's manifest file
as
well as a "jar tf" of the bundle.

->   richard

  BR,


Markus





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]







Reply via email to