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 的过程, 就是动态创建代理的过程。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值