作为lead developer写给组员的一封邮件

I prepared this in case some of you not very understand RMI, so if you are very familiar with it, you can just ignore this email.
wishing Dear Prof.Kevin can help to point mistakes out.
Here's an sample code of RMI with 4 java class: interface, remote method going to be called, client and server including almost everything we need (well, except org.w3c and sql), nothing but few lines!
This is from a Chinese website.
I just translate the explanation from Chinese into English,  so that all of you can read.^_^
Since we are database subsystem, most likely, other subsystem are our "clients" so, 1 and 2 may be the things that we need to implement:

1. Create remote interface(HelloInterface.java)
/*Everyone of us will need this!*/
java code:
  1. package com.unmi;   
  2.   
  3. import java.rmi.*;   
  4.   
  5. /**  
  6.  * this interface must extends java.rmi.Remote 
  7.  */  
  8. public interface HelloInterface extends Remote   
  9. {   
  10.    /**  
  11.     * and it must throws java.rmi.RemoteException 
  12.     */  
  13.    public String say() throws RemoteException;   
  14. }  
2.the class who actually implement remote method!
/*Everyone of us need this!! is't just the sub_database!*/
  1. package com.unmi;   
  2.   
  3. import java.rmi.*;   
  4. import java.rmi.server.*;   
  5.   
  6. /**  
  7.  * extends UnicastRemoteObject,implements HelloInterface 
  8.  */  
  9. public class Hello extends UnicastRemoteObject implements HelloInterface   
  10. {   
  11.    private String message;   
  12.   
  13.    /**  
  14.     * you must explicit constructor as you must notify it to throws RemoteException 
  15.     */  
  16.    public Hello(String msg) throws RemoteException   
  17.    {   
  18.       message = msg;   
  19.    }   
  20.   
  21.    /**  
  22.     * Actually method we will made for others to use
  23.     * Here is the only hard part that we must consider how to handle sql and xml
  24.      but again I will be there to help! and don't you think it's so funny to learn those magic      things~ haha
  25.     */  
  26.    public String say() throws RemoteException   
  27.    {   
  28.       System.out.println("Called by HelloClient");   
  29.       return message;   
  30.    }   
  31. }   
If you want to know how to set up a RMI sever pls continue: nothing but few methods!
  1. package com.unmi;   
  2.   
  3. import java.rmi.Naming;   
  4. import java.rmi.registry.LocateRegistry;   
  5.   
  6. public class HelloServer   
  7. {   
  8.    /**  
  9.     * Start RMI and Register the remote method!
  10.     */  
  11.    public static void main(String[] argv)   
  12.    {   
  13.       try  
  14.       {   
  15.          //Start RMI registration,Point as 1099 (1099 is default value)  
  16.          //you can also do it in this way: $java_home/bin/rmiregistry 1099
  17.          //however it will open another dos windowsand a stub may be needed.  
  18.          //Thus the alternative way is not suggest.
  19.          LocateRegistry.createRegistry(1099);   
  20.            
  21.          //Create instance of remote object,following is an instance of Hello.java  
  22.          //you can use different name of course. 
  23.          HelloInterface hello = new Hello("Hello, world!");   
  24.            
  25.          //register Hello into the server and name it as hello

  26.          // to register this method into another computer! according to its url //address!  
  27.         Naming.rebind("//192.168.1.105:1099/Hello",hello);  
  28.            
  29.          System.out.println("Hello Server is ready.");   
  30.       }   
  31.       catch (Exception e)   
  32.       {   
  33.          System.out.println("Hello Server failed: " + e);   
  34.       }   
  35.    }   
  36. }  
simple?^_^

now let's take a look at what the client will do?

4. client find the remote object,and call its method(HelloClient)

java code
  1. package com.unmi;   
  2.   
  3. import java.rmi.Naming;   
  4.   
  5. public class HelloClient   
  6. {   
  7.    /**  
  8.     * 
  9.     */  
  10.    public static void main(String[] argv)   
  11.    {   
  12.       try  
  13.       {   
  14.          //
  15.          HelloInterface hello = (HelloInterface)Naming.lookup("//192.168.1.105:1099/Hello");  
  16.             
  17.          //remember? Hello.java has a method called say()
  18.          System.out.println(hello.say());   
  19.       }   
  20.       catch (Exception e)   
  21.       {   
  22.          System.out.println("HelloClient exception: " + e);   
  23.       }   
  24.    }   
  25. }   
  26.   
oh my god. Amazing!? that's all thing we are going to made, simple~?^_^
now again, I must emphasize to you all that, the technical part is very easy for this course, hard part is you must get connection with the corresponding subsystem closely! and do not forget your documentation!! 

all technical problem, (RMI, MYSQL,DOM,SQL)I believe all of us can handle them easily! 
I'm try to learn org.w3c.dom now, so next time I will provide an sample code of how to handle xml using DOM(one of the mechanism to handle xml in java).
again If anyone is also very interesting to learn those technical problem, please do so, and then share your experience to all of us.

okay, after read through this, If anyone wish to be the lead developer of RMI, please inform Prof Kevin and me.^_^

Thanks!

Best wishes!

Zhang Shu Hao (Mr.)
Nanyang Technological University
Computer Engineering- Year 2
HP: (+65) 98702513 or (+86) 13688017816
Email: shzhang1@e.ntu.edu.sg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值