⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getjini.java

📁 基于JMS的消息,用包括界面代码,主要用初学都学习
💻 JAVA
字号:
package com.sjx.jms;

import java.util.*;
import javax.jms.*;
import javax.naming.*;

public class GetJini {
	
	public GetJini(){}
	
	public static Context getContext(){
		Context  context = null;
		try {
			Hashtable property = new Hashtable();
			property.put(Context.INITIAL_CONTEXT_FACTORY,  "org.exolab.jms.jndi.InitialContextFactory"); 
			property.put(Context.PROVIDER_URL,"rmi://localhost:1099/");
			//context = new InitialContext(property);
			context = new InitialContext(property); 
		} catch (NamingException e) {
			e.printStackTrace();
		}
		if(context == null){
			System.out.println("Context 初始化失败");
			System.exit(0);
		}
		return context;
	}
	
	public static QueueConnectionFactory getQueueConnectionFactory(Context context){
		QueueConnectionFactory qcfy = null;
		try {
			qcfy = (QueueConnectionFactory)context.lookup("JmsQueueConnectionFactory");
		} catch (NamingException e) {
			e.printStackTrace();
		}
			return qcfy;
	}
	
	public static QueueConnection getQueueConnection(QueueConnectionFactory queueConnectionFactory){
		QueueConnection queueConnection = null;
		try {
			queueConnection = queueConnectionFactory.createQueueConnection();
		} catch (JMSException e) {
			e.printStackTrace();
		}  
		return queueConnection;
	}
	
	public static TopicConnectionFactory getTopicConnectionFactory(Context context){
		
		TopicConnectionFactory factory =  null;
		try {
			factory =
			    (TopicConnectionFactory) context.lookup( "JmsTopicConnectionFactory");
		} catch (NamingException e) {
			e.printStackTrace();
		}
		return factory;
	}
	
	public static void closeTopicConnection(TopicConnection connection){		
		try {
			connection.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	public static void closeTopicSession(TopicSession topicSession){		
		try {
			topicSession.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeTopicPublisher(TopicPublisher topicPublisher){		
		try {
			topicPublisher.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeTopicSubscriber(TopicSubscriber topicSubscriber){		
		try {
			topicSubscriber.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	
	public static TopicConnection getTopicConnection(TopicConnectionFactory factory){
		TopicConnection topicConnection =  null;
		try {
			topicConnection=factory.createTopicConnection();
		} catch (JMSException e) {
			e.printStackTrace();
		}
		return topicConnection;
	}
	
	public static void closeQueudSender(QueueSender queueSender){
		try {
			queueSender.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeQueueSession(QueueSession queueSession){
		try {
			queueSession.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeQueueConnection(QueueConnection queueConnection){
		try {
			queueConnection.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeContext(Context context){
		try {
			context.close();
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	
	
	public static void closeQueueReceive(QueueReceiver queueReceiver){
		try {
			queueReceiver.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -