當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.close方法代碼示例

本文整理匯總了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();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:21,代碼來源:TestIntegrationActiveMQ.java

示例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) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolSessionTest.java

示例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();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:23,代碼來源:PooledConnectionTempQueueTest.java

示例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;
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:26,代碼來源:JmsClient.java

示例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);
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:27,代碼來源:PooledConnectionFactoryMaximumActiveTest.java

示例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());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:9,代碼來源:JmsPoolSessionTest.java

示例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;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:15,代碼來源:JmsClient.java

示例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();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:35,代碼來源:JmsPoolSessionTest.java

示例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();
    }
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:41,代碼來源:HelloWorldConsumerThread.java

示例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);
	}
}
 
開發者ID:xtf-cz,項目名稱:xtf,代碼行數:31,代碼來源:JmsClient.java

示例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();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:34,代碼來源:PooledConnectionTempQueueTest.java

示例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();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:28,代碼來源:PooledSessionTest.java

示例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);
  }
}
 
開發者ID:eXcellme,項目名稱:eds,代碼行數:11,代碼來源:ActiveMQEventPublisher.java

示例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();
        }
    
	}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:39,代碼來源:HelloWorldProducer.java

示例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();
        }
    
	}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:41,代碼來源:HelloWorldConsumer.java


注:本文中的javax.jms.Session.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。