I've been following this tutorial on distributed RMI using clojure, but it seems to be outdated and I can't get it to work:
http://nakkaya.com/2009/12/05/distributed-clojure-using-rmi/
I was getting a java.lang.ClassNotFoundException: stub.sayName when I followed the tutorial precisely, so I tried using reify instead of proxy, but the error is still there.
As of now my code is as follows:
for the interface: package stub;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface sayName extends Remote {
String Name() throws RemoteException;
}
For my main clojure class:
(ns immutability.core
(:gen-class))
(defn -main
[& args]
(println "Hello, World!"))
(def rmi-registry
(java.rmi.registry.LocateRegistry/createRegistry 1099))
(defn name-server []
(reify stub.sayName Name
(Name [personname] "Hello, " + personname)))
(defn register-server []
(.bind
(java.rmi.registry.LocateRegistry/getRegistry)
"Hello"
(java.rmi.server.UnicastRemote/exportObject
(name-server) 0)))
(register-server)
I'm sure it's something silly and small, but I just can figure it out
Okay, these are your issues:
Post these changes, the code compiles, and appears to be doing what it should. I stopped at invoking the RPI call.
interface code:
package stub;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface SayName extends Remote {
String name(String n) throws RemoteException;
}
I compiled and stored the stub.SayName interface in target/classes/stub/SayName.class. This is on the classpath and was found on the repl startup (relative to your project.clj file).
clojure code:
(ns immutability.core
(:gen-class))
(defn -main
[& args]
(println "Hello, World!"))
(defonce rmi-registry (java.rmi.registry.LocateRegistry/createRegistry 1099))
(defn name-server []
(reify stub.SayName
(name [_ n] (str "Hello " n))))
(defn register-server []
(.bind
(java.rmi.registry.LocateRegistry/getRegistry)
"Hello"
(java.rmi.server.UnicastRemoteObject/exportObject
(name-server) 0)))
(register-server)
One last thing, as a note, you don't want to leave a call like (register-server) directly in your code, since that will get called on compilation. commenting that out, or reserving it for the REPL is a better approach.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.