EJB.8.7 Entity Bean s Handle


EJB.8.7 Entity Bean's Handle

An entity object's handle is an object that identifies the entity object on a network. A client that has a reference to an entity object's remote interface can obtain the entity object's handle by invoking the getHandle() method on the remote interface.

Since a handle class extends java.io.Serializable , a client may serialize the handle. The client may use the serialized handle later, possibly in a different process or even system, to re-obtain a reference to the entity object identified by the handle.

The client code must use the javax.rmi.PortableRemoteObject.narrow(...) method to convert the result of the getEJBObject() method invoked on a handle to the entity bean's remote interface type.

The lifetime and scope of a handle are specific to the handle implementation. At the minimum, a program running in one Java virtual machine must be able to obtain and serialize the handle, and another program running in a different Java virtual machine must be able to deserialize it and re-create an object reference. An entity handle is typically implemented to be usable over a long period of time ”it must be usable at least across a server restart.

Containers that store long-lived entities will typically provide handle implementations that allow clients to store a handle for a long time (possibly many years ). Such a handle will be usable even if parts of the technology used by the container (e.g., ORB, DBMS, server) have been upgraded or replaced while the client has stored the handle. Support for this "quality of service" is not required by the EJB specification.

An EJB container is not required to accept a handle that was generated by another vendor's EJB container.

The use of a handle is illustrated by the following example:

 // A client obtains a handle of an account entity object and  // stores the handle in stable storage.  //  ObjectOutputStream stream = ...;  Account account = ...;  Handle handle = account.getHandle();  stream.writeObject(handle);  // A client can read the handle from stable storage, and use the  // handle to resurrect an object reference to the  // account entity object.  //  ObjectInputStream stream = ...;  Handle handle = (Handle) stream.readObject(handle);  Account account = (Account)javax.rmi.PortableRemoteObject.narrow(       handle.getEJBObject(), Account.class);  account.debit(100.00); 

A handle is not a capability, in the security sense, that would automatically grant its holder the right to invoke methods on the object. When a reference to an object is obtained from a handle, and then a method on the object is invoked, the container performs the usual access checks based on the caller's principal.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net