Re: Basic Jini problem and cast exceptions
Thomas Vinod Johnson <[email protected]> Wed, 7 Nov 2007 09:41:19 -0500
| Newsgroups | gmane.comp.java.sun.jini |
|---|---|
| Message-ID | <[email protected]> |
>
> This seems to be the right way, but I have a casting exception.
>
> public void init(){
> ...
> LookupLocator locator = new
> LookupLocator("jini://"+ip+":4160");
> ServiceRegistrar registrar = locator.getRegistrar();
> ServiceTemplate serviceTemplate = new
> ServiceTemplate(null,new Class[]{ Hello.class}, null);
> Object obj = registrar.lookup(serviceTemplate);
> System.out.println(" Is instance ["+
> Hello.class.isInstance(obj)+"] "); // prints "Is instance [false] "
> Hello hello = (Hello)obj; // There is the exception
> ...
> }
>
> Exception in thread "main" java.lang.ClassCastException:
> net.jini.core.HelloServer
> at net.jini.client.Client.init (Client.java:42)
> at net.jini.client.Client.main(Client.java:72)
>
> Another detail I could add is that my HelloServer service has two
> interfaces[ "java.io.Serializable", "net.jini.core.Hello"], but the
> "Hello" interface of HelloService seems not to be the same as "Hello"
> I'm using in my HelloClient.java. ( Hello is also java.rmi.Remote )
>
>
> Class []clazz = obj.getClass().getInterfaces();
> System.out.println( "["+clazz[0].equals(Hello.class )+"]" );
> //that prints "[false]" although there have the same name, "
> net.jini.core.Hello"
>
> I can guess some answers. Both hello in server side and client side
> are not the same. But is this really the problem? Is how jini works?
> If I am doing something wirdo and not correct please let me know about
> it. But I think my requirement is simple. I do only need that my
> client know the interfaces, but only the interfaces.
>
Does your -dl.jar have a preferred list that also prefers the Hello
class? Try printing out the names of the interfaces in the your
getInterfaces array and their class loaders (as well as your local
Hello's classloader). You may want to turn on the
net.jini.loader.pref.PreferredClassProvider logger.||
||
> I hope this extend explanation can be enough to show you my doubts.
> Any reference to a good jini document or article will be welcome.
> Regards,
> Jose Hernan Valdes Murguia
>
>
> --------------------------------------------------------------------------
> Getting Started: http://www.jini.org/wiki/Category:Getting_Started
> Community Web Site: http://jini.org jini-users Archive:
> http://archives.java.sun.com/archives/jini-users.html Unsubscribing:
> email "signoff JINI-USERS" to [email protected]
--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to [email protected]