connection = new ActiveMQConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, enable1xPrefixes, factory); } else if (type == ActiveMQConnection.TYPE_QUEUE_CONNECTION) { connection = new ActiveMQConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, enable1xPrefixes, factory); } else if (type == ActiveMQConnection.TYPE_TOPIC_CONNECTION) { connection = new ActiveMQConnection(this, username, password, type, clientID, dupsOKBatchSize, transactionBatchSize, cacheDestinations, enable1xPrefixes, factory); throw new JMSException("Failed to create connection: invalid type " + type); connection.setReference(this); connection.authorize(!isEnableSharedClientID()); } catch (JMSException e) { try { connection.close(); } catch (JMSException me) {
private void checkTempQueues(Destination destination) throws JMSException { ActiveMQDestination jbdest = (ActiveMQDestination) destination; if (jbdest.isTemporary() && !containsTemporaryQueue(jbdest.getSimpleAddress())) { throw new JMSException("Can not create consumer for temporary destination " + destination + " from another JMS connection"); } }
@Override public void setClientID(final String clientID) throws JMSException { checkClosed(); if (this.clientID != null) { throw new IllegalStateException("Client id has already been set"); } if (!justCreated) { throw new IllegalStateException("setClientID can only be called directly after the connection is created"); } validateClientID(initialSession, clientID); this.clientID = clientID; try { this.addSessionMetaData(initialSession); } catch (ActiveMQException e) { JMSException ex = new JMSException("Internal error setting metadata jms-client-id"); ex.setLinkedException(e); ex.initCause(e); throw ex; } justCreated = false; }
@Override public synchronized Session createSession(final boolean transacted, final int acknowledgeMode) throws JMSException { checkClosed(); return createSessionInternal(false, transacted, checkAck(transacted, acknowledgeMode), ActiveMQConnection.TYPE_GENERIC_CONNECTION); }
/** * This internal method serves basically the Resource Adapter. * The resource adapter plays with an XASession and a non XASession. * When there is no enlisted transaction, the EE specification mandates that the commit should * be done as if it was a nonXA Session (i.e. SessionTransacted). * For that reason we have this method to force that nonXASession, since the JMS Javadoc * mandates createSession to return a XASession. */ public Session createNonXATopicSession(final boolean transacted, final int acknowledgeMode) throws JMSException { checkClosed(); return createSessionInternal(false, transacted, acknowledgeMode, ActiveMQConnection.TYPE_TOPIC_CONNECTION); }
@Override public ConnectionConsumer createConnectionConsumer(final Topic topic, final String messageSelector, final ServerSessionPool sessionPool, final int maxMessages) throws JMSException { checkClosed(); checkTempQueues(topic); return null; }
connection.setHasNoLocal(); if (connection.getClientID() != null) { filter = ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + connection.getClientID() + "'"; } else { filter = ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + connection.getUID() + "'"; connection.addKnownDestination(dest.getSimpleAddress()); connection.addKnownDestination(dest.getSimpleAddress()); if (connection.getClientID() == null) { throw new IllegalStateException("Cannot create durable subscription - client ID has not been set"); queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), subscriptionName);
if (!connection.containsKnownDestination(address)) { try { ClientSession.AddressQuery query = clientSession.addressQuery(address); ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address); if (queueQuery.isExists()) { connection.addKnownDestination(address); } else if (destination.isQueue() && query.isAutoCreateQueues()) { if (destination.isTemporary()) {
@Test public void testTemporaryQueueLeak() throws Exception { ActiveMQConnection conn = null; try { conn = (ActiveMQConnection) createConnection(); Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue tempQueue = producerSession.createTemporaryQueue(); MessageProducer producer = producerSession.createProducer(tempQueue); MessageConsumer consumer = consumerSession.createConsumer(tempQueue); conn.start(); final String messageText = "This is a message"; javax.jms.Message m = producerSession.createTextMessage(messageText); producer.send(m); TextMessage m2 = (TextMessage) consumer.receive(2000); assertNotNull(m2); assertEquals(messageText, m2.getText()); consumer.close(); tempQueue.delete(); assertFalse(conn.containsKnownDestination(SimpleString.toSimpleString(tempQueue.getQueueName()))); assertFalse(conn.containsTemporaryQueue(SimpleString.toSimpleString(tempQueue.getQueueName()))); } finally { if (conn != null) { conn.close(); } } } @Test
public void authorize(boolean validateClientId) throws JMSException { try { initialSession = sessionFactory.createSession(username, password, false, false, false, false, 0); if (clientID != null) { if (validateClientId) { validateClientID(initialSession, clientID); } else { initialSession.addMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientID); } } addSessionMetaData(initialSession); initialSession.addFailureListener(listener); initialSession.addFailoverListener(failoverListener); } catch (ActiveMQException me) { throw JMSExceptionHelper.convertFromActiveMQException(me); } }
session.addFailoverListener(failoverListener); ActiveMQSession jbs = createAMQSession(isXA, transacted, acknowledgeMode, session, type); this.addSessionMetaData(session);
@Override protected final void finalize() throws Throwable { if (!closed) { if (this.factoryReference.isFinalizeChecks()) { ActiveMQJMSClientLogger.LOGGER.connectionLeftOpen(creationStack); } close(); } }
conn.setFailoverListener(listener); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Assert.assertEquals(FailoverEventType.FAILOVER_COMPLETED, listener.get(1)); conn.close(); Assert.assertEquals("Expected 2 FailoverEvents to be triggered", 2, listener.size());
@Override public TemporaryQueue createTemporaryQueue() throws JMSException { // As per spec. section 4.11 if (sessionType == ActiveMQSession.TYPE_TOPIC_SESSION) { throw new IllegalStateException("Cannot create a temporary queue using a TopicSession"); } try { final ActiveMQTemporaryQueue queue; if (enable1xPrefixes) { queue = ActiveMQDestination.createTemporaryQueue(this, PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()); } else { queue = ActiveMQDestination.createTemporaryQueue(this); } SimpleString simpleAddress = queue.getSimpleAddress(); session.createTemporaryQueue(simpleAddress, RoutingType.ANYCAST, simpleAddress); connection.addTemporaryQueue(simpleAddress); return queue; } catch (ActiveMQException e) { throw JMSExceptionHelper.convertFromActiveMQException(e); } }
connLive.setFailoverListener(listener); Session sessLive = connLive.createSession(false, Session.AUTO_ACKNOWLEDGE); connLive.close();
@Override public String getClientID() throws JMSException { checkClosed(); return clientID; }
@Test //(timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnTopic() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(); SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); System.out.println("Address is " + addressName); clientSession.createAddress(addressName, RoutingType.ANYCAST, false); Topic topic = new ActiveMQTopic(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(topic); for (int i = 0; i < 10; i++) { producer.send(session.createTextMessage("hello")); } Assert.assertTrue(((ActiveMQConnection)connection).containsKnownDestination(addressName)); }
public void authorize() throws JMSException { authorize(true); }
@Override public TopicSession createTopicSession(final boolean transacted, final int acknowledgeMode) throws JMSException { checkClosed(); return createSessionInternal(false, transacted, checkAck(transacted, acknowledgeMode), ActiveMQSession.TYPE_TOPIC_SESSION); }
connection.setHasNoLocal(); if (connection.getClientID() != null) { filter = ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + connection.getClientID() + "'"; } else { filter = ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + connection.getUID() + "'"; connection.addKnownDestination(dest.getSimpleAddress()); connection.addKnownDestination(dest.getSimpleAddress()); if (connection.getClientID() == null) { throw new IllegalStateException("Cannot create durable subscription - client ID has not been set"); queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), subscriptionName);