RMI provides the solution of communication between Java processes. For building a RMI Server/Client Application, below steps are considered:
1. define the Remote interfaces extends from java.rmi.Remote
these interfaces will also be provided to client.
note: all remote interfaces throw java.rmi.RemoteException
2. implement the remote interfaces, the implementation classes also extend java.rmi.server.UnicastRemoteObject to export the remote objects.
3. use java.rmi.Naming binds names with remote objects
4. execute rmic to generate stub and skeleton classes based on the remote implementation classes. it seems should be under the "classes" directory instead of "src"
5. on the client side, we should obtain the remote interfaces and stub classes, then look up the remote objects by java.rmi.Naming and convert to the given interfaces. Then we can invoke the remote methods as local ones.
6. for achieve callback functionality, we can program in this way:
6.1 implement client as RMI server as well
6.2 pass client to Server as a listener
6.2 on the RMI server side, invoke methods of listener anytime