Ne vi li se e iskaloda izpolzvate Remote Objects bez da se zanimavate s RMI (govorq za Java client i server , da ne spomenavam che nqkoi hora za chisto Java prilojeniq biha polzvali Corba nadqvam se ne sashtestvuvat takiva veche ).
Ta ne vi li se e iskalo da mojete da kajete
server.Bind("ime",obekt);
i posle pri clienta server.get("ime") s 3 reda
razbira se i na men mi se e iskalo i estestveno che e vazmjno i udobno
primer :
imame interfeis :
public interface Duck {
boolean looks();
boolean walks();
boolean talks();
}
imame i klas
import gnu.cajo.invoke.Remote;
import gnu.cajo.utils.ItemServer;
public class DuckServer implements Duck {
public boolean looks() {
System.out.println("hi there!");
return true;
}
public boolean walks() {
System.out.println("waddle waddle");
return true;
}
public boolean talks() {
System.out.println("quack quack!");
return true;
}
public static void main(String args[]) { // simple unit test
try {
Remote.config(null, 1198, null, 0); // use cajo port 1198
ItemServer.bind(new DuckServer(), "Donald"); // lol 1 red !
System.out.println("duck server running");
} catch(Exception x) { x.printStackTrace(); }
}
}
imame i klient
mport gnu.cajo.utils.extra.TransparentItemProxy;
public class DuckClient { // try out DuckServer
public static void main(String args[]) {
try {
Duck duck = (Duck)TransparentItemProxy.getItem(
"//serverHost:1198/Donald",
new Class[] { Duck.class }
); //lol otnovo 1 red.
System.out.println("looks like = " + duck.looks());
System.out.println("walks like = " + duck.walks());
System.out.println("talks like = " + duck.talks());
} catch(Exception x) { x.printStackTrace(); }
}
}
pulna statiq s podrobni obqasneniq
http://wiki.java.net/bin/view/Communications/TransparentProxyproekta se naricha the cojo project (
https://cajo.dev.java.net/ )