190 likes | 298 Views
Knowledge Byte In this section, you will learn about: New features in EJB 2.1 specification RMI in EJB. New Features in EJB 2.1 Specification New features and enhancements introduced in EJB 2.1 specification are: Enhanced message-driven beans
E N D
Knowledge Byte • In this section, you will learn about: • New features in EJB 2.1 specification • RMI in EJB Collaborate
New Features in EJB 2.1 Specification • New features and enhancements introduced in EJB 2.1 specification are: • Enhanced message-driven beans • New clauses and functions in EJB Query Language (QL) • EJB timer service • New Web services for EJB architecture Collaborate
New Features in EJB 2.1 Specification (Contd.) • Enhanced Message-Driven Beans • EJB 2.1 specification allows message-driven beans to receive messages from non-JMS APIs, such as Java API for XML Messaging (JAXM), as well. • You need to implement only those interfaces corresponding to the API that you are using for sending messages. • For example, to receive the JAXM-compatible messages, you need to implement the javax.xml.messaging.OnewayListener or javax.xml.messaging.ReqRespListener interfaces in the message-driven bean class file. Collaborate
New Features in EJB 2.1 Specification (Contd.) • New Clauses and Functions in EJB Query Language (EJB QL) are: • Introduces the ORDER BY clause in EJB QL that enables you to sort the data retrieved by a database query according to a specified field. • Introduces following mathematical functions that enable you to perform mathematical operations: • MOD(Num1,Num2) • AVG(Field) • MIN(Field) • MAX(Field) • SUM(Field) • COUNT(Field) Collaborate
New Features in EJB 2.1 Specification (Contd.) • EJB Timer Service: • Enables you to send notifications after scheduled time intervals to all type of beans except stateful session beans. • Uses a Timer object to send notification to an enterprise bean after specified delay. • The following code snippet creates a Timer object named time1 that notifies an enterprise bean after a time delay of 5 seconds: • TimerService timeservice1= context.getTimerService(); • Timer time1=timeservice1.createTimer(5000,”Example Timer”); Collaborate
New Features in EJB 2.1 Specification (Contd.) • New Web Services For EJB Architecture are: • You can declare stateless session beans as Web service endpoints to enable the stateless session beans to interact with clients, directly. • Web service support in stateless session beans enables the client interfaces that are developed in various languages, such as C# and .NET, to access methods of enterprise beans directly, without using JSP and servlets. • EJB 2.1 specification also enables enterprise beans to access the Web services directly. • The reference to a Web service is stored in the <service-ref> tag in the deployment descriptor of the enterprise bean. Collaborate
RMI in EJB • RMI: • Is the technique that enables objects in one Java Virtual Machine (JVM) to invoke the methods of another object stored in another JVM. • Is supported by most EJB servers as a standard feature. • Is used by the enterprise applications to invoke remote methods. Enterprise beans communicate with each other and clients using RMI over IIOP. Collaborate
RMI in EJB (Contd.) • The remote and home interfaces are stored at the client-end. • A client calls the methods of the remote and home interfaces and these method calls are sent to the stubs on client-end. • The stub marshals the parameters and calls the skeleton across the network. • The skeleton demarshals the parameters and calls the methods of the EJB object. • Before the release of EJB 2.0 specification, RMI was the only technique to call the methods of enterprise beans. • EJB 2.0 specification has introduced local interfaces, which do not use RMI to invoke methods but can only be used when both, client and bean, are stored in the same JVM . Collaborate
From the Expert’s Desk • In this section, you will learn: • Best Practice on: • Upgrading a Web Application by Incorporating EJB Components • Tips and Tricks on: • Passing a Session Bean’s Reference to Another Session Bean • Optimizing the Performance of Stateless Session Beans • Declaring and Accessing Session Bean Environment Properties • FAQs on EJB Collaborate
Best Practices • Upgrading a Web Application by Incorporating EJB Components • A Web application can be upgraded to an EJB application by creating enterprise beans and interfaces. • The enterprise beans are included between the Web tier and the database tier. • JSP and servlets interact with clients and invoke the methods of enterprise beans to perform database operations. Collaborate
Best Practices • Upgrading a Web Application by Incorporating EJB Components (Contd.) • Benefits of enterprise beans are: • Enterprise beans handle the business logic efficiently as compared to JSP and servlets that handle the business logic in Web applications. • EJB container provides various features, such as transaction management and connection pooling that improve the performance and scalability of the application. • Enterprise beans reduce network traffic. The calls between EJB components located in the same JVM are faster as they can interact using local interfaces. • EJB technology secures an application by authenticating clients and defining which security roles can invoke which business methods of the enterprise bean. Collaborate
Tips and Tricks • Passing a Session Bean’s Reference to Another Session Bean • You can pass the reference of a session bean’s object to another session bean by using the getEJBObject() method, which returns the reference to the instance context of the session bean. • The SessionContext object of a session bean contains the getEJBObject() method. Collaborate
Tips and Tricks • Optimizing the Performance of Stateless Session Beans • Techniques to optimize the performance of a stateless session bean are: • Setting appropriate bean pool size. • Caching resources using the ejbCreate() and setSessionContext() methods. • Releasing resources using the ejbRemove() method. Collaborate
Tips and Tricks • Declaring and Accessing Session Bean Environment Properties • Environment properties: • Enable you to change and modify the business logic of an application without modifying the source code of the session bean. • Are represented as name and value pairs in the deployment descriptor. • Are accessed using the Java Naming and Directory Interface (JNDI) Environment Naming Context (ENC). Collaborate
FAQs • Why are local interfaces used to access an enterprise bean? • Local interfaces enable clients to access bean methods faster than remote interfaces. Local interfaces are faster because they directly call the methods of enterprise bean rather than using the RMI technique for invoking methods. • Why does the EJB specification impose certain programming restrictions in EJB? • EJB container is responsible for providing various system-level services, such as network connections and thread management. As a result, you need to avoid coding these system-level services in enterprise beans. The EJB specification defines certain programming restrictions to avoid the programming of system-level services by the programmers. Collaborate
FAQs (Contd.) • Which EJB component is responsible for the creation and removal of stateless session bean instances? • EJB container is responsible for managing the creation and removal of stateless session bean instances in the shared pool. • Is the ejb-jar.xml file EJB container-specific or is it same for all the EJB application servers? • The ejb-jar.xml file is same for all EJB-compliant application servers. The various application servers may generate other vendor-specific files with the .xml extension that store the container-specific features. Collaborate
FAQs (Contd.) • What is the function of the setSessionContext() method in stateless session beans? • The setSessionContext() method is used to associate a session bean with a session context, which stores information, such as home object reference, transactional state, and security, about the session bean. Collaborate
Challenge • The EJB container creates the _________and _______ objects. • Deployment descriptor elements are specified in the ______ file. • The javax.ejb.SessionBean interface extends the ___________ interface. • The ejbCreate() and ejbRemove() methods are also called the _____________ methods of an enterprise bean. • EJB-related classes and interfaces are present in the __________ package. Collaborate
Solutions to Challenge • Home, EJB • ejb-jar.xml • javax.ejb.EnterpriseBean • life cycle • javax.ejb Collaborate