public synchronized void signalStopToAllSessions() { for (ActiveMQSession session : sessions) { ClientSession coreSession = session.getCoreSession(); if (coreSession instanceof ClientSessionInternal) { ClientSessionInternal internalSession = (ClientSessionInternal) coreSession; internalSession.setStopSignal(); } } }
/** * @param transacted * @param acknowledgeMode * @param session * @param type * @return */ protected ActiveMQSession createAMQSession(boolean isXA, boolean transacted, int acknowledgeMode, ClientSession session, int type) { if (isXA) { return new ActiveMQXASession(options, this, transacted, true, acknowledgeMode, cacheDestinations, enable1xPrefixes, session, type); } else { return new ActiveMQSession(options, this, transacted, false, acknowledgeMode, cacheDestinations, enable1xPrefixes, session, type); } }
@Override public int getAcknowledgeMode() throws JMSException { checkClosed(); return ackMode; }
public void delete() throws JMSException { if (session != null) { if (session.getCoreSession().isClosed()) { // Temporary queues will be deleted when the connection is closed.. nothing to be done then! return; } if (isQueue()) { session.deleteTemporaryQueue(this); } else { session.deleteTemporaryTopic(this); } } }
@Override public MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a shared durable consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return internalCreateSharedConsumer(localTopic, name, messageSelector, ConsumerDurability.DURABLE); }
@Override public TopicSubscriber createDurableSubscriber(final Topic topic, final String name, String messageSelector, final boolean noLocal) throws JMSException { // As per spec. section 4.11 if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a durable subscriber on a QueueSession"); } checkTopic(topic); if (!(topic instanceof ActiveMQDestination)) { throw new InvalidDestinationException("Not an ActiveMQTopic:" + topic); } if ("".equals(messageSelector)) { messageSelector = null; } ActiveMQDestination jbdest = (ActiveMQDestination) topic; if (jbdest.isQueue()) { throw new InvalidDestinationException("Cannot create a subscriber on a queue"); } return createConsumer(jbdest, name, messageSelector, noLocal, ConsumerDurability.DURABLE); }
ActiveMQMessage msg = ActiveMQMessage.createMessage(message, session.getCoreSession(), options); if (session.isEnable1xPrefixes()) { msg.setEnable1xPrefixes(true); message.acknowledge(); } catch (ActiveMQException e) { ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly(); ActiveMQJMSClientLogger.LOGGER.errorProcessingMessage(e); session.getCoreSession().rollback(true); session.setRecoverCalled(true); } catch (Exception e2) { ActiveMQJMSClientLogger.LOGGER.errorRecoveringSession(e2); connection.getThreadAwareContext().clearCurrentThread(false); if (!session.isRecoverCalled() && !individualACK) { try { ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly(); ActiveMQJMSClientLogger.LOGGER.errorProcessingMessage(e); session.setRecoverCalled(false);
@Override public MessageConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a durable consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return createConsumer(localTopic, name, messageSelector, noLocal, ConsumerDurability.DURABLE); }
ClientSession coreSession = session.getCoreSession(); boolean needSession = ackMode == Session.CLIENT_ACKNOWLEDGE || ackMode == ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE || jmsMsg = ActiveMQMessage.createMessage(coreMessage, needSession ? coreSession : null, options); if (session.isEnable1xPrefixes()) { jmsMsg.setEnable1xPrefixes(true); jmsMsg.doBeforeReceive(); } catch (IndexOutOfBoundsException ioob) { ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly(); if (session.getAcknowledgeMode() == ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE) { jmsMsg.setIndividualAcknowledge(); } else if (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) { jmsMsg.setClientAcknowledge(); coreMessage.acknowledge(); ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly(); throw JMSExceptionHelper.convertFromActiveMQException(e); } catch (ActiveMQInterruptedException e) { ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly(); throw JMSExceptionHelper.convertFromActiveMQException(e);
@Override public MessageConsumer createConsumer(final Destination destination, final String messageSelector) throws JMSException { return createConsumer(destination, messageSelector, false); }
@Test public void testClosingTemporaryTopicDeletesQueue() throws JMSException, ActiveMQException { conn = cf.createConnection(); Assert.assertEquals(1, server.getRemotingService().getConnections().size()); session1 = (ActiveMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQTemporaryTopic topic = (ActiveMQTemporaryTopic) session1.createTemporaryTopic(); String address = topic.getAddress(); session1.close(); conn.close(); conn2 = cf.createConnection(); session2 = (ActiveMQSession) conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession cs = session2.getCoreSession(); try { cs.createConsumer(address); fail("the address from the TemporaryTopic still exists!"); } catch (ActiveMQException e) { assertEquals("expecting 'queue does not exist'", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, e.getType()); } }
@Override public TopicPublisher createPublisher(final Topic topic) throws JMSException { return (TopicPublisher) createProducer(topic); }
session.close();
@Override public QueueBrowser createBrowser(final Queue queue) throws JMSException { return createBrowser(queue, null); }
@Override public MessageConsumer createDurableConsumer(Topic topic, String name) throws JMSException { return createDurableConsumer(topic, name, null, false); }
@Override public TopicSubscriber createDurableSubscriber(final Topic topic, final String name, String messageSelector, final boolean noLocal) throws JMSException { // As per spec. section 4.11 if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a durable subscriber on a QueueSession"); } checkTopic(topic); if (!(topic instanceof ActiveMQDestination)) { throw new InvalidDestinationException("Not an ActiveMQTopic:" + topic); } if ("".equals(messageSelector)) { messageSelector = null; } ActiveMQDestination jbdest = (ActiveMQDestination) topic; if (jbdest.isQueue()) { throw new InvalidDestinationException("Cannot create a subscriber on a queue"); } return createConsumer(jbdest, name, messageSelector, noLocal, ConsumerDurability.DURABLE); }
/** * Note: Needs to throw an exception if a subscriptionName is already in use by another topic, or if the messageSelector is different * * validate multiple subscriptions on the same session. * validate multiple subscriptions on different sessions * validate failure in one connection while another connection stills fine. * Validate different filters in different possible scenarios * * @param topic * @param name * @param messageSelector * @return * @throws JMSException */ @Override public MessageConsumer createSharedConsumer(Topic topic, String name, String messageSelector) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a shared consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return internalCreateSharedConsumer(localTopic, name, messageSelector, ConsumerDurability.NON_DURABLE); }
@Override public MessageConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a durable consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return createConsumer(localTopic, name, messageSelector, noLocal, ConsumerDurability.DURABLE); }
@Override public TopicSubscriber createSubscriber(final Topic topic, final String messageSelector, final boolean noLocal) throws JMSException { return (TopicSubscriber) createConsumer(topic, messageSelector, noLocal); }
@Override public QueueSender createSender(final Queue queue) throws JMSException { return (QueueSender) createProducer(queue); }