I have a problem in the Jini programming when one service A uses another service B. ClassCastException happens. I've searched for old messages, but haven't get useful suggestions to my problem. Need help!!! Please drop me some lines!!! Thank you very much!!!!!!!!!!!!!!
Service B: a movie player Service A: a command controller Service A needs to use Service B. __________________________________________________________
A-dl. jar is the downloadable jar file that the client uses. In A-dl.jar, I've include B.class(for more detail: Movie.class)
A.jar is the jar file that is used for the service A.jar is NOT include B.class
________________________________________________________________ In Service A:
The interface A.java has a method: void ShowSlids(...)
The remote interface remoteA.java has no methods.
The service AService.java only does the process of getting proxy,discovery, join, registration.
The proxy AProxy.java implements the method void ShowSlids(...) in the interface: public void showSlides(String [] picList, int time) throws RemoteException{ TestMovie testMovie = new TestMovie(); testMovie.showSlides(picList, time); }
TestMovie.java is used to look for the Service A(a movie player) and call the methods in Service A. ________________________________________________________________
In TestMovie.java : ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::: Class[] classes = new Class[] {Movie.class}; ServiceTemplate template = new ServiceTemplate(null, classes,null); Object si = registrar.lookup(template); System.out.println(si); // store current ClassLoader classLoader thisClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setCont extClassLoader(si.getClass().getClassLoader()); System.out.println("The name of the class is: " + si.getClass().getName()); System.out.println("MovieProxy classloader = " + java.rmi.server.RMIClassLoader.getClassAnnotation(si.getClass())); // HERE'S WHERE YOU DO YOUR THING WITH THE SERVICE if (si instanceof Movie){ System.out.println("true"); }else{ System.out.println("false"); }
movieService = (Movie) si; <-- - - - - - - - --- -- - - - - error happens at this point
// restore the ClassLoader Thread.currentThread().setContextClassLoader(thisClassLoader);
movie.MovieProxy@5fd868 The name of the class is: movie.MovieProxy MovieProxy classloader = http://192.38.86.72:8080/Movie2705-dl.jar false java.lang.ClassCastException: movie.MovieProxy at commandctrl.TestMovie.lookupMovie(TestMovie.java:167) at commandctrl.TestMovie.discovered(TestMovie.java:118) at net.jini.discovery.LookupDiscovery$1.run(LookupDiscovery.java:585) at java.security.AccessController.doPrivileged(Native Method) at net.jini.discovery.LookupDiscovery$Notifier.run(LookupDiscovery.java:566)