java 实例化PortableRemoteObject笔记

来源:互联网 发布:开淘宝店前期如何推广 编辑:程序博客网 时间:2024/06/08 01:35

之前获取Bean实例都是new,spring context,class.newInstance。今天阅读发现一种新的实例方法。

该方法有如下优点:

1、对实例化作check 

2、支持远程interface,abstract


此处为官方解释:

Server implementation objects may either inherit from javax.rmi.PortableRemoteObject or they may implement a remote interface and then use the exportObject method to register themselves as a server object. The toStub method takes a server implementation and returns a stub that can be used to access that server object. The connect method makes a Remote object ready for remote communication. The unexportObject method is used to deregister a server object, allowing it to become available for garbage collection. The narrow method takes an object reference or abstract interface type and attempts to narrow it to conform to the given interface. If the operation is successful the result will be an object of the specified type, otherwise an exception will be thrown.


该类可执行方法有:

static void connect(Remote target, Remote source)
Makes a Remote object ready for remote communication.

static void exportObject(Remote obj)
Makes a server object ready to receive remote calls.

static Object narrow(Object narrowFrom, Class narrowTo)
Checks to ensure that an object of a remote or abstract interface type can be cast to a desired type.

static Remote toStub(Remote obj)
Returns a stub for the given server object.

static void unexportObject(Remote obj)
Deregisters a server object from the runtime, allowing the object to become available for garbage collection.


具体执行方法为PortableRemoteObject.narrow(Object narrowFrom, Class narrowTo);返回一个实例的对象。

0 0
原创粉丝点击