Session Bean Interface - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Session Bean Interface

Description:

... acquire any resource that it has released earlier in the ejbPassivate() method. ... release any resources that it can re-acquire later in the ejbActivate() method. ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 21
Provided by: ecstCs
Category:

less

Transcript and Presenter's Notes

Title: Session Bean Interface


1
Session Bean Interface
  • The SessionBean Interface is used to set
  • public interface SessionBean
  • ejbActivate()
  • ejbPassivate()
  • ejbRemove()
  • setSessionContext( SessionContext )

2
Session Bean Methods
  • ejbActivate()
  • This method is called when the instance gets
    activated from its passive state
  • The instance should acquire any resource that it
    has released earlier in the ejbPassivate()
    method.

3
Session Bean Methods (Cont)
  • ejbPassivate()
  • This method is called when the instance enters a
    passive state and should release any resources
    that it can re-acquire later in the ejbActivate()
    method.
  • After completion, the instance must be in a state
    that allows the container to use the Java
    Serialization protocol to externalize and store
    away the instance's state.
  • This method is called with no transaction
    context.

4
Session Bean Methods (Cont)
  • ejbRemove()
  • A container invokes this method before it ends
    the life of the session object.
  • This happens because the client invoked a remove
    operation or the container terminated it due to a
    timeout.

5
Session Bean Methods (Cont)
  • setSessionContext( SessionContext )
  • Set the associated session context. The container
    calls this method after the instance creation.
  • The EJB instance should store the reference to
    the SessionContext in an instance variable.
  • This method is called with no transaction
    context.

6
Exceptions Thrown
  • EJBException - Thrown by the method to indicate a
    failure caused by a system-level error.
  • RemoteException - This exception is defined in
    the method signature to provide backward
    compatibility for applications written for the
    EJB 1.0 specification. Should not use with beans
    written with the EJB 2.0 or later standards.

7
Clients of Session Bean
  • Clients may either be remote or local
  • Remote clients
  • Location independent
  • Can access session bean in EJB container from any
    RMI/IIOP compliant application

8
Clients of Session Bean (Cont.)
  • Local Clients
  • Access session bean with the local and local home
    interfaces
  • Allows objects to be passed by reference
  • Local clients must lie in the same JVM as the
    session bean it interfaces with

9
Clients of Session Bean (Cont.)
  • Both Local and Remote home interfaces provide an
    interface to the client
  • Neither access the session bean directly
  • They use a component interface to the session
    bean.
  • Instances of remote interfaces are called
    EJBObjects.
  • Instances of local are called EJBLocalObjects.

10
Creating a Remote Interface
  • Remote interfaces extend javax.ejb.EJBObject
  • The bean writer provides the interface and the
    container implements it
  • It provides the clients view of a session bean
    and defines any business methods that the client
    can call
  • The business methods must throw at minimum the
    same exceptions as in the bean class

11
Remote Interface Methods
  • EJBHome getEJBHome()
  • Returns a reference to the home interface
  • Handle getHandle()
  • Returns a handle which can be used later to
    retrieve a reference to the EJB Object
  • Object getPrimaryKey()
  • Not to be used with session beans.

12
Remote Interface Methods (Cont.)
  • boolean isIdentical(EJBObject obj )
  • Tests whether the passed EJB Object is identical
    to the invoked EJB object.
  • void remove()
  • Removes a session bean object.

13
Home Interface Methods
  • create()
  • For every ejbCreate method in the bean class the
    home Interface must contain a corresponding
    create method
  • getEJBMetaData()
  • Returns an EJBMetaData interface of an EJB which
    enables the client to retrieve information about
    the enterprise bean.

14
Home Interface (Cont.)
  • getHomeHandle()
  • Retrieves the handle of the home object.
  • May allow the client to use a remote home
    interface in the future, even though he does not
    know the JNDI name of the remote home Interface
  • remove( Handle h)
  • Removes the EJBObject identified with the handle
    h
  • remove( Object primaryKey)
  • Should not be used with SessionBeans

15
SessionBean Class
  • It implements the SessionBean interface.
  • The class is defined as public.
  • The class cannot be defined as abstract or final.
  • It implements one or more ejbCreate methods.
  • It implements the business methods.
  • It contains a public constructor with no
    parameters.
  • It must not define the finalize method.

16
Session Bean Class Methods
  • ejbCreate()
  • Used to initialize the bean
  • Must have
  • Public access control modifier
  • Return type of void
  • RMI-Compliant arguments
  • Not have static or final modifier
  • Called when the user calls the create method of
    the home interface
  • Business Methods

17
Session Bean Class Methods(Cont)
  • Business Method signatures may not contain
  • The method name must not conflict with one
    defined by the EJB architecture. For example, you
    cannot call a business method ejbCreate or
    ejbActivate.
  • The access control modifier must be public.
  • The arguments and return types must be legal
    types for Java RMI.
  • The modifier must not be static or final.

18
Generated Classes
  • Home stub
  • Home tie
  • The interface between the home stub and the Home
    Object
  • Home Object
  • Connects the home tie to the home life cycle
    methods

19
Generated Classes (Cont)
  • Remote stub
  • Remote tie
  • Interface between the remote stub and the remote
    object
  • Remote object
  • Connects the remote tie to the business class
    code.

20
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com