当前位置: 技术问答>java相关
SOS! 用适配器模式设计RMI应用的问题
来源: 互联网 发布时间:2015-06-20
本文导语: 各位用适配器模式设计过RMI应用么?我在做这个试验时遇到难题,希望有经验的朋友相助。代码如下: 一、远程接口 package examples.hello; import java.io.*; import java.rmi.Remote; import java.rmi.RemoteException; public interface He...
各位用适配器模式设计过RMI应用么?我在做这个试验时遇到难题,希望有经验的朋友相助。代码如下:
一、远程接口
package examples.hello;
import java.io.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
BufferedReader getVMInfo() throws RemoteException;
}
二、远程接口实现
package examples.hello;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject
implements Hello {
VMInfo vminfo;
// The owner publishes this service in the RMI registry.
public HelloImpl(VMInfo vminfo) throws RemoteException {
super();
this.vminfo = vminfo;
}
public String sayHello() {
return "Hello World!";
}
public BufferedReader getVMInfo() throws RemoteException {
return vminfo.getVMInfo();
}
public static void main(String args[]) {
// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
HelloImpl obj = new HelloImpl();
// Bind this object instance to the name "HelloServer"
Naming.rebind("HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
三、VMInfo类
package examples.hello;
import java.io.*;
public class VMInfo
implements Serializable {
public BufferedReader getVMInfo()
{
BufferedReader vminfo = null;
try {
Process proc = Runtime.getRuntime().exec("iostat 1 5");
vminfo = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
int i = 0;
String text = null;
while((text = vminfo.readLine()) != null) {
System.out.println(text);
}
}
catch(IOException ioError) {
ioError.printStackTrace();
System.exit(0);
}
return vminfo;
}
public static void main(String[] args)
{
VMInfo vminfo = new VMInfo();
vminfo.getVMInfo();
}
}
运行javac -d $HOME/public_html/myclasses Hello.java HelloImpl.java HelloApplet.java 出现如下错误信息(在netterm下,在telnet下与此不同):
HelloImpl.java:61: The method examples.hello.BufferedReader getVMInfo() declare
public BufferedReader getVMInfo() throws RemoteException {
^
1 error
请高手指点,多谢了!
e-mail:duhj@lianchuang.com
一、远程接口
package examples.hello;
import java.io.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
BufferedReader getVMInfo() throws RemoteException;
}
二、远程接口实现
package examples.hello;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject
implements Hello {
VMInfo vminfo;
// The owner publishes this service in the RMI registry.
public HelloImpl(VMInfo vminfo) throws RemoteException {
super();
this.vminfo = vminfo;
}
public String sayHello() {
return "Hello World!";
}
public BufferedReader getVMInfo() throws RemoteException {
return vminfo.getVMInfo();
}
public static void main(String args[]) {
// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
try {
HelloImpl obj = new HelloImpl();
// Bind this object instance to the name "HelloServer"
Naming.rebind("HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
三、VMInfo类
package examples.hello;
import java.io.*;
public class VMInfo
implements Serializable {
public BufferedReader getVMInfo()
{
BufferedReader vminfo = null;
try {
Process proc = Runtime.getRuntime().exec("iostat 1 5");
vminfo = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
int i = 0;
String text = null;
while((text = vminfo.readLine()) != null) {
System.out.println(text);
}
}
catch(IOException ioError) {
ioError.printStackTrace();
System.exit(0);
}
return vminfo;
}
public static void main(String[] args)
{
VMInfo vminfo = new VMInfo();
vminfo.getVMInfo();
}
}
运行javac -d $HOME/public_html/myclasses Hello.java HelloImpl.java HelloApplet.java 出现如下错误信息(在netterm下,在telnet下与此不同):
HelloImpl.java:61: The method examples.hello.BufferedReader getVMInfo() declare
public BufferedReader getVMInfo() throws RemoteException {
^
1 error
请高手指点,多谢了!
e-mail:duhj@lianchuang.com
|
“public BufferedReader getVMInfo() throws RemoteException” ?
确定是这样吗?
为什么“public String sayHello()”就可以呢?
把throws RemoteException 去了看看,我现在没机子,没办法试你试试看吧!:)
|
这是编译错误还是执行错误啊?我怎么看得像执行错误呀,是不是?
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。