📄 connectionimpl.java
字号:
/**
* Project:ms4j
* Date:2007-2-15
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package com.sunjob.ms4j.client;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionConsumer;
import javax.jms.ConnectionMetaData;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.ServerSessionPool;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicSession;
import javax.jms.XAConnection;
import javax.jms.XAQueueConnection;
import javax.jms.XAQueueSession;
import javax.jms.XASession;
import javax.jms.XATopicConnection;
import javax.jms.XATopicSession;
/**
* @author sunjob
*
*/
public class ConnectionImpl implements Connection, QueueConnection,
TopicConnection, XAConnection, XAQueueConnection, XATopicConnection {
public static int GENERATE_CONNECTION_TYPE = 0;
public static int QUEUE_CONNECTION_TYPE = 1;
public static int TOPIC_CONNECTION_TYPE = 2;
// ////////////////////////////////////////////////
private int ConnType = 0;
private String username = null;
private String password = null;
private boolean supportXA = false;
private Hashtable env = null;
// ///////////////////////////////////////////////
private String clientID = null;
private ExceptionListener eListener = null;
private ConnConsumerThread consumer = null;
public ConnectionImpl(String username, String password, int connectionType,
boolean supportXA, Hashtable env) {
this.ConnType = connectionType;
this.username = username;
this.password = password;
this.supportXA = supportXA;
this.env = env;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#close()
*/
public void close() throws JMSException {
try {
if (consumer != null)
consumer.close();
} catch (Exception e) {
throw new JMSException(e.getLocalizedMessage());
}
consumer = null;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#createConnectionConsumer(javax.jms.Destination,
* java.lang.String, javax.jms.ServerSessionPool, int)
*/
public ConnectionConsumer createConnectionConsumer(Destination destination,
String messageSelector, ServerSessionPool sessionPool,
int maxMessages) throws JMSException {
ConnectionConsumer cc = null;
if (this.clientID != null && destination instanceof Topic) {
cc = this.createDurableConnectionConsumer((Topic) destination,
this.clientID, messageSelector, sessionPool, maxMessages);
} else {
// TODO
cc = null;
}
return cc;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#createDurableConnectionConsumer(javax.jms.Topic,
* java.lang.String, java.lang.String, javax.jms.ServerSessionPool,
* int)
*/
public ConnectionConsumer createDurableConnectionConsumer(Topic topic,
String subscriptionName, String messageSelector,
ServerSessionPool sessionPool, int maxMessages) throws JMSException {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#createSession(boolean, int)
*/
public Session createSession(boolean transacted, int acknowledgeMode)
throws JMSException {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#getClientID()
*/
public String getClientID() throws JMSException {
return this.clientID;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#getExceptionListener()
*/
public ExceptionListener getExceptionListener() throws JMSException {
return this.eListener;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#getMetaData()
*/
public ConnectionMetaData getMetaData() throws JMSException {
return ConnectionMetaDataImpl.getInstance();
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#setClientID(java.lang.String)
*/
public void setClientID(String arg0) throws JMSException {
this.clientID = arg0;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#setExceptionListener(javax.jms.ExceptionListener)
*/
public void setExceptionListener(ExceptionListener arg0)
throws JMSException {
this.eListener = arg0;
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#start()
*/
public void start() throws JMSException {
this.consumer.start();
}
/*
* (non-Javadoc)
*
* @see javax.jms.Connection#stop()
*/
public void stop() throws JMSException {
try {
this.consumer.stop();
} catch (Exception e) {
throw new JMSException(e.getLocalizedMessage());
}
}
/*
* (non-Javadoc)
*
* @see javax.jms.QueueConnection#createConnectionConsumer(javax.jms.Queue,
* java.lang.String, javax.jms.ServerSessionPool, int)
*/
public ConnectionConsumer createConnectionConsumer(Queue queue,
String messageSelector, ServerSessionPool sessionPool,
int maxMessages) throws JMSException {
return this.createConnectionConsumer(queue, messageSelector,
sessionPool, maxMessages);
}
/*
* (non-Javadoc)
*
* @see javax.jms.QueueConnection#createQueueSession(boolean, int)
*/
public QueueSession createQueueSession(boolean transacted,
int acknowledgeMode) throws JMSException {
return (QueueSession) this.createSession(transacted, acknowledgeMode);
}
/*
* (non-Javadoc)
*
* @see javax.jms.TopicConnection#createConnectionConsumer(javax.jms.Topic,
* java.lang.String, javax.jms.ServerSessionPool, int)
*/
public ConnectionConsumer createConnectionConsumer(Topic topic,
String messageSelector, ServerSessionPool sessionPool,
int maxMessages) throws JMSException {
return this.createConnectionConsumer(topic, messageSelector,
sessionPool, maxMessages);
}
/*
* (non-Javadoc)
*
* @see javax.jms.TopicConnection#createTopicSession(boolean, int)
*/
public TopicSession createTopicSession(boolean transacted,
int acknowledgeMode) throws JMSException {
return (TopicSession) this.createSession(transacted, acknowledgeMode);
}
/*
* (non-Javadoc)
*
* @see javax.jms.XAConnection#createXASession()
*/
public XASession createXASession() throws JMSException {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
*
* @see javax.jms.XAQueueConnection#createXAQueueSession()
*/
public XAQueueSession createXAQueueSession() throws JMSException {
return (XAQueueSession)this.createXASession();
}
/*
* (non-Javadoc)
*
* @see javax.jms.XATopicConnection#createXATopicSession()
*/
public XATopicSession createXATopicSession() throws JMSException {
return (XATopicSession)this.createXASession();
}
}
class ConnConsumerThread extends Thread {
public void run() {
}
public void close() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -