티스토리 뷰
728x90
반응형
EJB3에 대한 아주 기초적인 내용이다...그냥 정리 정도로 생각하면 될듯.
1. EJB Component Types
_ Session beans: stateless
_ Session beans: stateful
_ Session beans: Singleton bean <New feature>
_ Message-driven EJB (MDB)
1-1. Session beans : stateless
정의 : 기본적으로 단건 처리를 하고 사라지는 object이다. 보통 비지니스 로직을 만들때 사용되고 클라이언트 specific한 상태를
저장할 수 없다.(예 : 계좌간의 돈을 이체하는 비지니스 로직)
디폴트로 local interface를 사용한다.
만약에 외부에 같은 bean을 노출시키고 싶다고 아래와 같이 @Remote를 쓰면 된다.
@Remote(MyRemoteBusinessInterface.class)
@Stateless
public class MyBean implements MyRemoteBusinessInterface {
// ejb methods
.....
}
|
Tip: If the session bean implements only one interface, you can use the
@Remote annotation without a class name.
@Remote annotation without a class name.
1-2. Session beans: stateful
정의 : 딱 stateless의 반대개념. 비지니스 로직보단 하나의 일을 담당하는 또는 비지니스 절차를 만들때
사용된다. 매번 client의 specific한 data를 저장하고 이를 이용하여 어떠한 일을 하게 된다.
1-3. Session beans: Singleton bean
정의 : 이름에서 알수 있듯이 Singleton 패턴이 적용된 bean을 의미한다. 대신 start up 시에 initial 할 수 있는 기회를 준다는 게
좀 다르다.. (보통 프로그램 중에 생성이 되는데..)
@Startup
@Singleton
@LocalBean
public class MySingletonBean{
// ejb methods
.....
}
|
1-4. Message Driven Bean
정의 : MDBs are used for the processing of asynchronous Java Message Service (JMS) messages within JEE-based applications. MDBs are invoked by the container on the arrival of a message.
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination",propertyValue="queue/myQueue") })) public class MyMessageBean implements javax.jms.MessageListener { public void onMessage(javax.msg.Message inMsg) { //implement the onMessage method to handle the incoming message .... } } |
2.Business interface (remote and local)
- A business interface cannot be both a local and a remote business interface of the bean. (비지니스 인터페이스는 Remote와 local을 동시에 사용못함 ==> 파일을 두개 만들고 나중에 원하는대로 사용하면 된다. )
- If a bean class implements a single interface, that interface is assumed to be the business interface of the bean. This business interface is a local interface, unless the interface is designated as a remote business interface by use of the @Remote annotation or by means of the deployment descriptor.(하나의 인터페이스에 연결된 object가 하나면 내부적으로 local을 사용하게 된다.)
- If a bean class implements a single interface, that interface is assumed to be the business interface of the bean. This business interface is a local interface, unless the interface is designated as a remote business interface by use of the @Remote annotation or by means of the deployment descriptor.(하나의 인터페이스에 연결된 object가 하나면 내부적으로 local을 사용하게 된다.)
How to organize the EJB component interfaces
@Stateless
public class MyFirstSessionBean
implements MyLocalBusinessInterface, MyRemoteBusinessInterface {
// implementation of methods declared in MyLocalBusinessInterface
....
// implementation of methods declared in MyRemoteBusinessInterface
....
}
|
주의사항
- RemoteException을 사용하면 안된다.
- 모든 Exception은 EJBException으로 Container에 의해 wrap 된다.
Tip. EJB 3.x에서부터는 local interface가 없이도 session bean을 만들수 있다.
3. EJB Life Cycle (of stateless session bean)
EJB2.1에서 사용하던 ejbPassivate, ejbActivate, ejbLoad, and ejbStore와 같은 역활을 한다.
Example 12-9 Stateless session bean with two callback methods
@Stateless
public class MyStatelessBean implements MyBusinessLogic {
// .. bean business method
@PostConstruct
public void initialize() {
// initialize the resources uses by the bean
}
@PreDestroy
public void cleanup() {
// deallocates the resources uses by the bean
}
}
|
stateful session beans 는 더 많은 callback 메소드를 가지고 있다. 이것은 passivate와 activate를 왔다갔다 할 수 있다.
이 빈은 메모리와 storage를 사이를 이동할 수 있다.
_ The EJB container invokes the method annotated with @PrePassivate, immediately before passivating it.
_ If a client invokes a business method on the bean while it is in the passivestage, the EJB container activates the bean by calling the method annotated with @PostActivate and then moves it to the ready stage.
|
제일 마지막에 client가 임의대로 부를 수 있는 callback 메소드는 @Remove이다.
반응형
'이제 관심밖의 IT 기술 > ETC' 카테고리의 다른 글
Junit 4 Assertion 사용을 위한 기본세팅 (0) | 2011.10.26 |
---|---|
JUnit4 특징설명 (0) | 2011.10.26 |
JUnit3 example (0) | 2011.10.26 |
Maven 정리 v0.9 (1) | 2011.10.26 |
Bug Tracker Mantis 설치부터 설정, Mylyn 연동까지!! 완벽 가이드 (0) | 2011.05.30 |
댓글
250x250
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 인터넷
- 벌링턴
- 온타리오
- 정착서비스
- 옥빌
- Red Hat
- redhat
- BC주
- RHCE
- BTBS
- 부모님초청이민
- 토론토정착서비스
- cert
- Canada
- Jay
- 토론토
- certification
- git proGit
- 캐나다부동산
- TORONTO
- 우드워킹
- Certificate
- 밀튼
- docker
- RHEL
- 미시사가
- basement
- 캐나다
- ansible
- 부동산분석
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함