Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc.

Client View of a Session Bean

Enterprise JavaBeans 2.0, Public Draft

Object identity

Next we decide to complete this shopping session at a later time so we serialize a handle to this cart session object and store it in a file:

Handle cartHandle = cart.getHandle();

serialize cartHandle, store in a file...

Finally we deserialize the handle at a later time, re-create the reference to the cart session object, and purchase the contents of the shopping cart:

Handle cartHandle = deserialize from a file...

Cart cart = (Cart)javax.rmi.PortableRemoteObject.narrow( cartHandle.getEJBObject(), Cart.class);

cart.purchase();

cart.remove();

5.8 Object identity

5.8.1 Stateful session beans

A stateful session object has a unique identity that is assigned by the container at create time.

A client can determine if two object references refer to the same session object by invoking the isIdentical(EJBObject otherEJBObject) method on one of the references.

The following example illustrates the use of the isIdentical method for a stateful session object.

FooHome fooHome = ...; // obtain home of a stateful session bean Foo foo1 = fooHome.create(...);

Foo foo2 = fooHome.create(...);

if (foo1.isIdentical(foo1)) {// this test must return true

...

}

if (foo1.isIdentical(foo2)) {// this test must return false

...

}

5.8.2 Stateless session beans

All session objects of the same stateless session bean within the same home have the same object identity, which is assigned by the container. If a stateless session bean is deployed multiple times (each deployment results in the creation of a distinct home), session objects from different homes will have a different identity.

The isIdentical(EJBObject otherEJBObject) method always returns true when used to compare object references of two session objects of the same stateless session bean.

5/31/00

54