home接口的weblogic实现类的stub类 ((hello bean))_homeimpl_wlstub(部署的时候动态生成字节码)
home接口的weblogic实现类的skeleton类 ((hello bean))_homeimpl_wlskeleton(部署的时候动态生成字节码)
remote接口:hello (用户编写)
remote接口的weblogic实现类 ((hello bean))_eoimpl(ejbc生成)
remote接口的weblogic实现类的stub类 ((hello bean))_eoimpl_wlstub(部署的时候动态生成字节码)
remote接口的weblogic实现类的skeleton类 ((hello bean))_eoimpl_wlskeleton(部署的时候动态生成字节码)
客户端只需要hello.class和hellohome.class这两个文件。
((hello home)) home = (home)
((portable remote object)).narrow(ctx.lookup("hello"),
((hello home)).class);
这一行代码是从jndi获得home接口,但是请记住!接口是抽象的,那么home这个对象到底是什么类的对象实例呢?很简单,用tostring()输出看一下就明白了,下面一行是输出结果:
((hello bean))_homeimpl_wlstub@18c458
这表明home这个通过从服务器的jndi树上查找获得的对象实际上是hellobean_homeimpl_wlstub类的一个实例。
接下来客户端代码:
hello h = home.create()
同样hello只是一个抽象的接口,那么h对象是什么东西呢?打印一下:
((hello bean))_eoimpl_wlstub@8fa0d1
原来是hellobean_eoimpl_wlstub的一个对象实例。
用这个例子来简述一遍ejb调用过程:
首先客户端jndi查询,服务端jndi树上hello这个名字实际上绑定的对象是hellobean_homeimpl_wlstub,所以服务端将创建hellobean_homeimpl_wlstub的一个对象实例,序列化返回给客户端。
于是客户端得到home对象,表面上是得到hellohome接口的实例,实际上是进行了一次远程调用得到了hellobean_homeimpl_wlstub类的对象实例,别忘记了hellobean_homeimpl_wlstub也实现了hellohome接口。
然后home.create()实质上就是hellobean_homeimpl_wlstub.create(),该方法将发送信息给hellobean_homeimpl_wlskeleton,而hellobean_homeimpl_wlskeleton接受到信息后,再去调用hellobean_homeimpl的create方法,至此完成第1次完整的rmi循环。
注意在这次rmi循环过程中,远程对象是hellobean_homeimpl,远程对象的接口是hellohome,对象的stub是hellobean_homeimpl_wlstub,对象的skeleton是hellobean_homeimpl_wlskeleton。
然后hellobean_homeimpl再去调用hellobean_impl的ejbcreate方法,而hellobean_impl的ejbcreate方法将负责创建或者分配一个bean实例,并且创建一个hellobean_eoimpl_wlstub的对象实例。
这一步比较有趣的是,在前一步rmi循环中,远程对象hellobean_homeimpl在客户端有一个代理类hellobean_homeimpl_wlstub,但在这一步,hellobean_homeimpl自己却充当了hellobean_impl的代理类,只不过hellobean_homeimpl不在客户端,而是在服务端,因此不进行rmi。
然后hellobean_eoimpl_wlstub的对象实例序列化返回给客户端,这一步也很有趣,上次rmi过程,主角是hellobean_homeimpl和它的代理类hellobean_homeimpl_wlstub,但这这一次换成了hellobean_eoimpl和它的代理类hellobean_eoimpl_wlstub来玩了。
hello h = home.create();h.helloworld();
假设hello接口有一个helloworld远程方法,那么表面上是在调用hello接口的helloworld方法,实际上是在调用hellobean_eoimpl_wlstub的helloworld方法。
然后hellobean_eoimpl_wlstub的helloworld方法将发送信息给服务器上的hellobean_eoimpl_wlskeleton,而hellobean_eoimpl_wlskeleton收到信息以后,再去调用hellobean_eoimpl的helloworld方法。至此,完成第2次完整的rmi循环过程。
在刚才hellobean_eoimpl是作为远程对象被调用的,它的代理类是hellobean_eoimpl_wlstub,但现在hellobean_eoimpl要作为hellobean_impl的代理类了。现在hellobean_eoimpl去调用hellobean_impl的helloworld方法。注意!hellobean_impl继承了hellobean,而hellobean中的helloworld方法是我们亲自编写的代码,现在终于调用到了我们编写的代码了!
至此,一次ejb调用过程终于完成。在整个过程中,服务端主要要调用的类是hellobean_impl, hello bean?_homeimpl,hellobean_homeimpl_wlskeleton,hellobean_eoimpl,hellobean_eoimpl_wlskeleton。
客户端主要调用的类是hellobean_homeimpl_wlstub,hellobean_eoimpl_wlstub,这两个类在客户端代码中并不会直接出现,出现在代码中的类是他们的接口hellohome和hello,因此客户端需要这两个接口文件,而stub是服务器传送给他们的。
闽公网安备 35060202000074号