Monday, March 29, 2021

Enterprise Java Bean (EJB)

 👉    What is EJB and specify its components?

*    It is a specification given by Sun's Micro-system to develop secured, robust and scalable distributed systems.

*    It is a server side component and hence reusable.

*    It is similar to a java class and typically contains the business logic.

*    There are mainly 3 types of EJB's

    1.    Entity Bean.

    2.    Session Bean.

    3.    Message driven.

 👉    What is Enterprise Java Server(EJS) ?

*    The EJS is the server where the EJB is deployed (Server-side).

*    This is a part of the application server that hosts the EJB container.

*    EJB cannot directly interact with the EJS whereas it uses a middleware.

*    EJB specification outlines eight services that must be provided by the EJS such as :

    1.    Naming.
    2.    Transaction.
    3.    Security.
    4.    Persistence.
    5.    Concurrency.
    6.    Life-cycle.
    7.    Messaging
    8.    Timer.

*    Examples    :    WebSphere, Sun Application Server, Oracle Application Server, JBoss

 👉    Briefly explain the EJB components ?

*    First lets categorize the EJB as follows which makes it easier to understand the concepts:


*    EJB components are categorized as synchronous and asynchronous.

*    Entity bean and the session bean are categorized in the synchronous block while the message driven bean is an asynchronous block.

*    The Entity bean is further classified as Container Managed Persistence (CMP) & Bean Managed Persistence (BMP).

*    The session bean is further classified as stateless and stateful.

NOTE : Lets consider the Student Management System for explaining the EJB components further.

 👉    What is an Entity Bean in EJB components ?

*    Java objects are created when the program is created and lost when the program terminates. But the entity bean stays until it is deleted. 

*    Typically in the business logic entity beans are backed up onto a stable storage media (in most cases it is a database).

*    The entity bean has a primary key. It is used to uniquely identify the data in the entity bean.

*    @Entity annotation is used to specify an entity bean class.

*    This must be a non-final concrete class and no methods in the entity bean is final.


*    CMP    -    The container maintains persistence transparently using JDBC calls.
*    BMP    -    The programmer provides the persistence logic. It is used to connect non-JDBC calls. 

*    Lets consider out Student management example.
    The nouns in the system are categorized under the Entity Bean. Eg. Student, Timetable, etc.

 👉    What is an Session Bean in EJB components ?

*    There are 2 types of session beans mainly :

    1.    Stateless Session Bean (SLSB).

*    It is not essential to remember the client state when considering the SLSB.

*    @Stateless annotation is used to denote a SLSB.

*    The optional lifecycle callback events are @PostConstruct and @PreDestroy.

    2.    Stateful Session Bean (SFSB).

*    Maintains the conversational state of the client.

*    Each instance in the SFSB maintains an instance of the client.

*    @Stateful annotation is used to denote a SFSB.

*    The optional lifecycle callback events are @PostConstruct and @PreDestroy.

*    Lets consider out Student management example.

    The verbs in the system are categorized under the Session Bean  (The Methods) . 
    Eg. addStudent(), register(), etc.


 

 👉    What is an Message driven Bean in EJB components ?

*    This is invoked by asynchronous messages.

*    This cannot be invoked by remote or local interfaces.

*    @MessageDriven is the annotation used to mark a message driven bean.

*    It is stateless and transaction aware.




 👉    List some advantages of EJB ?

*    Simplified development with a reliable robust and portable application.
*    Focuses on the business logic without considering the application development.
*    Increase in the developer productivity.
*    Reduces the time to launch the real-time critical systems.


No comments:

Post a Comment

Monolithic vs Microservices

👉     Monolithic Architecture. *     Monolithic architecture was there before Microservices came into action.  *     All functionalities or...