- 浏览: 101065 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
zhangyulove911:
读XML in a Nutshell (10) -
sunzihao128858:
非常好
Red5源代码分析 - 关键类及其初始化过程 -
还是小鬼:
受用了
Red5源代码分析 - 关键类及其初始化过程 -
qiyue49:
如果有flex4版本,可以直接把C:\Program Fil ...
[转]Flex的中文编译 -
faylai:
标题党骗流量!
20090209-20090211 (about Red5 and Flex)
A session bean is similar to an interactive session. A session bean is not shared; it can have only one client, in the same way that an interactive session can have only one user. Like an interactive session, a session bean is not persistent. (That is, its data is not saved to a database.) When the client terminates, its session bean appears to terminate and is no longer associated with the client.
Stateful Session Beans
The state of an object consists of the values of its instance variables. In a stateful session bean, the instance variables represent the state of a unique client-bean session. Because the client interacts (“talks”) with its bean, this state is often called the conversational state.
The state is retained for the duration of the client-bean session. If the client removes the bean or terminates, the session ends and the state disappears. This transient nature of the state is not a problem, however, because when the conversation between the client and the bean ends there is no need to retain the state.
Stateless Session Beans
A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client, but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained. Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client. That is, the state of a stateless session bean should apply accross all clients.
Because stateless session beans can support multiple clients, they can offer better scalability for applications that require large numbers of clients. Typically, an application requires fewer stateless session beans than stateful session beans to support the same number of clients.
A message-driven bean is an enterprise bean that allows Java EE applications to process messages asynchronously. It normally acts as a JMS message listener, which is similar to an event listener except that it receives JMS messages instead of events. The messages can be sent by any Java EE component (an application client, another enterprise bean, or a web component) or by a JMS application or system that does not use Java EE technology. Message-driven beans can process JMS messages or other kinds of messages.
When a message arrives, the container calls the message-driven bean’s onMessage method to process the message. The onMessage method normally casts the message to one of the five JMS message types and handles it in accordance with the application’s business logic. The onMessage method can call helper methods, or it can invoke a session bean to process the information in the message or to store it in a database.
When a message arrives, the container calls the message-driven bean’s onMessage method to process the message. The onMessage method normally casts the message to one of the five JMS message types and handles it in accordance with the application’s business logic. The onMessage method can call helper methods, or it can invoke a session bean to process the information in the message or to store it in a database.
To create an enterprise bean that allows remote access, you must do one of the following:
Decorate the business interface of the enterprise bean with the @Remote annotation:
@Remote
public interface InterfaceName { ... }
Decorate the bean class with @Remote, specifying the business interface or interfaces:
@Remote(InterfaceName.class)
public class BeanName implements InterfaceName { ... }
If the bean’s business interface is not decorated with @Local or @Remote, and the bean class does not specify the interface using @Local or @Remote, the business interface is by default a local interface. To build an enterprise bean that allows only local access, you may, but are not required to do one of the following:
Annotate the business interface of the enterprise bean as a @Local interface. For example:
@Local
public interface InterfaceName { ... }Specify the interface by decorating the bean class with @Local and specify the interface name. For example:
@Local(InterfaceName.class)
public class BeanName implements InterfaceName { ... }
Whether to allow local or remote access depends on the following factors.
Tight or loose coupling of related beans: Tightly coupled beans depend on one another. For example, if a session bean that processes sales orders calls a session bean that emails a confirmation message to the customer, these beans are tightly coupled. Tightly coupled beans are good candidates for local access. Because they fit together as a logical unit, they typically call each other often and would benefit from the increased performance that is possible with local access.
Type of client: If an enterprise bean is accessed by application clients, then it should allow remote access. In a production environment, these clients almost always run on different machines than the Application Server. If an enterprise bean’s clients are web components or other enterprise beans, then the type of access depends on how you want to distribute your components.
Component distribution: Java EE applications are scalable because their server-side components can be distributed across multiple machines. In a distributed application, for example, the web components may run on a different server than do the enterprise beans they access. In this distributed scenario, the enterprise beans should allow remote access.
Performance: Due to factors such as network latency, remote calls may be slower than local calls. On the other hand, if you distribute components among different servers, you may improve the application’s overall performance. Both of these statements are generalizations; actual performance can vary in different operational environments. Nevertheless, you should keep in mind how your
application design might affect performance.
Although it is uncommon, it is possible for an enterprise bean to allow both remote and local access. If this is the case, either the business interface of the bean must be explicitly designated as a business interface by being decorated with the @Remote or @Local annotations, or the bean class must explicitly designate the business interfaces by using the @Remote and @Local annotations. The same business interface cannot be both a local and remote business interface.
A web service client accesses a stateless session bean through the bean’s web service endpoint implementation class. By default, all public methods in the bean class are accessible to web service clients. The @WebMethod annotation may be used to customize the behavior of web service methods. If the @WebMethod annotation is used to decorate the bean class’s methods, only those methods decorated with @WebMethod are exposed to web service clients.
You package the files in the preceding list into an EJB JAR file, the module that stores the enterprise bean. An EJB JAR file is portable and can be used for different applications. To assemble a Java EE application, you package one or more modules (such as EJB JAR files) into an EAR file, the archive file that holds the application. When you deploy the EAR file that contains the bean’s EJB JAR file, you also deploy the enterprise bean to the Application Server. You can also deploy an EJB JAR that is not contained in an EAR file.
The Life Cycle of a Stateful Session Bean
The client initiates the life cycle by obtaining a reference to a stateful session bean. The container performs any dependency injection and then invokes the method annotated with @PostConstruct, if any. The bean is now ready to have its business methods invoked by the client.
While in the ready stage, the EJB container may decide to deactivate, or passivate, the bean by moving it from memory to secondary storage. (Typically, the EJB container uses a least-recently-used algorithm to select a bean for passivation.) The EJB container invokes the method annotated @PrePassivate, if any, immediately before passivating it. If a client invokes a business method on the bean while it is in the passive stage, the EJB container activates the bean, calls the method annotated @PostActivate, if any, and then moves it to the ready stage.
At the end of the life cycle, the client invokes a method annotated @Remove, and the EJB container calls the method annotated @PreDestroy, if any. The bean’s instance is then ready for garbage collection.
Your code controls the invocation of only one life-cycle method: the method annotated @Remove. All other methods are invoked by the EJB container.
The Life Cycle of a Stateless Session Bean
Because a stateless session bean is never passivated, its life cycle has only two stages: nonexistent and ready for the invocation of business methods.
The client initiates the life cycle by obtaining a reference to a stateless session bean. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if any. The bean is now ready to have its business methods invoked by the client.
At the end of the life cycle, the EJB container calls the method annotated @PreDestroy, if any. The bean’s instance is then ready for garbage collection.
The Life Cycle of a Message-Driven Bean
The EJB container usually creates a pool of message-driven bean instances. For each instance, the EJB container performs these tasks:
If the message-driven bean uses dependency injection, the container injects these references before instantiating the instance.
The container calls the method annotated @PostConstruct, if any.
Like a stateless session bean, a message-driven bean is never passivated, and it has only two states: nonexistent and ready to receive messages.
At the end of the life cycle, the container calls the method annotated @PreDestroy, if any. The bean’s instance is then ready for garbage collection.
Use @Stateless/@Stateful/@MessageDriven annotation decorating the enterprise bean class. This lets the container know that ConverterBean is a stateless/stateful/messagedriven bean.
Java EE application clients refer to enterprise bean instances by annotating static fields with the @EJB annotation.
@EJB
private static Converter converter;
The web service endpoint implementation class has the following requirements:
The class must be annotated with either the javax.jws.WebService or javax.jws.WebServiceProvider annotations.
The implementing class may explicitly reference an SEI through the endpointInterface element of the @WebService annotation, but is not required to do so. If no endpointInterface is specified in @WebService, an SEI is implicitly defined for the implementing class.
The business methods of the implementing class must be public, and must not be declared static or final.
Business methods that are exposed to web service clients must be annotated with javax.jws.WebMethod.
Business methods that are exposed to web service clients must have JAXB-compatible parameters and return types. See Default Data Type Bindings.
The implementing class must not be declared final and must not be abstract.
The implementing class must have a default public constructor.
The endpoint class must be annotated @Stateless.
The implementing class must not define the finalize method.
The implementing class may use the javax.annotation.PostConstruct or javax.annotation.PreDestroy annotations on its methods for life-cycle event callbacks.
The @PostConstruct method is called by the container before the implementing class begins responding to web service clients.
The @PreDestroy method is called by the container before the endpoint is removed from operation.
Stateless session bean can use a timer, when method A is called by client, if there are some logic that would like to be executed asynchronizely after method A return, method A can create a timer, when the timer is timeout, ejb contatiner will find the method defined in the same bean that is marked using @Timeout and execute it.
Methods annotated @Timeout in the enterprise bean class must return void and take a javax.ejb.Timer object as the only parameter. They may not throw application exceptions.
An enterprise bean usually creates a timer within a transaction. If this transaction is rolled back, the timer creation is also rolled back. Similarly, if a bean cancels a timer within a transaction that gets rolled back, the timer cancellation is rolled back. In this case, the timer’s duration is reset as if the cancellation had never occurred.
A system exception indicates a problem with the services that support an application. Examples of these problems include the following: a connection to an external resource cannot be obtained or an injected resource cannot be found. If your enterprise bean encounters a system-level problem, it should throw a javax.ejb.EJBException. Because the EJBException is a subclass of the RuntimeException, you do not have to specify it in the throws clause of the method declaration. If a system exception is thrown, the EJB container might destroy the bean instance. Therefore, a system exception cannot be handled by the bean’s client program; it requires intervention by a system administrator.
An application exception signals an error in the business logic of an enterprise bean. Application exceptions are typically exceptions that you’ve coded yourself, such as the BookException thrown by the business methods of the CartBean example. When an enterprise bean throws an application exception, the container does not wrap it in another exception. The client should be able to handle any application exception it receives.
javax.ejb.TransactionManagement
Declares whether a session bean or message driven bean has container managed transactions or bean managed transactions.
javax.ejb.TransactionAttribute
When applied at the TYPE-level, designates the default transaction attribute for all business methods of the session or message driven bean. When applied at the method-level, designates the transaction attribute for only that method.
The EJB 3.0 spec added Dependency Injection as a main feature. The @Resource annotation can be used to inject several things including EntityManagers, DataSources, Topics, Queues, etc. Most of these are container supplied objects. It is possible, however, to supply your own values to be injected via an <env-entry> in your ejb-jar.xml deployment descriptor. EJB 3.0 supported env-entry types are limited to the following:
java.lang.String
java.lang.Integer
java.lang.Short
java.lang.Float
java.lang.Double
java.lang.Byte
java.lang.Character
java.lang.Boolean
@Inject
Configures a JNDI values for a field or method.
Inject relies heavily on defaults from the field or method name and type. If more information is required, use @Resource, @EJB, or @EJBHome.
@Resource
Configures a JNDI values for a field or method. @Resource is essentially the same as @Inject but provides more configurable options. @Resource can also be used at the Class level to declare a dependency in cases where the session bean loads the JNDI value by itself.
In the following exaple, Resin will call setDataSource method with the data source in "java:comp/env/jdbc/test" before the session is started. The "java:comp/env/jdbc" full name is inferred from the DataSource type.
@Resource(name="test")
private _dataSource;
default JNDI names javax.sql.DataSource java:comp/env/jdbc
javax.mail.* java:comp/env/mail
javax.ejb.EntityManager java:comp/EntityManager
javax.transaction.UserTransaction java:comp/UserTransaction
javax.ejb.EJBHome java:comp/env/ejb
javax.jms.* java:comp/env/jms
发表评论
-
2010 (gwt study)
2010-08-03 07:29 1091In the module XML file, you spe ... -
20100803 (jaas study)
2010-08-03 07:26 669JAAS authentication is performe ... -
20100723 (jpa study)
2010-07-23 10:50 743Each EntityManager instance is ... -
20100723 (JAX-WS study)
2010-07-23 10:49 942The starting point for developi ... -
RMI Summary
2009-08-14 09:49 645UnicastRemoteObject.exportObjec ... -
对Java Generic相关知识的总结
2006-12-13 19:06 3537对于如 List<E> 、 Lis ... -
对java 5除generic外的new features的总结
2006-12-14 12:19 625The for-each loop for (type_na ... -
对javax.swing.undo包的总结
2006-12-14 18:36 675/* UndoableEdit and AbstractUnd ... -
Summary for JTA
2009-01-06 17:06 648JTA is useful not only for diff ...
相关推荐
本资料集`EJB3_study`主要围绕EJB3的核心概念、设计模式以及实际应用展开。 ### 1. EJB3的核心概念 - **实体Bean(Entity Bean)**:代表业务对象,通常与数据库中的记录对应。EJB3引入了注解驱动的实体管理,使得...
### EJB基础知识与核心概念解析 #### EJB的预备知识及学习目标 EJB,即Enterprise JavaBeans,是Java EE平台的关键组成部分,主要用于构建企业级应用程序。它提供了一种标准化的方式来开发、部署和管理分布式组件...
【EJB3 Study】是一个关于企业级Java Bean(Enterprise JavaBeans,简称EJB)3.0版本的学习资源,主要探讨了这一技术在实际项目中的应用和解析。EJB是Java平台上的一个核心组件,用于构建分布式的企业级应用程序,...
**ejb与jsf简介** EJB(Enterprise JavaBeans)是Java EE平台中用于构建企业级应用程序的核心组件。...通过ejb3Study和jsfStudy的学习,你可以深入了解这两种技术,并运用它们来开发功能丰富、高效的Web应用。
### SCBCD 5.0 Study Guide:SUN EJB3.0认证考试知识点解析 #### 一、EJB3.0概述 **知识点1:EJB3.0技术的用途、优势及特性** - **用途与优势**:EJB(Enterprise JavaBeans)3.0是Java EE平台的核心组件之一,...
《Sun Certified Enterprise Architect for J2EE Study Guide》是针对Sun Microsystems公司推出的J2EE企业架构师认证考试的一本详尽指南。这本书旨在帮助读者全面掌握Java企业级应用开发的精髓,以便成功通过这个高...
《Sun Certified Enterprise Architect for Java EE Study Guide》是针对Java企业级架构师认证的一本学习指南,旨在帮助读者理解和掌握Java企业版(Java EE)的高级架构设计与开发技能。这本指南涵盖了广泛的Java EE...
4. **EJB(Enterprise JavaBeans)**:EJB是JavaEE中用于构建服务器端业务逻辑的组件模型,分为会话bean(Session Beans)、实体bean(Entity Beans)和消息驱动bean(Message-Driven Beans)。EJB提供了事务管理、...
### SCEA for J2EE Technology Study Guide (2002) 关键知识点解析 #### 标题:SCEA for J2EE Technology Study Guide (2002) 本指南是针对Sun Certified Enterprise Architect (SCEA) 考试的学习资料,主要聚焦于...
SCBCD Exam Study Kit Java Business Component Developer Certification for EJB.Jun.2005 sun认证材料
4. **EJB(Enterprise JavaBeans)**:EJB提供了一种组件模型,用于创建可部署在JavaEE服务器上的企业级组件,包括会话bean、实体bean和消息驱动bean。 5. **JMS(Java Message Service)**:JMS是Java消息服务,...
《SCEA Study Guide》是针对Sun Certified Enterprise Architect for Java EE (SCEA)认证的一份详尽学习指南。这份指南通常包含多个部分,旨在帮助考生深入理解和掌握Java企业级应用架构设计的关键概念和技术。 ...
《SCWCD Exam Study Kit》是一本专门为准备Sun Certified Web Component Developer(SCWCD)认证考试的考生编写的复习资料。SCWCD是Java web开发领域的重要认证,它验证了开发者在创建Java web组件,如Servlets和JSP...
本资料包“j2ee study”可能是对J2EE学习资料的集合,通过源码分析和工具使用来提升技能。 描述中提到的“博文链接:https://tendyming.iteye.com/blog/1985812”,这可能是一个IT社区博客文章,作者Tendyming分享...
此外,Java EE(企业版)部分则会涵盖Servlet、JSP、JDBC数据库连接、EJB(Enterprise JavaBeans)以及MVC(模型-视图-控制器)架构等内容,这些都是构建web应用程序的基础。 "java-study.pdf"可能还会包含Java ...
此外,EJB(Enterprise JavaBeans)提供了面向组件的分布式计算模型,学习EJB 2.x和3.0版本,同时掌握一种应用服务器的使用,如WebSphere、Weblogic、Tomcat或JBoss,这将有助于你理解Java EE的完整生态系统。...
它提供了开发分布式、多层应用程序所需的服务和API,支持Web服务、EJB(Enterprise JavaBeans)、Servlets、JSP(JavaServer Pages)等。J2EE的核心在于其分层架构,包括客户端层、Web层、业务逻辑层和数据访问层。...
11. **Java EE(企业版)**:包含Servlet、JSP、EJB等技术,用于构建分布式的企业级应用,如Web应用服务器和应用程序服务器。 12. **Spring框架**:Spring是Java领域最流行的开源框架之一,提供依赖注入、AOP(面向...