Home > Articles > Programming > Java

This chapter is from the book

3.2 Fundamentals of the EJB architecture

An EJB is essentially a software component on which method calls can be made, and which can itself make calls on other components. These calls may be made over a network. In this sense, EJB technology is similar to Java RMI and CORBA. However, there are some defining features of EJBs that make EJB development rather different from (and easier than) other techniques for developing distributed applications. In Version 2.0 of the EJB Specification, EJBs are allowed to interact using local calling semantics, as well as distributed, RMI-like techniques.

Here are some other important features of the EJB architecture.

The client’s view of an EJB is defined strictly by interfaces As we have already seen, synchronous clients can call only those methods exposed by the EJB’s interfaces. In the EJB Specification, the interfaces are collectively referred to as the client view. Each EJB publishes ‘factory’ interfaces and ‘business method’ interfaces (usually, but not necessarily, one of each). The factory interfaces expose methods that clients can use to create, locate, and remove EJBs of that type. The business method interfaces define all the methods that clients can call on a specific EJB after it has been located or created through the factory interface. The term ‘business method’ is a generic one used to describe any method that a client can call on a specific EJB, and does not have to be related to ‘business’ in the dictionary sense.

Figure 3.1 shows in outline the interaction between EJBs, with the interfaces forming the points of contact in all cases.

Figure 3.1Figure 3.1 . The interactions between EJBs and their clients are defined in terms of interfaces. Each EJB has a factory interface (‘F’) and a business method interface (‘B’), as discussed in the text. When EJBs make method calls on other EJBs, even in the same JVM, then the calling EJB is a client of the target EJB and can call only those methods exposed by the interfaces.


It is important for the developer to understand that anything that makes method calls on an EJB is a client of that EJB, and interacts with it via its factory and business method interfaces. This applies even in the case where multiple EJBs interact within the same JVM. Enforcing this model allows the EJB infrastructure to provide important services transparently. If we are sure that the EJBs must be in the same JVM, then we can use local home and local interfaces, rather than remote home and remote interfaces.

In Java, as in most programming languages, an interface is simply a specification of method signatures; it does not indicate how the methods are to be implemented. Obviously something has to implement the interfaces. You may be surprised to learn that in EJB technology the interfaces are never implemented by a class authored by the developer. They are implemented proxy objects generated dynamically by the server vendor’s tools.

EJBs are isolated and supported by an EJB container Although EJB clients make method calls as if they were directly on the EJB, in fact the method calls are on proxies which delegate to the EJB’s implementation class. These proxies, and their supporting classes, form the EJB container. 5 The client never calls EJB methods on the implementation directly, even if the client and the EJB are actually on the same server, or even in the same JVM. This strategy allows powerful features like distributed transaction management to be provided transparently, and provides for pooling of implementation instances to increase efficiency.

Message-driven EJBs are not called directly by clients at all, and don’t have container proxies in the same sense. Instead they are called directly by the container when it receives a message for a queue or topic in which the EJB has registered an interest.

The container encapsulates the EJB and acts as its security manager. It also provides general services to the EJB, as we shall see. The notion of the container and its proxies is illustrated in Figure 3.2. 6

Figure 3.2Figure 3.2 . The notion of the EJB container as a proxy for the EJB: the client calls methods on the home object and EJB object, which delegate to the implementation itself. The process is transparent to the client. There are different home objects and EJB objects for local and remote access, but the purpose of these objects is essentially the same

Because the methods on the EJB proxies will delegate to methods on the EJB itself, the proxies must be generated to match the EJB—that is, the proxies will be specific to the EJB they serve. The vendor of the EJB server will provide tools to support this generation, which will typically take place when the EJB is deployed to the server.

Gotcha!

The terms ‘EJB server’ and ‘EJB container’ are not well-defined in the EJB Specification, and are used by developers somewhat interchangeably. In this book, a ‘server’ will be taken to mean a process of some sort, providing a set of low-level services that may be shared by any number of EJBs. A ‘container’ refers specifically to the supporting class or classes that encapsulate and manage an EJB.

The EJB container provides an illusion of a single-threaded environment The developer of an EJB should not have to be concerned about concurrency and thread management; in fact, it contravenes the EJB Specification [EJB2.0 24.1.2] for the developer to include code to handle these issues. The container ensures that the EJB is never called re-entrantly, 7 so the developer can code the EJB as if it were used in a single-threaded environment. This issue is a subtle one, and is discussed in more detail on page 476.

The EJB container manages database transactions It does this even when the transaction spans multiple servers. There is a mechanism for specifying the transactional behaviour of EJBs outside of program code, although limited programmatic control of transactions is permissible as well.

The EJB container manages access and security Security attributes specify which methods on which EJBs are accessible to which groups of users. No coding is required, although limited programmatic intervention is allowed. The EJB server must provide a mechanism for end users to identify themselves to the application (e.g., a ‘login’ dialog box) or be able to access authentication from a Web browser in a Web application. The EJB developer should never have to code authentication procedures.

Creation and location of EJBs is standardized There is a well-defined way for the client to create new EJBs or to find existing ones. It does this on the factory interface, which it finds by doing a JNDI lookup on the EJB name. Having found the interface, the client can call its create() or find() methods to create or locate new EJBs. When it does this, it gets a reference to a proxy, not to the the EJB itself. The client manipulates the proxy exactly as if it were the real EJB, but the proxy carries out other functions (transaction management, for example) as well as delegating method calls to the EJB.

Instances can be pooled for efficiency When a client creates an EJB, it is really creating a ‘conceptual EJB,’ not an instance of a Java class. The EJB container may pool instances of the implementation class and give the client a reference to an existing instance when the client asks to create an EJB. Allowing the container to pool instances can lead to enormous gains in efficiency. Again, this is transparent to the client, but the developer must be aware of the circumstances in which pooling is permitted. Proxy instances may also be pooled in some circumstances.

The container manages resources EJBs get access to external resources—such as databases and messaging systems—through the container. The container can pool, share, and manage these resources on behalf of the EJBs, in a way that is transparent to the EJB developer. In this way, we get all the benefits or a resource sharing scheme, with few of the disadvantages.

There is a standard deployment process There is a specified, standard way for the EJB to be packaged and transferred to the server. This process is called deployment. Any EJB server that complies with the EJB Specification [EJB2.0 23] must be able to accept an EJB packaged in the correct way, regardless of the platform on which it was developed and tested.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020