Table of Contents
This chapter describes the common characteristics of EJBs in JEUS environment.
This chapter does not cover the EJB standard, and only conveys additional information that is required to use EJB in JEUS environment. For information on EJB deployment, refer to "Chapter 3. EJB Module".
This section discusses EJB types and their DD configurations.
The following EJB types are supported in JEUS.
Stateless session bean: "Chapter 7. Session Bean"
Stateful session bean: "Chapter 7. Session Bean"
BMP entity bean: "Chapter 8. Entity Bean"
CMP 1.1 & CMP 2.x entity bean: "Chapter 8. Entity Bean"
Message-driven bean: "Chapter 9. Message Driven Bean(MDB)"
This chapter will describe all the shared characteristics and configurations that apply to all bean types. In the previous list, we have indicated the chapter where you can find additional information about the type.
Entity Bean is replaced by JPA from EJB 3.0. For more information, refer to the "JEUS JPA Guide". Therefore, it is not recommend to use Entity Bean, which is supported for compatibility reasons.
JEUS EJB Deployment Descriptor (hereafter JEUS EJB DD) is a generic XML file named jeus-ejb-dd.xml, and it is placed in the META-INF directory of an EJB JAR file. For information on JEUS EJB DD, refer to "Chapter 3. EJB Module".
The following table offers a summary of all the functions and components that can be configured in JEUS EJB DD ("@" indicates that the entity can be configured using annotation). The items listed on the left column of the table represent the actual configurable XML tags of a JEUS EJB DD. The six columns to the right show whether the component is applicable to each of the EJB types.
[Table 4.1] Configurable Features and Components of JEUS EJB
The previous table is partitioned as follows:
Items 1 through 16 apply uniformly to all six EJB types (however, items 2-5 and 14-16 do not apply to MDB). All applicable items will be discussed in this chapter.
Items 7 (run-as Identify), 8 (security interoperability), and 14 (clustering) apply uniformly to all EJB types, and will be discussed in separate chapters titled "4.2.6. EJB Security Configuration", "Chapter 5. Interoperability and RMI-IIOP", and "Chapter 6. EJB Clustering" respectively.
Item 17 only applies to stateful session beans and will be discussed in "Chapter 7. Session Bean".
Item 18 (object management) applies uniformly to all six EJB types, but it varies slightly for each EJB type. Basic information about this item will be discussed in "Chapter 7. Session Bean", and the differences in each chapter.
Items 19 through 22 only apply to entity beans. They will be discussed in "Chapter 8. Entity Bean".
Items 23 through 28 only apply to message-driven beans (MDB). MDB will be covered in "Chapter 9. Message Driven Bean(MDB)".
Item 29 is applicable to beans (all beans excluding stateful session bean) that can use the Timer Service provided by EJB specification. For additional information, refer to the "Chapter 10. EJB Timer Service".
All the EJB settings are configured in the jeus-ejb-dd.xml file, the JEUS EJB DD file. The parent XML tag is <jeus-bean> regardless of the bean type.
The next section will describe settings applicable to XML parent tags for the five EJB types. Other tags outside the <beanlist> have already been discussed in "Chapter 3. EJB Module". Refer to the latter chapters in this guide for more information on specific XML parent tags (bean type).
For information on clustering settings, refer to "Chapter 6. EJB Clustering".
The following settings are only for JEUS, and are defined in the jeus-ejb-dd.xml file. For more information on this file, refer to "Chapter 3. EJB Module".
<ejb-name>
It uses the <ejb-name> value from the ejb-jar.xml file, or the "name" value of @Stateless, @Stateful, and @MessageDriven annotations in the implementation class.
<export-name>
It has to have a unique name to be registered with the global JNDI.
If this element is not defined in the DDs, either the mappedName attribute value of @Stateless or @Stateful annotation, or the <mapped-name> value in ejb-jar.xml is applied.
If none is configured, a Remote Business Interface name is used as the default value. But the default value is applied only when there is one Remote Business interface but no Remote Home Interface or vise versa. Otherwise, the deployment will fail because the JNDI name cannot be determined.
The priority is as follows:
<export-name> of jeus-ejb-dd.xml
<mapped-name> of ejb-jar
mappedName of @EJB
Class name (including package name) of remote business interface, the default value
<local-export-name>
It has to have a unique name within the system to be registered to JNDI.
It is applied to the mappedName attribute of @EJB annotation when this element is not configured in DD. If remote business interface exists, '_Local' is attached to this value.
If neither exists, local business interface name is used as the default value. But the default value is applied only when there is one Local Business interface but no Local Home Interfaces or vise versa. Otherwise, an exception will occur because the JNDI name cannot be found.
The priority is as follows:
<local-export-name> of jeus-ejb-dd.xml
If a remote business interface exists, <mapped-name>+ _Local of ejb-jar.xml
If a remote business interface does not exist, <mapped-name> of ejb-jar.xml
If a remote business interface exists, mappedName + _Local of @EJB
If a remote business interface does not exist, mappedName of @EJB
Class name (including package name) of local business interface, the default value
<export-port>
This setting is used when RMI service port needs to be specified explicitly.
It is useful when system access is possible only through a certain port because of a firewall. The value of this tag should be same as the firewall's allowed port. If a value is not specified, ports are applied according to the system properties as follows:
Tag | Description |
---|---|
jeus.ejb.exportPort | Determines export ports of EJBs whose <export-port> is not specified for a specific EJB in jeus-ejb-dd. |
jeus.rmi.usebaseport | If the value is true or false, MS base port or MS base port + 7 is used respectively. |
<export-iiop>
If this setting is activated, it enables the interfaces of the bean to be exported to COS naming server as IIOP stubs and skeletons. This enables all clients, who can access IIOP, to access the bean.
<use-access-control>
When executing bean methods, this Boolean element determines whether the method execution is monitored by Java SE security manager according to Java EE principal. For more information, refer to the "JEUS Security Guide" and JACC specification. The default value is false.
The following examples show how the previous settings can be applied to the Session Bean classes and DDs. Elements of corresponding annotation and DDs are displayed in bold.
[Example 4.1] Stateful Session Bean Class and DDs: <<CounterEJB.java>>
package ejb.basic.statefulSession;
@Stateful(name="counter", mappedName="counterEJB")
public class CounterEJB implements Counter, CounterLocal
{
private int count = 0;
public void increase()
{
count++;
}
...
}
[Example 4.2] Stateful Session Bean Class and DDs: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd>
. . .
<beanlist>
<jeus-bean>
<ejb-name>counter</ejb-name>
<export-name>counterEJB</export-name>
<local-export-name>counterEJB_Local</local-export-name>
<export-port>7654</export-port>
<export-iiop/>
. . .
</jeus-bean>
. . .
</beanlist>
. . .
</jeus-ejb-dd>
The following figure illustrates the concept of EJB thread ticket pool (hereafter TTP).
If there is a client request, a new RMI thread is assigned to the client request. If the number of assigned threads is greater than the configured maximum value, the request waits for an available thread.
As can be seen from the figure, a thread pool contains thread
tickets (hereafter TT). One TT permits one client thread to access the
EJB engine. When a client request arrives, one TT is drawn from the TP
and assigned to the client. This implies that each client thread will be
assigned to one EJB object that will relay the request to an actual EJB
instance. An EJB object is thus an object that lives in the EJB engine
and manages the connection between an EJB client and an actual EJB
instance.
If more client requests arrive than there are TTs in the thread ticket pool, the new requests must wait until a TT is returned to the pool. If the waiting period exceeds 10 minutes, it throws a RemoteException due to a timeout.
TTs are returned to TTP when the client gets disconnected after EJB process terminates (for stateless session bean), or a connection timeout occurs. Each remote-call enabled EJB component contains a TTP. There are also connection and bean pools. Bean pool, instead of TTP, should be configured for MDB.
For more information on connection and bean pools, refer to "Chapter 7. Session Bean" and "Chapter 8. Entity Bean". For more information on using bean pool in MDB, refer to "Chapter 9. Message Driven Bean(MDB)".
TT of EJB is configured in the <thread-max> element of the root XML tag of the bean. This value represents the maximum number of allowable threads that can operate in each EJB, in other words, the maximum number of TT. The default value is 100. If the number of client requests in a queue is larger than this value, new requests have to wait until a running job is finished and the TT is returned to the pool. If the waiting period exceeds 10 minutes, it throws a RemoteException due to a timeout.
The following shows how to apply the previous settings to a BMP bean.
[Example 4.3] BMP Bean Configuration: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd> . . . <beanlist> <jeus-bean> . . . <thread-max>200</thread-max> . . . </jeus-bean> . . . </beanlist> . . . </jeus-ejb-dd>
External references that the bean uses can be configured through annotation or JNDI export name in jeus-ejb-dd.xml, which is mapped to the reference name used in ejb-jar.xml. In the actual system, all defined external references must be mapped to JNDI export name.
Annotations or all the external references defined in ejb-jar.xml must be mapped to relevant tags in jeus-ejb-dd.xml using the JNDI export-name used in the actual system.
Reference tags of ejb-jar.xml and JEUS EJB DD files are as follows:
[Table 4.2] Relationship of Tags in ejb-jar.xml and JEUS EJB DD Files
Tag | EJB DD XML Tag | Description |
---|---|---|
<env-entry> | <env> | Defines or ignores EJB environment configuration. |
<ejb-ref> | <ejb-ref> | Binds EJB reference to actual export name. |
<resource-ref> | <res-ref> | Binds external resource manage reference to actual export name. |
<resource-env-ref> | <res-env-ref> | Binds managed object reference to actual export name. |
<message-destination-ref> | <message-destination-ref> | Binds message destination reference to actual export name. |
<service-ref> | <service-ref> | Binds webservice endpoint reference to actual export name. |
Every <env> tag has the following child tags:
Tag | Description |
---|---|
<name> | Name of env. Same value as the <env-entry-name> defined in the ejb-jar.xml. |
<type> | Complete Java class name corresponding to the data type of the value. Basic data types use a wrapper class. |
<value> | Specifies actual value of env. |
Other three tags (<ejb-ref>, <res-ref>, and <res-env-ref>) have several <jndi-info> child tags. These tags, in turn, have to set the following child tags to map JNDI export name to reference.
Tag | Description |
---|---|
<ref-name> | Reference name defined in EJB source code and ejb-jar.xml. <ejb-ref> and <resenv- ref> are equivalent to <ejb-ref> and <resource-env-ref>, respectively, in ejb-jar.xml. |
<export-name> | Used when an entity or object is exported to JNDI. |
<ref-name> and <export-name> tags must be same with the names defined in ejb-jar.xml.
The following is an example of annotation and XML that illustrates how to map external references to JNDI.
[Example 4.4] Mapping External Reference to JNDI: <<CounterEJB.java>>
@Stateful @EJB(name="AccountEJB", beanInterface=ejb.Account.class, mapppedName="ACCEJB") @Resource(name="jdbc/DBDS", type=javax.sql.DataSource.class, mappedName="ACCOUNTDB") public class CounterEJB implements Counter{ @Resource(name="minAmount") private int minAccount = 100; . . . }
[Example 4.5] Mapping External Reference to JNDI: <<ejb-jar.xml>>
<ejb-jar.xml> . . . <enterprise-beans> <session> . . . <env-entry> <env-entry-name>minAmount</env-entry-name> <env-entry-type>java.lang.Integer</env-entry-type> </env-entry> <ejb-ref> <ejb-ref-name>AccountEJB</ejb-ref-name> <ejb-ref-type>Session<ejb-ref-type> <remote>ejb.Account</remote> </ejb-ref> <resource-ref> <res-ref-name>jdbc/DBDS</res-ref-name> <res-ref-type>javax.sql.DataSource</res-ref-type> </resource-ref> . . . </session> </enterprise-beans> . . . </ejb-jar.xml>
[Example 4.6] Mapping External Reference to JNDI: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd> . . . <beanlist> <jeus-bean> . . . <env> <name>minAmount</name> <type>java.lang.Integer</type> <value>100</value> </env> <ejb-ref> <jndi-info> <ref-name>AccountEJB</ref-name> <export-name>ACCEJB</export-name> </jndi-info> </ejb-ref> <res-ref> <jndi-info> <ref-name>jdbc/DBDS</ref-name> <export-name>ACCOUNTDB</export-name> </jndi-info> </res-ref> . . . </jeus-bean> . . . </beanlist> . . . </jeus-ejb-dd>
In order to set up HTTP invocation on a specific EJB module, <invoke-http> needs to be configured inside the <jeus-bean> element of jeus-ejb-dd.xml. If an EJB engine needs HTTP invocation, add the <invoke-http> tag to the ejb-engine in the jeus-ejb-dd.xml file. (mentioned in "Chapter 2. EJB Engine"). Settings in the domain.xml file will be applied to all the modules, but if the DD of each module contains the <invoke-http> setting, the setting in DD file is used.
The following example configures the HTTP invoke environment properties in jeus-ejb-dd.xml.
[Example 4.7] HTTP Invoke Configuration: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd> . . . <beanlist> <jeus-bean> . . . <invoke-http> <url> /mycontext/RMIServletHandler </url> <http-port> 80 </http-port> </invoke-http> . . . </jeus-bean> </beanlist> . . . </jeus-ejb-dd>
<invoke-http> tag has the following two child tags.
The RMI handler servlet must be deployed to successfully execute an HTTP invoke. The class to implement the RMI handler servlet is jeus.rmi.http.ServletHandler. The jeus.rmi.http.ServletHandler must be deployed to the URL specified in the <invoke-http> element of the context. For more information about deployment, refer to "JEUS Web Engine Guide".
JEUS provides JEUS RMI communication that helps improve its performance. This RMI is useful especially when there are many clients, because it can also use Non-blocking IO to communicate. In order to use JEUS RMI, you only need to configure JEUS_HOME/lib/client/jclient.jar, the client library file, to the classpath.
Specify whether to use JEUS RMI in the jeus-ejb-dd.xml file of each bean, or use the system property (-Djeus.ejb.rmi.jeus=true) for the entire JEUS system. DD configuration has higher priority than the latter.
Communication layer details, such as whether to use Blocking IO or Non-blocking IO and whether to use channel or socket for JEUS RMI, can be configured through the system property. For more information, refer to "JEUS Reference Book".
This section describes how to configure security for EJB in JEUS. Here security refers to certification and authorization.
The following issues are covered by JEUS EJB security settings.
Role assignment of EJB modules
EJB run-as Identify setting
The actual JEUS user list that is used by EJB setting is defined in the accounts.xml file. Refer to the "JEUS Security Guide".
The following explains how to configure security settings for each case.
The role assignment setting of EJB is mapping developer-defined role of the ejb-jar.xml file with principal and group name of the actual JEUS security domain. Configure this setting in the <role-permission> element inside the <module-info> element of the jeus-ejb-dd.xml file.
The following is an example of configuring a role in XML.
[Example 4.8] Role Assignment Configuration: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd>
<module-info>
<role-permission>
<role>manager</role>
<principal>peter</principal>
</role-permission>
</module-info>
<beanlist>
. . .
</beanlist>
. . .
</jeus-ejb-dd>
The two necessary child tags are as follows:
Run-as identity setting provides the actual mapping of developer-defined role name in the <run-as> tag of the ejb-jar.xml file with the actual principal specified in the JEUS security domain configuration (e.g., in the accouts.xml file).
This principal, in general, uses a simple user name. This setting is configured in the <run-as-identity> tag, which is at the same level as the bean configuration in jeus-ejb-dd.xml.
The following is an example of XML setting for run-as identity.
[Example 4.9] Run-as Identify Configuration: <<jeus-ejb-dd.xml>>
<jeus-ejb-dd>
. . .
<beanlist>
<jeus-bean>
. . .
<run-as-identity>
<principal-name>peter</principal-name>
</run-as-identity>
. . .
</jeus-bean>
. . .
</beanlist>
. . .
</jeus-ejb-dd>
Tag | Description |
---|---|
<principal-name> | Specifies the user name to map with role in the <run-as> element of the ejbjar.xml file. This user name should be specified in the accounts.xml file. |
The following examples show how the role of role-permission and role of run-as are mapped to an actual JEUS user.
Some parts of Java classes and XML are taken from three configuration files (ejb-jar.xml, jeus-ejb-dd.xml, and accounts.xml). The identical parts in these files are highlighted in bold.
[Example 4.10] Security Setting: <<CustomerBean.java>>
@Stateless(name="CustomerEJB")
@RolesAllowed("CUSTOMER")
public class CustomerBean implementes Customer {
...
}
[Example 4.11] Security Setting: <<EmployeeServiceBean.java>>
@Stateful(name="EmployeeService")
@RunAs("ADMIN")
public class EmployeeServiceBean implements EmployService{
...
}
[Example 4.12] Security Setting: <<ejb-jar.xml>>
<?xml version="1.0"?> <ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"> <enterprise-beans> <session> <ejb-name>CustomerEJB</ejb-name> . . . <security-role-ref> <role-name>CUSTOMER</role-name> </security-role-ref> <security-identity> <use-caller-identity /> </security-identity> </session> <session> <ejb-name>EmployeeService</ejb-name> . . . <security-identity> <run-as> <role-name>ADMIN</role-name> </run-as> </security-identity> </session> . . . </enterprise-beans> <assembly-descriptor> <security-role> <role-name>CUSTOMER</role-name> </security-role> <method-permission> <role-name>CUSTOMER</role-name> <method> <ejb-name>CustomerEJB</ejb-name> <method-name>*</method-name> <method-params /> </method> </method-permission> . . . </assembly-descriptor> . . . </ejb-jar>
The previous example defines two session beans.
The first bean (CustomerEJB) has a security role connected to the CUSTOMER role.
The second session bean (EmployeeService) defines the <run-as> role as ADMIN. The roles CUSTOMER and ADMIN should be mapped to actual system Principals when EJB is deployed.
The following example shows how the roles, CUSTOMER and ADMIN are mapped to the actual system principal names (customer and peter, respectively).
[Example 4.13] Security Setting: <<jeus-ejb-dd.xml>>
<?xml version="1.0" encoding="UTF-8"?> <jeus-ejb-dd xmlns="http://www.tmaxsoft.com/xml/ns/jeus"> <module-info> . . . <role-permission> <principal>customer</principal> <role>CUSTOMER</role> </role-permission> </module-info> <beanlist> <jeus-bean> <ejb-name>EmployeeService</ejb-name> <run-as-identity> <principal-name>peter</principal-name> </run-as-identity> </jeus-bean> . . . </beanlist> . . . </jeus-ejb-dd>
The following example shows how these users are configured in the accounts.xml file.
[Example 4.14] Security Setting: <<accounts.xml>>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <accounts xmlns="http://www.tmaxsoft.com/xml/ns/jeus"> <users> <user> <name>customer</ name> <password>{SHA}blSUPYpdjb8QDcq+ozfbIEZx5oY=</name> <group>test</group> </user> <user> <name>peter</ name> <password>{SHA}McbQlyhI3yiOG1HGTg8DQVWkyhg=</name> <group>test</group> </user> </users> </accounts>
The previous example shows definition for the users,
customer and peter. These users are connected to the roles, CUSTOMER
and ADMIN, of the ejb-jar.xml file through the jeus-ejbdd.xml
file.
JEUS does not provide a method to control each EJB included in the EJB module. However, it is possible to monitor each bean through the jeusadmin or WebAdmin. It is recommended to use the WebAdmin.
In the console tool, each EJB information including bean name, export name, and status can be displayed using the application-info command. If an EJB called countermod is deployed, use the following command.
As the result of the previous command, the name and export name of each bean registered to the EJB module are displayed.
[DAS]domain1.adminServer>application-info -server server1 -id countermod -detail
General information about the EJB module [countermod].
==============================================================
+-------------+----------------------------------------------+
| Module Name | Unique Module Name |
+-------------+----------------------------------------------+
| countermod | countermod |
+-------------+----------------------------------------------+
==============================================================
Beans
================================================================================
+-----------+-------------------------+-------------------+--------------------+
| Bean Name | Type | Local Export Name | Remote Export Name |
+-----------+-------------------------+-------------------+--------------------+
| Count | StatelessSessionBean | | Count |
+-----------+-------------------------+-------------------+--------------------+
================================================================================
The status of each bean in EJB module can be monitored with the following command.
[DAS]domain1.adminServer>application-info -server server1 -id countermod -bean Count
Module name : countermod
Bean name : Count
================================================================================
+---------------+-----------+-------------------+--------------+---------------+
| Name | (Count) | WaterMark(High:Low| Bound(Upper:L| Time(Max:Min:T|
| | | :Cur) | ower) | otal) |
+---------------+-----------+-------------------+--------------+---------------+
| create | times(0) | | | |
+---------------+-----------+-------------------+--------------+---------------+
| comitted | transactio| | | |
| |n(0) | | | |
+---------------+-----------+-------------------+--------------+---------------+
| total-remote-t| |thread(100:100:100)| | |
|hread | | | | |
+---------------+-----------+-------------------+--------------+---------------+
| timed-rb | transactio| | | |
| |n(0) | | | |
+---------------+-----------+-------------------+--------------+---------------+
| remove | times(0) | | | |
+---------------+-----------+-------------------+--------------+---------------+
| active-bean | | bean(0:0:0) | | |
+---------------+-----------+-------------------+--------------+---------------+
| request | request(0)| | | |
+---------------+-----------+-------------------+--------------+---------------+
| total-bean | | bean(0:0:0) | | |
+---------------+-----------+-------------------+--------------+---------------+
| rolledback | transactio| | | |
| |n(0) | | | |
+---------------+-----------+-------------------+--------------+---------------+
| active-thread | | thread(0:0:0) | | |
+---------------+-----------+-------------------+--------------+---------------+
| MethodReadyCou| | bean(0:0:0) | | |
|nt | | | | |
+---------------+-----------+-------------------+--------------+---------------+
================================================================================
For more information about the application-info command, refer to JEUS Reference Book. "4.2.6.3. application-info".
There are some settings that can be uniformly applied to all EJB types in order to enhance EJB operation performance (or to prevent system resources from being wasted):
Adjust the max value of TTP.
Configure beans after clustering beans from several EJB engines. Refer to "Chapter 6. EJB Clustering".
Configure a proper JDBC connection pool. Refer to the "JEUS Server Guide".
For EJB 2.x, use the -fast option and the appcompiler to save the deployment time of EJB modules. Refer to "Chapter 3. EJB Module".
There are many tuning tips for each bean type besides the already mentioned basic optimization options. Therefore, look up the corresponding chapter for optimization and tuning method recommended for each EJB type.
The TTP should be configured correctly for an EJB to exhibit the best performance. You can apply the following principles for this.
The larger the specified max pool size, the more TTs can be generated and more client requests can be processed. However, a large max pool size consumes more memory resources.
If the number of clients who request a service of a bean increases rapidly at a specific time, increase the pool size by subtracting the min pool size from the max pool size. This enables the new TTs to be created in batches.
TTP setting acts as a valve that controls the volume of accesses to a certain EJB.
The max pool size is the most important parameter in the thread ticket pool. Therefore, this value should be adjusted and tuned first to improve performance. Set this value to <threadmax>.