Re felix.bundle.dictionary - this is the package which is contains the
dictionary implementation inside the bundle, and so I thought this is what
the bundle needs to export as its 'services offered'.
I am trying to see how a client of some kind (either a host application or
another bundle) uses a service provided by a bundle. From the samples, it
appears that an interface is created which is shared by client and bundle,
with the only catch being that both need to share the same Class<?> instance
(loaded from a common classloader - the hosts).
If a bundle just exports a package or service of which host app or other
bundles do not share a common interface (e.g. a dictionary service with no
interface known to client), then the only way to invoke it is to use the
reflection API.
I thought the way host and client share the same Class<?> instance was
through the config setup:
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"felix.bundle.dictionary.DictionaryService");
My ultimate goal is to create a set of java interfaces which have different
implementations inside OSGi bundles (1 implementation per bundle) and the
decision about which implementation (bundle) to load could be made at
runtime.
Serge
Richard S. Hall wrote:
>
> Why are you making the felix.bundle.dictionary package available inside
> from a bundle in the first place?
>
> If you want to share packages between the host app and bundles inside
> the framework, then these packages should be on the class path. There is
> really no reason to include them packaged inside of bundles too.
>
> -> richard
>
> On 1/25/10 0:35, Serge Merzliakov wrote:
>> Hello,
>> I am having trouble with the OSGI tutorials, with the host
>> application
>> using a bundle service (Tutorial 2 - dictionary service). I have read
>> previous posts on classloader issues between host app and bundles and
>> also
>> read (apache-felix-framework-launching-and-embedding.html) page as well.
>>
>> My problem is that despite trying to 'inject' the service interface class
>> from the host into the bundle, as detailed in Felix pages above, the
>> bundle
>> is still using its own service interface, causing the ClassCastException.
>> I
>> have shown this to be the case as if use:
>>
>> Class<?> bundleInstance =
>> felix.getBundleContext().getBundle(1).loadClass("felix.bundle.dictionary.DictionaryService");
>> Object dictionary =
>> bundleInstance.cast(felix.getBundleContext().getService(ref))
>>
>> then it works. I find this very 'clunky' and would much rather do:
>>
>> DictionaryService dictionary = (DictionaryService)
>> felix.getBundleContext().getService(ref);
>>
>> I have attached my host application and would appreciate any feeback as
>> to
>> how to solve the classloader issue (I have seen the HostActivator code,
>> and
>> tried it, but fail to see how that would solve my problem).
>>
>>
>> Serge
>>
>>
>> /***********************************************/
>> public static void main(String[] argv) throws Exception
>> {
>> System.out.println("\nWelcome to Felix.");
>>
>> try
>> {
>> Properties config = new Properties();
>> config.setProperty(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
>> "install,start");
>> config.setProperty(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY,
>> "/Users/serge/dev/osgi/Felix/bundle");
>> config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
>> "felix.bundle.dictionary.DictionaryService");
>>
>> felix = getFrameworkFactory().newFramework(config);
>> felix.init();
>> AutoProcessor.process(config, felix.getBundleContext());
>> felix.start();
>>
>> ServiceReference ref =
>> felix.getBundleContext().getServiceReference(DictionaryService.class.getName());
>>
>> Class<?> hostClassInstance = DictionaryService.class; // hosts
>> version
>> Class<?> bundleClassInstance =
>> felix.getBundleContext().getBundle(1).loadClass("felix.bundle.dictionary.DictionaryService");
>> //bundle version
>>
>> // -------- !!!!
>> // THIS LINE FAILS BECAUSE hostClassInstance !=
>> bundleClassInstance
>> DictionaryService svc = (DictionaryService)
>> felix.getBundleContext().getService(ref);
>> // ---------- !!!!
>>
>> boolean found = svc.checkWord("hello");
>> System.out.println("word hello exists - " + found);
>>
>> felix.waitForStop(4000);
>> felix.getBundleContext().ungetService(ref); //reference
>> counting
>> for bundle unloading
>> System.exit(0);
>> }
>> catch (Exception ex)
>> {
>> .......
>> }
>> }
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://old.nabble.com/service-interface-classes-not-being-exported-into-bundle---ClassCaseException-tp27302355p27314844.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]