java rmi stub 反编译以后, 动态代理

源文件:

/**

** User: xingxiaobing* Date: 2015-02-13* 远程的接口的实现*/public class HelloImpl extends UnicastRemoteObject implements IHello { /** * 因为UnicastRemoteObject的构造方法抛出了RemoteException异常,因此这里默认的构造方法必须写,必须声明抛出RemoteException异常 * * @throws RemoteException */ public HelloImpl() throws RemoteException { } /** * 简单的返回“Hello World!"字样 * * @return 返回“Hello World!"字样 * @throws java.rmi.RemoteException */ public String helloWorld() throws RemoteException { return "Hello World!"; } /** * 一个简单的业务方法,根据传入的人名返回相应的问候语 * * @param someBodyName 人名 * @return 返回相应的问候语 * @throws java.rmi.RemoteException */ public String sayHelloToSomeBody(String someBodyName) throws RemoteException { return "你好," + someBodyName + "!"; }

}

在工程bin目录下使用 rmic 命令

反编译以后

package rmi;import java.lang.reflect.Method;import java.rmi.Remote;import java.rmi.RemoteException;import java.rmi.UnexpectedException;import java.rmi.server.RemoteObject;import java.rmi.server.RemoteRef;import java.rmi.server.RemoteStub;//实现和真实对象相同的接口

//RemoteStub类是客户机 stub 的公共超类,提供支持大量远程引用语义的框架public final class HelloImpl_Stub extends RemoteStub implements IHello, Remote{ private static final long serialVersionUID = 2L; private static Method $method_helloWorld_0; private static Method $method_sayHelloToSomeBody_1; static { try { $method_helloWorld_0 = Remote.class.getMethod("helloWorld", new Class[0]); $method_sayHelloToSomeBody_1 = tmp50_47.getMethod("sayHelloToSomeBody", new Class[] { String.class }); } catch (NoSuchMethodException localNoSuchMethodException) { throw new NoSuchMethodError("stub class initialization failed"); } } public HelloImpl_Stub(RemoteRef paramRemoteRef) { super(paramRemoteRef); } public String helloWorld() throws RemoteException { Object localObject; try {

//调用真实对象的helloword方法 localObject = this.ref.invoke(this, $method_helloWorld_0, null, 32013462L); return ((String)localObject); } catch (RuntimeException localRuntimeException) { throw localRuntimeException; } catch (RemoteException localRemoteException) { throw localRemoteException; } catch (Exception localException) { throw new UnexpectedException("undeclared checked exception", localException); } } public String sayHelloToSomeBody(String paramString) throws RemoteException { try { Object localObject = this.ref.invoke(this, $method_sayHelloToSomeBody_1, new Object[] { paramString }, -1641805534L); return ((String)localObject); } catch (RuntimeException localRuntimeException) { throw localRuntimeException; } catch (RemoteException localRemoteException) { throw localRemoteException; } catch (Exception localException) { throw new UnexpectedException("undeclared checked exception", localException); } }}

显然HelloImpl_Stub 是HelloImpl 的一个代理。

动态生成HelloImpl_Stub 的过程, 就是动态创建代理的过程。

父母养我不容易,我在学校争口气。

java rmi stub 反编译以后, 动态代理

相关文章:

你感兴趣的文章:

标签云: