作为lead developer写给组员的一封邮件
2012-01-31 21:25
288 查看
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:
package com.unmi;
import java.rmi.*;
/**
* this interface must extends java.rmi.Remote
*/
public interface HelloInterface extends Remote
{
/**
* and it must throws java.rmi.RemoteException
*/
public String say() throws RemoteException;
}
2.the class who actually implement remote method!
/*Everyone of us need this!! is't just the sub_database!*/
package com.unmi;
import java.rmi.*;
import java.rmi.server.*;
/**
* extends UnicastRemoteObject,implements HelloInterface
*/
public class Hello extends UnicastRemoteObject implements HelloInterface
{
private String message;
/**
* you must explicit constructor as you must notify it to throws RemoteException
*/
public Hello(String msg) throws RemoteException
{
message = msg;
}
/**
* Actually method we will made for others to use
* Here is the only hard part that we must consider how to handle sql and xml
but again I will be there to help! and don't you think it's so funny to learn those magic things~ haha
*/
public String say() throws RemoteException
{
System.out.println("Called by HelloClient");
return message;
}
}
If you want to know how to set up a RMI sever pls continue: nothing but few methods!
package com.unmi;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
public class HelloServer
{
/**
* Start RMI and Register the remote method!
*/
public static void main(String[] argv)
{
try
{
//Start RMI registration,Point as 1099 (1099 is default value)
//you can also do it in this way: $java_home/bin/rmiregistry 1099
//however it will open another dos windowsand a stub may be needed.
//Thus the alternative way is not suggest.
LocateRegistry.createRegistry(1099);
//Create instance of remote object,following is an instance of Hello.java
//you can use different name of course.
HelloInterface hello = new Hello("Hello, world!");
//register Hello into the server and name it as hello
// to register this method into another computer! according to its url //address!
Naming.rebind("//192.168.1.105:1099/Hello",hello);
System.out.println("Hello Server is ready.");
}
catch (Exception e)
{
System.out.println("Hello Server failed: " + e);
}
}
}
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
package com.unmi;
import java.rmi.Naming;
public class HelloClient
{
/**
*
*/
public static void main(String[] argv)
{
try
{
//
HelloInterface hello = (HelloInterface)Naming.lookup("//192.168.1.105:1099/Hello");
//remember? Hello.java has a method called say()
System.out.println(hello.say());
}
catch (Exception e)
{
System.out.println("HelloClient exception: " + e);
}
}
}
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
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:
package com.unmi;
import java.rmi.*;
/**
* this interface must extends java.rmi.Remote
*/
public interface HelloInterface extends Remote
{
/**
* and it must throws java.rmi.RemoteException
*/
public String say() throws RemoteException;
}
2.the class who actually implement remote method!
/*Everyone of us need this!! is't just the sub_database!*/
package com.unmi;
import java.rmi.*;
import java.rmi.server.*;
/**
* extends UnicastRemoteObject,implements HelloInterface
*/
public class Hello extends UnicastRemoteObject implements HelloInterface
{
private String message;
/**
* you must explicit constructor as you must notify it to throws RemoteException
*/
public Hello(String msg) throws RemoteException
{
message = msg;
}
/**
* Actually method we will made for others to use
* Here is the only hard part that we must consider how to handle sql and xml
but again I will be there to help! and don't you think it's so funny to learn those magic things~ haha
*/
public String say() throws RemoteException
{
System.out.println("Called by HelloClient");
return message;
}
}
If you want to know how to set up a RMI sever pls continue: nothing but few methods!
package com.unmi;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
public class HelloServer
{
/**
* Start RMI and Register the remote method!
*/
public static void main(String[] argv)
{
try
{
//Start RMI registration,Point as 1099 (1099 is default value)
//you can also do it in this way: $java_home/bin/rmiregistry 1099
//however it will open another dos windowsand a stub may be needed.
//Thus the alternative way is not suggest.
LocateRegistry.createRegistry(1099);
//Create instance of remote object,following is an instance of Hello.java
//you can use different name of course.
HelloInterface hello = new Hello("Hello, world!");
//register Hello into the server and name it as hello
// to register this method into another computer! according to its url //address!
Naming.rebind("//192.168.1.105:1099/Hello",hello);
System.out.println("Hello Server is ready.");
}
catch (Exception e)
{
System.out.println("Hello Server failed: " + e);
}
}
}
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
package com.unmi;
import java.rmi.Naming;
public class HelloClient
{
/**
*
*/
public static void main(String[] argv)
{
try
{
//
HelloInterface hello = (HelloInterface)Naming.lookup("//192.168.1.105:1099/Hello");
//remember? Hello.java has a method called say()
System.out.println(hello.say());
}
catch (Exception e)
{
System.out.println("HelloClient exception: " + e);
}
}
}
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
相关文章推荐
- 学生写给老师的一封邮件
- 李开复:一封写给中国学生的信
- 金笛邮件-给新注册的用户发一封欢迎信
- 主管给实习生新人的一封邮件,字字珠玑,用心良苦
- 【转】一封写给初涉社会学生的智慧书信
- 一封邮件引发的思考
- 在网站中用邮件地址作为用户名的不足之处
- 四年后收到了她的一封邮件!
- 一封写给中国学生的信-从诚信谈起
- 写给实习生的邮件
- 如何写一封稍微像样的求职邮件
- [转]关于VIPT cache alias 的一封经典邮件
- 源自微软的一封邮件
- 比尔盖茨就离职决定致员工的一封邮件(ZZ)
- 一封邮件的认知
- 用代码发送包含SharePoint文档作为附件的邮件
- 一封邮件, 就能看出你是不是足够专业
- Bigcommerce: 给已完成购买的客户发送一封产品评论邮件,让客户直接进行产品评论
- SQL Server 定时发送邮件(从数据库查询出的数据作为附件)
- 一封邮件,六句话