📄 poolreceive.java
字号:
//声明这个类所在的包为examples.jms.startup
package examples.jms.startup;
//声明这个类引入的其它类 和包
import java.io.*;
import java.util.*;
import javax.transaction.*;
import javax.naming.*;
import javax.jms.*;
import weblogic.common.*;
import weblogic.jms.ServerSessionPoolFactory;
/**
*
* 这个例子演示怎样从启动类建立消息监听器(MsgListener定义)池。
* 当消息从主题接收,它们显示在命令行。可以用TopicSend客户端发送消息。
*/
public class PoolReceive
implements T3StartupDef
{
//声明构造器
private final static String SESSION_POOL_FACTORY=
"weblogic.jms.ServerSessionPoolFactory:examplesJMSServer";
//声明t3服务
private T3ServicesDef services;
//声明主题消息构造器
private TopicConnectionFactory tconFactory;
//声明主题连接
private TopicConnection tcon;
//声明主题会话
private TopicSession tsession;
//声明主题消息
private Topic topic;
//声明会话池构造器
private ServerSessionPoolFactory sessionPoolFactory;
//声明会话池
private ServerSessionPool sessionPool;
//声明ConnectionConsumer
private ConnectionConsumer consumer;
/**
* 设置t3服务对象
*
* @参数 services Services stub.
*/
public void setServices(T3ServicesDef services) {
this.services = services;
}
/**
* 创建使用者
* @参数 name 名字
* @参数 args Hashtable.
* @异常 Exception if problems occurs
*/
public String startup(String name, Hashtable args)
throws Exception
{
//从参数哈希表中获取连接构造器
String connectionFactory = (String)args.get("connectionFactory");
//从参数哈希表中获取主题名
String topicName = (String)args.get("topic");
if (connectionFactory == null || topicName == null) {
//抛出异常
throw new IllegalArgumentException("connectionFactory="+connectionFactory+
", topicName="+topicName);
}
//实例上下文
Context ctx = new InitialContext();
//通过上下文查找连接构造器
tconFactory = (TopicConnectionFactory) ctx.lookup(connectionFactory);
//创建主题连接
tcon = tconFactory.createTopicConnection();
//创建主题会话
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
//查找主题
topic = (Topic) ctx.lookup(topicName);
//启动连接
tcon.start();
//查找会话池构造器
sessionPoolFactory = (ServerSessionPoolFactory)
ctx.lookup(SESSION_POOL_FACTORY);
//获取会话池
sessionPool = sessionPoolFactory.
getServerSessionPool(tcon, 5, false,
Session.AUTO_ACKNOWLEDGE,
"examples.jms.startup.MsgListener");
//获取连接池使用者
consumer = tcon.createConnectionConsumer(topic, "TRUE", sessionPool, 10);
return "Ready To Receive Messages";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -