On Dec 14, 2007 7:17 PM, Abdelgadir Ibrahim
<[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I have a bundle which exports an object via RMI. In another OSGi runtime B, I
> have another bundle which uses this remote object using the code below:
>
> if (System.getSecurityManager() == null)
>  System.setSecurityManager ( new RMISecurityManager() );
> Registry registry = LocateRegistry.getRegistry(remoteHostAddress);
>
> RemoteServiceInterface rmiProxy = (RemoteServiceInterface)
> registry.lookup("remoteObjectKey");
>
> This all works fine and I am able to invoke the methods on the remote object.
>
> However, when I pass my obtained rmiProxy object to any other bundle in the 
> same
> frameowrk instance B, that bundle is unable to cast the rmiProxy object to the
> RemoteServiceInterface. The following is the stack trace:
>
> Client exception: java.lang.ClassCastException: $Proxy0
> java.lang.ClassCastException: $Proxy0
>         at importer4rmi.Activator.start(Activator.java:44)
>         at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993)
>         at
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974)
>         at
> org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
>         at
> org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:350)
>         at
> org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1118)
>         at
> org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:634)
>         at
> org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:508)
>         at
> org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:282)
>         at
> org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:468)
>         at
> org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:195)
>         at
> org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:297)
>
>
> In general, I noticed that the bundle who obtains the rmiProxy object via the
> Registry.lookup(name) method, is the only one who can correctly cast the
> returned object to one of the implemented interfaces.
>
> Any idea why this behaviour??. I suspect it is a class loader issue because 
> the
> two bundles will have different class loaders. Note that I am using jdk1.5 and
> have enabled the new feature of dynamic proxy generation to avoid the need to
> run the rmic tool.
>
> best regards
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> http://www2.osgi.org/mailman/listinfo/osgi-dev


I think this comes from dynamic proxy classes being re-generated by
each bundle's classloader, instead of being generated only once by the
bundle that does the RMI lookup, and being shared afterwards with all
importers of your remote interface.

Now I don't really know what the OSGi specs say about dynamic proxies,
but some of the wizards on this list should be able to enlighten us :)

-- 
Olivier Pernet

We are the knights who say
echo '16i[q]sa[ln0=aln100%Pln100/snlbx]sbA0D4D465452snlbxq'|dc
_______________________________________________
OSGi Developer Mail List
[email protected]
http://www2.osgi.org/mailman/listinfo/osgi-dev

Reply via email to