📄 hellomdbean.java
字号:
/*
* Created on 2004-7-2
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.ejbstudy;
import javax.ejb.MessageDrivenBean;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
* @ejb.bean name="HelloMD"
* acknowledge-mode="Auto-acknowledge"
* destination-type="javax.jms.Topic"
* subscription-durability="NonDurable"
* transaction-type="Bean"
*
*--
* This is needed for JOnAS.
* If you are not using JOnAS you can safely remove the tags below.
* @jonas.bean ejb-name="HelloMD"
* jndi-name="HelloMDBean"
*
*--
**/
public class HelloMDBean implements MessageDrivenBean, MessageListener {
/** Required method for container to set context. */
public void setMessageDrivenContext(
javax.ejb.MessageDrivenContext messageContext)
throws javax.ejb.EJBException {
this.messageContext = messageContext;
}
/**
* Required creation method for message-driven beans.
*
* @ejb.create-method
*/
public void ejbCreate() {
// no specific action required for message-driven beans
}
/** Required removal method for message-driven beans. */
public void ejbRemove() {
messageContext = null;
}
/**
* This method implements the business logic for the EJB.
*
* <p>Make sure that the business logic accounts for asynchronous message processing.
* For example, it cannot be assumed that the EJB receives messages in the order they were
* sent by the client. Instance pooling within the container means that messages are not
* received or processed in a sequential order, although individual onMessage() calls to
* a given message-driven bean instance are serialized.
*
* <p>The <code>onMessage()</code> method is required, and must take a single parameter
* of type javax.jms.Message. The throws clause (if used) must not include an application
* exception. Must not be declared as final or static.
*/
public void onMessage(javax.jms.Message message) {
System.out.println("Message Driven Bean got message " + message);
// do business logic here
TextMessage tm=(TextMessage)message;
try{
String content = tm.getText();
int times=tm.getIntProperty("times");
for(int i=0;i<times;i++){
System.out.println("received Message " + Integer.toString(i)+" :"+content);
}
}catch(Exception e){
System.out.println(e.toString());
}
}
/** The context for the message-driven bean, set by the EJB container. */
private javax.ejb.MessageDrivenContext messageContext = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -