Implement mechanisms for efficient inter-component calls

This page discusses - Implement mechanisms for efficient inter-component calls

Implement mechanisms for efficient inter-component calls

Implement mechanisms for efficient inter-component calls

Bean Interfaces and Implementation

According to the 2.0 specification, the implementation classes for entity beans that use CMP are now abstract classes.

Session beans and entity beans in 2.0 can have two types of interfaces: a remote interface and a local interface.

  • Local Interface

    The local interfaces for session and entity beans provide support for light weight access from enterprise beans that are local clients. That is, the bean uses a local interface if the bean wants to provide tight coupling with its clients with pass-by-reference semantics. The local interface is a standard Java interface that does not inherit from RMI.

  • Remote interface

    A bean that needs to have remote capabilities - the bean inherits from RMI and interacts with distributed clients - uses a remote interface. A bean can have both a local and a remote interface - that is, it can provide both a local and a remote client view.

Typically, however, a bean will be designed to provide only one or the other interface. Similarly, a bean can have a remote home interface and/or a local home interface.

In the 2.0 specification, a bean typically uses its remote interface to expose its methods across the network tier. A bean uses the local interface to expose its methods to other beans that reside within the same container. It is thus possible to directly access a bean through its local interface without the overhead of a remote method call.

Local interfaces provide the foundation for container managed relationships among entity beans and session beans. The bean uses the local interface to maintain its references to other beans. For example, entity beans use local interfaces to maintain relationships to other entity beans. They also allow session and entity beans to be tightly coupled with their clients. Using local interfaces, beans can also expose their state and use pass-by-reference to pass their state between related bean instances.

Adding references to enterprise beans

You can add different types of references to an enterprise bean, including EJB references (local and remote), resource references, security role references, and resource environment references.

An EJB reference is a logical name used by a client (or another bean) to locate the home interface of an enterprise bean. It is a best practice to use an EJB reference for any enterprise bean that you need to reference. Using an EJB reference will allow you to safely write Java code to lookup the home interface of the target enterprise bean without the worry of the binding changing for the target enterprise bean. This is necessary if you need to install the same EJB module on the same server with different bindings.

In addition, for looking up local home interface, you are required to use an EJB local reference.

At deployment, the EJB reference is bound to the enterprise bean's home in the target operational environment. The container makes the application's EJB references available in a JNDI naming context. Resource environment reference elements contain declarations of an enterprise bean's reference to an administered object associated with a resource in the application client's environment. Resource environment references are available only for J2EE 1.3 application clients. For EJB 2.0, the created resource reference has WebSphere Application Server extensions for isolation policy and connection policy.

To add references to an enterprise bean:

  1. In the J2EE Hierarchy view, right-click the desired EJB module and select Open With > Deployment Descriptor Editor from the pop-up menu.

  2. On the References page of the editor select the enterprise bean that you want to add a reference to (the referencing bean) - TravelAgent, and click the Add button. The Add Reference wizard opens.

    References
  3. Select the type of reference that you want to create (EJB local reference), and click Next.

    Add Reference wizard
  4. Select the location of the enterprise bean that you want to reference (the referenced bean).

    Note: Local references can reference enterprise beans in the same EJB project or in the same application. Remote references can also reference enterprise beans in another application.

    When you select an enterprise bean in another EJB project within the same application or another application, the Java JAR dependencies are automatically set up. If you select an enterprise bean in another application and the preference to create EJB client projects is turned on, you will be prompted to create an EJB client project for the EJB project of the selected enterprise bean if one does not already exist. The EJB client project is added as a Java utility JAR to all applications that the source bean projects belongs to. A Java JAR dependency for the source EJB project is also added to the utility JAR file, which is the target EJB client project.

  5. Select the enterprise bean that you are referencing (Cabin), and update the Name field or accept the default (recommended).

    Name - ejb/Cabin

    Add EJB Local Reference wizard
  6. Click Next to review your selections and enter a description for the reference.

    Add EJB Local Reference wizard
  7. Click Finish.

The reference is added to the bean that you selected and is displayed on the References page of the EJB deployment descriptor editor.

Reference


<session id="TravelAgent">
	<ejb-name>TravelAgent</ejb-name>
	...
	<ejb-local-ref id="EJBLocalRef_1122033021884">
		<ejb-ref-name>ejb/Cabin</ejb-ref-name>
		<ejb-ref-type>Entity</ejb-ref-type>
		<local-home>com.titan.cabin.CabinLocalHome</local-home>
		<local>com.titan.cabin.CabinLocal</local>
		<ejb-link>Cabin</ejb-link>
	</ejb-local-ref>
</session>
					
					

Repeat the same steps and add a reference to (the referencing bean) - TravelAgent for Ship (referenced) bean:

Reference


<session id="TravelAgent">
	<ejb-name>TravelAgent</ejb-name>
	...
	<ejb-local-ref id="EJBLocalRef_1122300603538">
		<ejb-ref-name>ejb/Ship</ejb-ref-name>
		<ejb-ref-type>Entity</ejb-ref-type>
		<local-home>com.titan.ship.ShipLocalHome</local-home>
		<local>com.titan.ship.ShipLocal</local>
		<ejb-link>Ship</ejb-link>
	</ejb-local-ref>
</session>
					
					

Tutorials

  1. Appendix A. Additional materials
  2. WSAD 5.0 Practicing for IBM Test 000-287 Mind Map
  3. Deploy enterprise applications into servers
  4. Chapter 6. Assemble enterprise applications and deploy them in IBM WebSphere Application Server
  5. Configure resource and security-role references
  6. Design and develop custom tags
  7. Chapter 4. Demonstrate understanding of database connectivity and messaging within IBM WebShpere Application Server
  8. Chapter 5. EJB transactions
  9. Design and develop message-driven EJBs
  10. Design and develop entity EJBs
  11. Validate operational parameters of application server to support the enterprise application
  12. Chapter 1. Design, build and test reusable enterprise components
  13. Access container and server services from enterprise components
  14. Part I. Exam Objectives
  15. Explain implications of resource management on application design and implementation
  16. Manage end-user state and understand performance tradeoffs of using HTTP sessions
  17. Chapter 7. Validate, tune and troubleshoot an application within an IBM WebSphere Application Server environment
  18. Implement mechanisms for efficient inter-component calls
  19. IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide
  20. Chapter 3. Develop clients that access the enterprise components
  21. Implement Java clients calling Web Services
  22. Configure JMS connection factories and destinations
  23. Design, develop and test JSPs
  24. Use JTA to control transaction demarcation
  25. Manipulate transactional behavior of EJBs using deployment descriptors
  26. Implement mechanisms which support loose coupling between clients and components
  27. Identify misbehaving application components
  28. Preface
  29. WSAD 5.0 Practicing for IBM Test 000-287
  30. Part II. Appendixes
  31. Interact with connection pools to obtain and release connections
  32. Describe the effects of a server failure on the application
  33. Test and debug enterprise components
  34. Chapter 2. Design, build and test web components
  35. Chapter 2. Design, build and test web components