FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Enterprise_JavaBeans

Jakarta Enterprise Beans

Contents
        Stateless Session Beans
        Singleton Session Beans
    Message driven beans
Execution
References
External links

Jakarta Enterprise Beans (EJB; formerly Enterprise JavaBeans) is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. An EJB web container provides a runtime environment for web related software components, including computer security, Java servlet lifecycle management, transaction processing, and other web services. The EJB specification is a subset of the Jakarta EE specification.

@Stateless publicclass CustomerService{ privateEntityManagerentityManager; publicvoidaddCustomer(Customercustomer){ entityManager.persist(customer); } }

The above defines a service class for persisting a Customer object (via O/R mapping). The EJB takes care of managing the persistence context and the addCustomer() method is transactional and thread-safe by default. As demonstrated, the EJB focuses only on business logic and persistence and knows nothing about any particular presentation.

Such an EJB can be used by a class in e.g. the web layer as follows:

Stateful Session Beans are business objects having state: that is, they keep track of which calling client they are dealing with throughout a session and of the history of its requests, and thus access to the bean instance is strictly limited to only one client during its lifetime. If concurrent access to a single bean is attempted anyway the container serializes those requests, but via the @AccessTimeout annotation the container can instead throw an exception. Stateful session beans' state may be persisted (passivated) automatically by the container to free up memory after the client hasn't accessed the bean for some time. The JPA extended persistence context is explicitly supported by Stateful Session Beans.

Examples

Stateless Session Beans

edit

Stateless Session Beans are business objects that do not have state associated with them. However, access to a single bean instance is still limited to only one client at a time, concurrent access to the bean is prohibited. If concurrent access to a single bean is attempted, the container simply routes each request to a different instance. This makes a stateless session bean automatically thread-safe. Instance variables can be used during a single method call from a client to the bean, but the contents of those instance variables are not guaranteed to be preserved across different client method calls. Instances of Stateless Session beans are typically pooled. If a second client accesses a specific bean right after a method call on it made by a first client has finished, it might get the same instance. The lack of overhead to maintain a conversation with the calling client makes them less resource-intensive than stateful beans.

Examples

Singleton Session Beans

edit

Singleton Session Beans are business objects having a global shared state within a JVM. Concurrent access to the one and only bean instance can be controlled by the container (Container-managed concurrency, CMC) or by the bean itself (Bean-managed concurrency, BMC). CMC can be tuned using the @Lock annotation, that designates whether a read lock or a write lock will be used for a method call. Additionally, Singleton Session Beans can explicitly request to be instantiated when the EJB container starts up, using the @Startup annotation.

Examples

Message driven beans

edit

Message Driven Beans are business objects whose execution is triggered by messages instead of by method calls. The Message Driven Bean is used among others to provide a high level ease-of-use abstraction for the lower level JMS (Java Message Service) specification. It may subscribe to JMS message queues or message topics, which typically happens via the activationConfig attribute of the @MessageDriven annotation. They were added in EJB to allow event-driven processing. Unlike session beans, an MDB does not have a client view (Local/Remote/No-interface), i. e. clients cannot look-up an MDB instance. An MDB just listens for any incoming message on, for example, a JMS queue or topic and processes them automatically. Only JMS support is required by the Java EE spec, but Message Driven Beans can support other messaging protocols. Such protocols may be asynchronous but can also be synchronous. Since session beans can also be synchronous or asynchronous, the prime difference between session- and message driven beans is not the synchronicity, but the difference between (object oriented) method calling and messaging.

Examples

Execution

edit

EJBs are deployed in an EJB container, typically within an application server. The specification describes how an EJB interacts with its container and how client code interacts with the container/EJB combination. The EJB classes used by applications are included in the ]/<module-name>/<bean-name>[!<fully-qualified-interface-name>] Application java:app/<module-name>/<bean-name>[!<fully-qualified-interface-name>] Module java:module/<bean-name>[!<fully-qualified-interface-name>]

(entries in square brackets denote optional parts)

A single bean can be obtained by any name matching the above patterns, depending on the 'location' of the client. Clients in the same module as the required bean can use the module scope and larger scopes, clients in the same application as the required bean can use the app scope and higher, etc.

E.g. code running in the same module as the CustomerService bean (as given by the example shown earlier in this article) could use the following code to obtain a (local) reference to it:

jakarta.ejb package.

