felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sahoo <Sa...@Sun.COM>
Subject Re: brain teaser - embedded felix / class cast exception
Date Tue, 08 Jul 2008 16:47:02 GMT
Craig Phillips wrote:
> Sahoo, Dieter,
>
> Yeah, this is what I'm suspecting and I'll try what you suggest, Deiter,
> to print them out and I think I/we'll know the answer -- they were
> loaded in two different class loaders... Note that they are from the
> same package -- I built everything so everything is on the same page
> from a compile/jar standpoint.
>   
This is clear from the error message.
> My parent is what creates the Felix container, so it is technically not
> in a bundle, but I loaded the same class code in it's jar (since I'm
> going to be using it, of course) -- although, design wise, I'm using the
> <<interface>> not the <<Impl>>, but I short circuited the interface
just
> to get to the bottom of the riddle...
This seems to be the problem. Felix does not use the class that's loaded 
by your code, which is running outside Felix. To fix it, you have to 
make both Felix and your code use the same class. Since your code runs 
before Felix and you probably don't want to use reflection to use that 
class, the only option that I can think of is to configure Felix to use 
your class by adding org.craig.cache to the list of packages exported by 
the parent class loader. The property name in config.property is: 
org.osgi.framework.system.packages. See OSGi documentation for more 
details about this property.

Thanks,
Sahoo
> I don't exactly understand the rest of the questions enough to give a
> technically sufficient response... [sorry]...
>
> I'll post back the output of the debug statements as Dieter suggests in
> a few...
>
> As always, much appreciative, Craig
>
> -----Original Message-----
> From: Sanjeeb.Sahoo@sun.com [mailto:Sanjeeb.Sahoo@sun.com] On Behalf Of
> Sahoo
> Sent: Tuesday, July 08, 2008 12:26 PM
> To: dev@felix.apache.org
> Subject: Re: brain teaser - embedded felix / class cast exception
>
> That basically means the same named class has been defined by two 
> different class loaders. Can you check if the bundle that's exporting 
> the service and the bundle that's consuming the service are not wired to
>
> the same org.craig.cache package?
>
> Which bundle is exporting the above package?
> How are the service producer and consumer bundles specifying their 
> package dependency for the above bundle?
>
> Thanks,
> Sahoo
>
> Craig Phillips wrote:
>   
>> Hi,
>>
>> Can't cast a class to it's own type... Huh?  I just got to believe
>>     
> it's
>   
>> some kind of class loader thing going on... I really could use a pair
>>     
> of
>   
>> eyes from one of the class loader experts out there, I anticipate (I
>> brought other eyes nearby to look, they're stumped too)...  Thanks,
>> Craig Phillips
>>
>> Here's the stack error message:
>>
>> java.lang.ClassCastException: org.craig.cache.CacheServiceMain cannot
>>     
> be
>   
>> cast to org.craig.cache.CacheServiceMain
>>
>> Here's the line of code:
>>
>> CacheServiceMain cacheServiceMain = (CacheServiceMain)
>>     
> bc.getService(sr)
>   
>> Here's the context snippet, that creates the felix container, more or
>> less:
>>
>> System.getProperties().setProperty(Main.CONFIG_PROPERTIES_PROP,
>>  
>> "file:../webapps/craigbox/WEB-INF/felix_config.properties");
>> Main.loadSystemProperties();
>> Properties configProps = Main.loadConfigProperties();
>> List<AutoActivator> list = new ArrayList<AutoActivator>(); // pass
>> through
>> list.add(new AutoActivator(configProps)); // pass through
>> Map map = new StringMap(configProps, false); // pass through
>> felix = new Felix(map, list); // there isn't a default constructor
>> felix.start();
>> BundleContext bc = felix.getBundleContext();
>> ServiceReference sr =
>> bc.getServiceReference("org.craig.cache.api.CacheServiceMainApi");
>> if (sr != null)
>> {
>>    CacheServiceMain cacheServiceMain =  (CacheServiceMain)
>> bc.getService(sr);
>>    ... // and the rest, which of course doesn't come in to play
>>
>>
>> PS - To Karl -- As you can tell, I have not done the "set TCL to
>>     
> null",
>   
>> but this is in the "parent" code... Note that I do have all the
>>     
> classes
>   
>> in the parent dot.jar file, if that's any consolation...
>>
>>
>>   
>>     

Mime
View raw message