Remote Method Invocation Remote Classes and Interfaces A














- Slides: 14

Remote Method Invocation

Remote Classes and Interfaces • A Remote class is one whose instances can be used remotely. • A Remote class has two parts – the interface – the class itself

Remote Classes and Interfaces • To create a remote interface – Extends interface Java. rmi. Remote – Must be public – Every method in the interface must declare that it throws java. rmi. Remote. Exception

Remote Classes and Interfaces • To create Remote Class – It must implement a Remote interface – Should extend the java. rmi. server. Unicast. Remote. Object class

Serializable Classes • Copy objects and send them over the wire. • Implements the java. io. Serializable interface.

Activatable Object • Class java. rmi. activation. Activatable • RMI daemon, rmid. • Created and execute "on demand" rather than running all the time.

Example • Server side – Define remote interface public interface Hello extends Remote { …. } – Implement remote class public class Hello. Impl extends Unicast. Remote. Object implements Hello { …… }

Example – Install security manager if (System. get. Security. Manager() == null) { System. set. Security. Manager(new RMISecurity. Manager()); } – Bind object instance to provide service Naming. rebind("//myhost/Hello. Server", obj); – Create stub Rmic – rmiregistry

Example • Client side – Get the reference of the remote object obj = (Hello)Naming. lookup("//" + get. Code. Base(). get. Host() + "/Hello. Server");

Homework • RMI Chat. Room Application Client hi Send Message Server hi Client hi hi Client Request to join Chatroom

Homework • Please design and implement a Message class. public class Message …{ …. // any information about the message //ex. Sender name. }

Homework • Define at least three remote methods below at sever side. – reg_user(…) • register new client with chat room. – get_user_list(…) • return all member in the chat room. – post_message(Message msg) • post message to any member in the chat room.

Grading • Basic Chat. Room application 70 • If server can delivers the latest message to client actively +20 • Implement Activatable Interface +10 • Deadline – 06 11 23

Reference • Sun Java RMI tutorial – http: //java. sun. com/j 2 se/1. 4. 2/docs/guide/rmi/in dex. html – http: //java. sun. com/docs/books/tutorial/rmi/ind ex. html • O'Reilly Java RMI