本文整理匯總了Java中javax.jms.Session.getTransacted方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.getTransacted方法的具體用法?Java Session.getTransacted怎麽用?Java Session.getTransacted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.Session
的用法示例。
在下文中一共展示了Session.getTransacted方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNotIdledWhenInUse
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testNotIdledWhenInUse() throws Exception {
cf.setIdleTimeout(10);
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// let connection to get idle
TimeUnit.MILLISECONDS.sleep(20);
// get a connection from pool again, it should be the same underlying connection
// as before and should not be idled out since an open session exists.
JmsPoolConnection connection2 = (JmsPoolConnection) cf.createConnection();
assertSame(connection.getConnection(), connection2.getConnection());
// now the session is closed even when it should not be
try {
// any operation on session first checks whether session is closed
s.getTransacted();
} catch (javax.jms.IllegalStateException e) {
assertTrue("Session should be fine, instead: " + e.getMessage(), false);
}
Connection original = connection.getConnection();
connection.close();
connection2.close();
// let connection to get idle
TimeUnit.MILLISECONDS.sleep(20);
// get a connection from pool again, it should be a new Connection instance as the
// old one should have been inactive and idled out.
JmsPoolConnection connection3 = (JmsPoolConnection) cf.createConnection();
assertNotSame(original, connection3.getConnection());
}
示例2: testNotIdledWhenInUse
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testNotIdledWhenInUse() throws Exception {
pooledFactory.setIdleTimeout(10);
JmsPoolConnection connection = (JmsPoolConnection) pooledFactory.createConnection();
Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// let connection to get idle
TimeUnit.MILLISECONDS.sleep(20);
// get a connection from pool again, it should be the same underlying connection
// as before and should not be idled out since an open session exists.
JmsPoolConnection connection2 = (JmsPoolConnection) pooledFactory.createConnection();
assertSame(connection.getConnection(), connection2.getConnection());
// now the session is closed even when it should not be
try {
// any operation on session first checks whether session is closed
s.getTransacted();
} catch (javax.jms.IllegalStateException e) {
assertTrue("Session should be fine, instead: " + e.getMessage(), false);
}
Connection original = connection.getConnection();
connection.close();
connection2.close();
// let connection to get idle
TimeUnit.MILLISECONDS.sleep(20);
// get a connection from pool again, it should be a new Connection instance as the
// old one should have been inactive and idled out.
JmsPoolConnection connection3 = (JmsPoolConnection) pooledFactory.createConnection();
assertNotSame(original, connection3.getConnection());
}
示例3: doPublish
import javax.jms.Session; //導入方法依賴的package包/類
protected void doPublish(Event event) throws EdsException {
Connection conn = null;
Session session = null;
MessageProducer messageProducer = null;
try {
LOG.debug("eds pub 3 mq in -[event:" + event + "]");
conn = connectionFactory.createConnection();
// 設置非事務,客戶端確認方式
session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MapMessage mapMessage = session.createMapMessage();
mapMessage = EventConverter.convertToMessage(mapMessage, event);
Destination dest = getDestination(event.getName(), session);
messageProducer = session.createProducer(dest);
messageProducer.send(mapMessage);
// commit session if necessary
if (session.getTransacted()) {
session.commit();
}
LOG.debug("eds pub 4 mq ok -[conn:" + conn + ",session:" + session + ",event:" + event + "]");
}catch(JMSException e){
throw new EdsException("eds client activemq doPublish exception ", e);
}finally {
releaseSession(session);
releaseMessageProducer(messageProducer);
releaseConnection(conn, false);
}
}
示例4: loadSession
import javax.jms.Session; //導入方法依賴的package包/類
private synchronized Session loadSession( final boolean transacted,
final int acknowledgeMode ) throws JMSException {
final Session s = session;
if (s != null) {
if ( (s.getTransacted() == transacted) && (s.getAcknowledgeMode() == acknowledgeMode)) {
return s;
}
s.close();
}
final Session newSession = loadConnection().createSession(transacted, acknowledgeMode);
session = newSession;
return newSession;
}