Other changes included removal of deprecated APIs that were pointless to move to the new top level package and the removal of features that depended on features that were removed from Java or elsewhere in Jakarta EE 9. The following APIs were removed:

  • methods relying on Schedule annotation repeatable.

    EJB 3.2.6, final release (2019-08-23)

    Jakarta Enterprise Beans 3.2, as a part of Jakarta EE 8, and despite still using "EJB" abbreviation, this set of APIs has been officially renamed to "Jakarta Enterprise Beans" by the Eclipse Foundation so as not to tread on the Oracle "Java" trademark.

    EJB 3.2, final release (2013-05-28)

    JSR 345. Enterprise JavaBeans 3.2 was a relatively minor release that mainly contained specification clarifications and lifted some restrictions that were imposed by the spec but over time appeared to serve no real purpose. A few existing full EJB features were also demanded to be in EJB 3 lite and functionality that was proposed to be pruned in EJB 3.1 was indeed pruned (made optional).

    The following features were added:

    • Passivation of a stateful session bean can be deactivated via attribute on @Stateful annotation (passivationCapable = false)
    • TimerService can retrieve all active timers in the same EJB module (could previously only retrieve timers for the bean in which the TimerService was called)
    • Lifecycle methods (e.g. @PostConstruct) can be transactional for stateful session beans using the existing @TransactionAttribute annotation
    • Autocloseable interface implemented by embeddable container

    EJB 3.1, final release (2009-12-10)

    JSR 318. The purpose of the Enterprise JavaBeans 3.1 specification is to further simplify the EJB architecture by reducing its complexity from the developer's point of view, while also adding new functionality in response to the needs of the community:

    • Local view without interface (No-interface view)
    • .war packaging of EJB components
    • EJB Lite: definition of a subset of EJB
    • Portable EJB Global JNDI Names
    • Singletons (Singleton Session Beans)
    • Application Initialization and Shutdown Events
    • EJB Timer Service Enhancements
    • Simple Asynchrony (@Asynchronous for session beans)

    EJB 3.0, final release (2006-05-11)

    JSR 220 - Major changes: This release made it much easier to write EJBs, using 'annotations' rather than the complex 'deployment descriptors' used in version 2.x. The use of home and remote interfaces and the ejb-jar.xml file were also no longer required in this release, having been replaced with a business interface and a bean that implements the interface.

    EJB 2.1, final release (2003-11-24)

    JSR 153 - Major changes:

    • Web service support (new): stateless session beans can be invoked over SOAP/HTTP. Also, an EJB can easily access a Web service using the new service reference.
    • EJB timer service (new): Event-based mechanism for invoking EJBs at specific times.
    • Message-driven beans accepts messages from sources other than JMS.
    • Message destinations (the same idea as EJB references, resource references, etc.) has been added.
    • EJB query language (EJB-QL) additions: ORDER BY, AVG, MIN, MAX, SUM, COUNT, and MOD.
    • XML schema is used to specify deployment descriptors, replaces DTDs

    EJB 2.0, final release (2001-08-22)

    JSR 19 - Major changes: Overall goals:

    • The standard component architecture for building distributed object-oriented business applications in Java.
    • Make it possible to build distributed applications by combining components developed using tools from different vendors.
    • Make it easy to write (enterprise) applications: Application developers will not have to understand low-level transaction and state management details, multi-threading, connection pooling, and other complex low-level APIs.
    • Will follow the "Write Once, Run Anywhere" philosophy of Java. An enterprise Bean can be developed once, and then deployed on multiple platforms without recompilation or source code modification.
    • Address the development, deployment, and runtime aspects of an enterprise application’s life cycle.
    • Define the contracts that enable tools from multiple vendors to develop and deploy components that can interoperate at runtime.
    • Be compatible with existing server platforms. Vendors will be able to extend their existing products to support EJBs.
    • Be compatible with other Java APIs.
    • Provide interoperability between enterprise Beans and Java EE components as well as non-Java programming language applications.
    • Be compatible with the CORBA protocols (RMI-IIOP).

    EJB 1.1, final release (1999-12-17)

    Major changes:

    • XML deployment descriptors
    • Default JNDI contexts
    • RMI over IIOP
    • Security - role driven, not method driven
    • Entity Bean support - mandatory, not optional

    Goals for Release 1.1:

    • Provide better support for application assembly and deployment.
    • Specify in greater detail the responsibilities of the individual EJB roles.

    EJB 1.0 (1998-03-24)

    Announced at JavaOne 1998, Sun's third Java developers conference (March 24 through 27) Goals for Release 1.0:

    • Defined the distinct "EJB Roles" that are assumed by the component architecture.
    • Defined the client view of enterprise Beans.
    • Defined the enterprise Bean developer’s view.
    • Defined the responsibilities of an EJB Container provider and server provider; together these make up a system that supports the deployment and execution of enterprise Beans.

    References

    edit
    "Singleton EJB". Openejb.apache.org. Archived from the original on 2010-05-24. Retrieved 2012-06-17.
  • ↑ JSR 318, 5.1, http://jcp.org/en/jsr/detail?id=318
  • ↑ JSR 318, 5.7.2, http://jcp.org/en/jsr/detail?id=318
  • ↑ JSR 318, 5.4.2, http://jcp.org/en/jsr/detail?id=318
  • ↑ JSR 318, 5.6.2, http://jcp.org/en/jsr/detail?id=318
  • ↑ "Transaction Annotations". Openejb.apache.org. Retrieved 2012-06-17.
  • ↑ JSR 318, 13.3.6, http://jcp.org/en/jsr/detail?id=318
  • ↑ JSR 318, 4.4, http://jcp.org/en/jsr/detail?id=318
  • ↑ "Resin Java EE 6 Web Profile - Resin 3.0". Wiki.caucho.com. 2010-02-12. Archived from the original on 2012-03-23. Retrieved 2012-06-17.
  • ↑ JSR 318, 21.1 EJB 3.1 Lite, http://jcp.org/en/jsr/detail?id=318
  • ↑ JSR 318, Table 27 - Required contents of EJB 3.1 Lite and Full EJB 3.1 API, http://jcp.org/en/jsr/detail?id=318
  • ↑ "JavaOne Conference Trip Report: Enterprise JavaBeans Technology: Developing and Deploying Business Applications as Components". Alephnaught.com. Retrieved 2012-06-17.

External links

edit

View original on Wikipedia | Back | FazBrowse Home