本文整理匯總了Java中javax.jms.Session.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.close方法的具體用法?Java Session.close怎麽用?Java Session.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.Session
的用法示例。
在下文中一共展示了Session.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putTopic
import javax.jms.Session; //導入方法依賴的package包/類
private void putTopic(List<String> events) throws Exception {
ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
PASSWORD, BROKER_BIND_URL);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
}
session.commit();
session.close();
connection.close();
}
示例2: testRun
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testRun() throws Exception {
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
session.run();
fail("Session should be unable to run outside EE.");
} catch (JMSRuntimeException jmsre) {}
session.close();
try {
session.run();
fail("Session should be closed.");
} catch (IllegalStateRuntimeException isre) {}
}
示例3: sendWithReplyToTemp
import javax.jms.Session; //導入方法依賴的package包/類
private void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException, InterruptedException {
Connection connection = cf.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Request");
msg.setJMSReplyTo(tempQueue);
MessageProducer producer = session.createProducer(session.createQueue(serviceQueue));
producer.send(msg);
MessageConsumer consumer = session.createConsumer(tempQueue);
Message replyMsg = consumer.receive();
assertNotNull(replyMsg);
LOG.debug("Reply message: {}", replyMsg);
consumer.close();
producer.close();
session.close();
connection.close();
}
示例4: createMessage
import javax.jms.Session; //導入方法依賴的package包/類
public Message createMessage(Object messageObject) throws JMSException {
Connection connection = null;
Message result = null;
try {
connection = startConnection();
Session session = null;
try {
session = connection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
if (messageObject == null) {
result = session.createMessage();
} else {
if (messageObject instanceof String) {
result = session.createTextMessage((String) messageObject);
} else {
result = session.createObjectMessage((Serializable) messageObject);
}
}
} finally {
if (session != null) session.close();
}
} finally {
safeCloseConnection(connection);
}
return result;
}
示例5: call
import javax.jms.Session; //導入方法依賴的package包/類
/**
* @return true if session created, false otherwise
*/
@Override
public Boolean call() {
Session session = null;
try {
session = PooledConnectionFactoryMaximumActiveTest.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TASK_LOG.info("Created new Session with id" + session);
PooledConnectionFactoryMaximumActiveTest.addSession(session);
} catch (Exception ex) {
TASK_LOG.error(ex.getMessage());
return new Boolean(false);
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
}
}
}
return new Boolean(session != null);
}
示例6: testToString
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testToString() throws Exception {
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session.toString());
session.close();
assertNotNull(session.toString());
}
示例7: 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;
}
示例8: testPooledSessionStatsOneSessionWithSessionLimit
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testPooledSessionStatsOneSessionWithSessionLimit() throws Exception {
cf.setMaximumActiveSessionPerConnection(1);
cf.setBlockIfSessionPoolIsFull(false);
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
assertEquals(0, connection.getNumActiveSessions());
// Create one and check that stats follow
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertEquals(1, connection.getNumActiveSessions());
assertEquals(0, connection.getNumtIdleSessions());
assertEquals(1, connection.getNumSessions());
try {
connection.createSession();
fail("Should not be able to create new session");
} catch (IllegalStateException ise) {}
// Nothing should have changed as we didn't create anything.
assertEquals(1, connection.getNumActiveSessions());
assertEquals(0, connection.getNumtIdleSessions());
assertEquals(1, connection.getNumSessions());
session.close();
// All back in the pool now
assertEquals(0, connection.getNumActiveSessions());
assertEquals(1, connection.getNumtIdleSessions());
assertEquals(1, connection.getNumSessions());
connection.close();
}
示例9: run
import javax.jms.Session; //導入方法依賴的package包/類
public void run() {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
connection.setExceptionListener(this);
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("HELLOWORLD.TESTQ");
// Create a MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive(1000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println("Received: " + text);
} else {
System.out.println("Received: " + message);
}
consumer.close();
session.close();
connection.close();
} catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
示例10: sendMessage
import javax.jms.Session; //導入方法依賴的package包/類
public void sendMessage(Message message) throws JMSException {
Connection connection = null;
try {
connection = startConnection(); //try to be smarter here and initiate start connection
Session session = null;
try {
session = connection.createSession(isTransacted, Session.AUTO_ACKNOWLEDGE);
Destination dest;
if (isQueue) {
dest = session.createQueue(destinationName);
} else {
dest = session.createTopic(destinationName);
}
MessageProducer producer = session.createProducer(dest);
try {
if (isPersistant) producer.setDeliveryMode(DeliveryMode.PERSISTENT);
if (timeToLive > 0) producer.setTimeToLive(timeToLive);
producer.send(message);
} finally {
if (producer != null) producer.close();
}
} finally {
if (session != null) session.close();
}
} finally {
safeCloseConnection(connection);
}
}
示例11: testTempQueueIssue
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testTempQueueIssue() throws JMSException, InterruptedException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
"vm://localhost?broker.persistent=false&broker.useJmx=false");
final JmsPoolConnectionFactory cf = new JmsPoolConnectionFactory();
cf.setConnectionFactory(factory);
Connection connection = cf.createConnection();
assertNotNull(connection);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
LOG.info("First connection was {}", connection);
// This order seems to matter to reproduce the issue
connection.close();
session.close();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
try {
receiveAndRespondWithMessageIdAsCorrelationId(cf, SERVICE_QUEUE);
} catch (JMSException e) {
e.printStackTrace();
}
}
});
sendWithReplyToTemp(cf, SERVICE_QUEUE);
cf.stop();
}
示例12: testRepeatedCreateSessionProducerResultsInSame
import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testRepeatedCreateSessionProducerResultsInSame() throws Exception {
JmsPoolConnection connection = (JmsPoolConnection) pooledFactory.createConnection();
assertTrue(pooledFactory.isUseAnonymousProducers());
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createTopic("test-topic");
JmsPoolMessageProducer producer = (JmsPoolMessageProducer) session.createProducer(destination);
MessageProducer original = producer.getMessageProducer();
assertNotNull(original);
session.close();
assertEquals(1, brokerService.getAdminView().getDynamicDestinationProducers().length);
for (int i = 0; i < 20; ++i) {
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = (JmsPoolMessageProducer) session.createProducer(destination);
assertSame(original, producer.getMessageProducer());
session.close();
}
assertEquals(1, brokerService.getAdminView().getDynamicDestinationProducers().length);
connection.close();
pooledFactory.clear();
}
示例13: releaseSession
import javax.jms.Session; //導入方法依賴的package包/類
private static void releaseSession(Session session) {
if (session == null) {
return;
}
try {
session.close();
} catch (Throwable ex) {
LOG.warn("Could not close JMS Session", ex);
}
}
示例14: main
import javax.jms.Session; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("HELLOWORLD.TESTQ");
// Create a MessageProducer from the Session to the Topic or Queue
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a messages
String text = "Hello world! From: " + Thread.currentThread().getName();
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
producer.send(message);
// Clean up
session.close();
connection.close();
}
catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
示例15: main
import javax.jms.Session; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("HELLOWORLD.TESTQ");
// Create a MessageConsumer from the Session to the Topic or Queue
MessageConsumer consumer = session.createConsumer(destination);
// Wait for a message
Message message = consumer.receive(1000);
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String text = textMessage.getText();
System.out.println("Received: " + text);
} else {
System.out.println("Received: " + message);
}
consumer.close();
session.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}