首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

为 J2EE 应用程序构建分布式对象管理框架(2)ObjectManager API

为 J2EE 应用程序构建分布式对象管理框架(2)ObjectManager API

ObjectManager API在本文中,我将用对象管理器(object manager) 这个词表示这个框架,以便区别于传统的对象池。与对象池一样,对象管理器也负责从池中获取对象和把对象返回池中。另外,对象管理器还理解范围的概念。清单 2 给出对象管理器的 API。
清单 2. ObjectManager API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public interface ObjectManager {
    /**
     * Retrieve an object instance of the give class from the object pool
     * for the given scope, identified by a scope type and a scope key.
     *
     * @param clazz         the class
     * @param scopeType     the type of the scope
     * @param scopeKey      the key to identify the scope
     *
     * @return  an object instance retrieved from the object pool
     */
    public Object getObject(Class clazz, int scopeType, Object scopeKey);

    /**
     * Release an object back to the object pool.
     *
     * @param object   the object to be released
     */
    public void releaseObject(Object object);

    /**
     * Release all objects of the given scope, identified by a scope type
     * and a scope key.
     * @param scopeType     the type of the scope that objects bound to
     * @param scopeKey      the key to identify the scope
     */
    public void releaseAll(int scopeType, Object scopeKey);

}




为了从对象池获取对象,需要提供一个范围类型和一个范围键。对象管理器把范围信息与获取的每个对象关联起来。在调用 releaseAll() 方法时,对象管理器可以识别出与给定的范围相关联的对象,并把它们释放回池中。
返回列表