You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/02/21 12:22:00 UTC

[jira] [Work logged] (AMQ-8322) Implement JMS 2.0 Connection createContext methods

     [ https://issues.apache.org/jira/browse/AMQ-8322?focusedWorklogId=730332&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-730332 ]

ASF GitHub Bot logged work on AMQ-8322:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 21/Feb/22 12:21
            Start Date: 21/Feb/22 12:21
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on a change in pull request #729:
URL: https://github.com/apache/activemq/pull/729#discussion_r811047310



##########
File path: activemq-client/src/main/java/org/apache/activemq/ActiveMQSession.java
##########
@@ -1956,12 +1976,15 @@ protected void send(ActiveMQMessageProducer producer, ActiveMQDestination destin
             //Set the "JMS" header fields on the original message, see 1.1 spec section 3.4.11
             message.setJMSDeliveryMode(deliveryMode);
             long expiration = 0L;
-            if (!producer.getDisableMessageTimestamp()) {
-                long timeStamp = System.currentTimeMillis();
+            long timeStamp = System.currentTimeMillis();

Review comment:
       It should also populate the JMSDeliveryTime value since thats a mandatory header (with the timestamp value at first, and later the actual delayed delivery time when delivery-delay support is added), doesnt look like that is happening.

##########
File path: activemq-client/src/main/java/org/apache/activemq/ActiveMQProducer.java
##########
@@ -0,0 +1,547 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jms.BytesMessage;
+import javax.jms.CompletionListener;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageFormatRuntimeException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.util.JMSExceptionSupport;
+import org.apache.activemq.util.TypeConversionSupport;
+
+public class ActiveMQProducer implements JMSProducer {
+
+    private final ActiveMQContext activemqContext;
+    private final MessageProducer activemqMessageProducer;
+
+    // QoS override of defaults on a per-JMSProducer instance basis
+    private String correlationId = null;
+    private byte[] correlationIdBytes = null;
+    private Long deliveryDelay = null;
+    private Integer deliveryMode = null;
+    private Integer priority = null;
+    private Destination replyTo = null;
+    private Long timeToLive = null;
+    private String type = null;
+
+    // Properties applied to all messages on a per-JMS producer instance basis
+    private Map<String, Object> messageProperties = null;
+
+    ActiveMQProducer(ActiveMQContext activemqContext, MessageProducer activemqMessageProducer) {
+        this.activemqContext = activemqContext;
+        this.activemqMessageProducer = activemqMessageProducer;
+    }
+
+    @Override
+    public JMSProducer send(Destination destination, Message message) {
+        try {
+            if(this.correlationId != null) {
+                message.setJMSCorrelationID(this.correlationId);
+            }
+
+            if(this.correlationIdBytes != null) {
+                message.setJMSCorrelationIDAsBytes(this.correlationIdBytes);
+            }
+
+            if(this.replyTo != null) {
+                message.setJMSReplyTo(this.replyTo);
+            }
+
+            if(this.type != null) {
+                message.setJMSType(this.type);
+            }
+
+            if(!messageProperties.isEmpty()) {
+                for(Map.Entry<String, Object> propertyEntry : messageProperties.entrySet()) {
+                    message.setObjectProperty(propertyEntry.getKey(), propertyEntry.getValue());
+                }
+            }
+
+            activemqMessageProducer.send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive());
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+        return this;
+    }
+
+    @Override
+    public JMSProducer send(Destination destination, String body) {
+        TextMessage textMessage = activemqContext.createTextMessage(body);
+        send(destination, textMessage);
+        return this;
+    }
+
+    @Override
+    public JMSProducer send(Destination destination, Map<String, Object> body) {
+        MapMessage mapMessage = activemqContext.createMapMessage();
+
+        if (body != null) {
+            try {
+               for (Map.Entry<String, Object> mapEntry : body.entrySet()) {
+                  final String key = mapEntry.getKey();
+                  final Object value = mapEntry.getValue();
+                  final Class<?> valueObject = value.getClass();
+                  if (String.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setString(key, String.class.cast(value));
+                  } else if (Integer.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setInt(key, Integer.class.cast(value));
+                  } else if (Long.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setLong(key, Long.class.cast(value));
+                  } else if (Double.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setDouble(key, Double.class.cast(value));
+                  } else if (Boolean.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setBoolean(key, Boolean.class.cast(value));
+                  } else if (Character.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setChar(key, Character.class.cast(value));
+                  } else if (Short.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setShort(key, Short.class.cast(value));
+                  } else if (Float.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setFloat(key, Float.class.cast(value));
+                  } else if (Byte.class.isAssignableFrom(valueObject)) {
+                      mapMessage.setByte(key, Byte.class.cast(value));
+                  } else if (byte[].class.isAssignableFrom(valueObject)) {
+                      byte[] array = byte[].class.cast(value);
+                      mapMessage.setBytes(key, array, 0, array.length);
+                  } else {
+                      mapMessage.setObject(key, value);
+                  }
+               }
+            } catch (JMSException e) {
+               throw new MessageFormatRuntimeException(e.getMessage());
+            }
+         }
+         send(destination, mapMessage);
+         return this;
+    }
+
+    @Override
+    public JMSProducer send(Destination destination, byte[] body) {
+        BytesMessage bytesMessage = activemqContext.createBytesMessage();
+
+        try {
+            if(body != null) {
+                bytesMessage.writeBytes(body);
+            }
+            send(destination, bytesMessage);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+        return this;
+    }
+
+    @Override
+    public JMSProducer send(Destination destination, Serializable body) {
+        ObjectMessage objectMessage = activemqContext.createObjectMessage(body);
+        send(destination, objectMessage);
+        return this;
+    }
+
+    @Override
+    public JMSProducer setDisableMessageID(boolean value) {
+        try {
+            activemqMessageProducer.setDisableMessageID(value);
+            return this;
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public boolean getDisableMessageID() {
+        try {
+            return activemqMessageProducer.getDisableMessageID();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSProducer setDisableMessageTimestamp(boolean value) {
+        try {
+            activemqMessageProducer.setDisableMessageTimestamp(value);
+            return this;
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public boolean getDisableMessageTimestamp() {
+        try {
+            return activemqMessageProducer.getDisableMessageTimestamp();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSProducer setDeliveryMode(int deliveryMode) {

Review comment:
       The link is for priority, seems unrelated. I think the comment is good about validating the provided delivery mode is valid. Even the existing MessageProducer impl does that.

##########
File path: activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java
##########
@@ -0,0 +1,539 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.jms.BytesMessage;
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.JMSRuntimeException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+import org.apache.activemq.util.JMSExceptionSupport;
+
+/**
+ * In terms of the JMS 1.1 API a JMSContext should be thought of as 
+ * representing both a Connection and a Session. Although the simplified 
+ * API removes the need for applications to use those objects, the concepts 
+ * of connection and session remain important. A connection represents a 
+ * physical link to the JMS server and a session represents a 
+ * single-threaded context for sending and receiving messages. 
+ *
+ *
+ * @see javax.jms.JMSContext
+ */
+
+public class ActiveMQContext implements JMSContext {
+
+    private static final boolean DEFAULT_AUTO_START = true;
+
+    private final ActiveMQConnection activemqConnection;
+    private final AtomicLong connectionCounter;
+    private ActiveMQSession activemqSession = null;
+
+    // Configuration
+    private boolean autoStart = DEFAULT_AUTO_START;
+    private final int sessionMode;
+
+    // State
+    private boolean closeInvoked = false;
+    private final AtomicBoolean startInvoked = new AtomicBoolean(false);
+    private ActiveMQMessageProducer activemqMessageProducer = null;
+
+    ActiveMQContext(final ActiveMQConnection activemqConnection) {
+        this.activemqConnection = activemqConnection;
+        this.sessionMode = AUTO_ACKNOWLEDGE;
+        this.connectionCounter = new AtomicLong(1l);
+    }
+
+    ActiveMQContext(final ActiveMQConnection activemqConnection, final int sessionMode) {
+        this.activemqConnection = activemqConnection;
+        this.sessionMode = sessionMode;
+        this.connectionCounter = new AtomicLong(1l);
+    }
+
+    private ActiveMQContext(final ActiveMQConnection activemqConnection, final int sessionMode, final AtomicLong connectionCounter) {
+        this.activemqConnection = activemqConnection;
+        this.sessionMode = sessionMode;
+        this.connectionCounter = connectionCounter;
+    }
+
+    @Override
+    public JMSContext createContext(int sessionMode) {
+        if(connectionCounter.get() == 0l) {
+            throw new JMSRuntimeException("Context already closed");
+        }
+
+        connectionCounter.incrementAndGet();
+        return new ActiveMQContext(activemqConnection, sessionMode, connectionCounter);
+    }
+
+    @Override
+    public JMSProducer createProducer() {
+        return new ActiveMQProducer(this, getCreatedActiveMQMessageProducer());
+    }
+
+    @Override
+    public String getClientID() {
+        try {
+            return this.activemqConnection.getClientID();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setClientID(String clientID) {
+        try {
+            this.activemqConnection.setClientID(clientID);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ConnectionMetaData getMetaData() {
+        checkContextState();
+        try {
+            return this.activemqConnection.getMetaData();
+        } catch (JMSException e) {
+                throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ExceptionListener getExceptionListener() {
+        checkContextState();
+        try {
+            return this.activemqConnection.getExceptionListener();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setExceptionListener(ExceptionListener listener) {
+        checkContextState();
+        try {
+            this.activemqConnection.setExceptionListener(listener);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void start() {
+        checkContextState();
+        try {
+            if(startInvoked.compareAndSet(false, true)) {
+                this.activemqConnection.start();
+            }
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void stop() {
+        checkContextState();
+        try {
+            if(startInvoked.compareAndSet(true, false)) {
+                this.activemqConnection.stop();
+            }
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setAutoStart(boolean autoStart) {
+       this.autoStart = autoStart;
+    }
+
+    @Override
+    public boolean getAutoStart() {
+        return this.autoStart;
+    }
+
+    @Override
+    public void close() {
+        JMSRuntimeException firstException = null;
+
+        if(this.activemqMessageProducer != null) {
+            try {
+                this.activemqMessageProducer.close();
+            } catch (JMSException e) {
+                if(firstException == null) { 
+                    firstException = JMSExceptionSupport.convertToJMSRuntimeException(e);
+                }
+            }
+        }
+
+        if(this.activemqSession != null) {
+            try {
+               this.activemqSession.close();
+            } catch (JMSException e) {
+               if(firstException == null) {
+                   firstException = JMSExceptionSupport.convertToJMSRuntimeException(e);
+               }
+            }
+        }
+
+        if(connectionCounter.decrementAndGet() == 0) {
+            if(this.activemqConnection != null) {
+                try {
+                    closeInvoked = true;
+                    this.activemqConnection.close();
+                } catch (JMSException e) {
+                    if(firstException == null) {
+                        firstException = JMSExceptionSupport.convertToJMSRuntimeException(e);
+                    }
+                }
+            }
+        }
+
+        if(firstException != null) {
+            throw firstException;
+        }
+    }
+
+    @Override
+    public BytesMessage createBytesMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createBytesMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+     }
+
+    @Override
+    public MapMessage createMapMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createMapMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public Message createMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ObjectMessage createObjectMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createObjectMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ObjectMessage createObjectMessage(Serializable object) {
+        checkContextState();
+        try {
+            return activemqSession.createObjectMessage(object);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public StreamMessage createStreamMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createStreamMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public TextMessage createTextMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createTextMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public TextMessage createTextMessage(String text) {
+        checkContextState();
+        try {
+            return activemqSession.createTextMessage(text);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public boolean getTransacted() {
+        checkContextState();
+        try {
+            return activemqSession.getTransacted();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public int getSessionMode() {
+        return this.sessionMode;
+    }
+
+    @Override
+    public void commit() {
+        checkContextState();
+        try {
+            activemqSession.commit();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void rollback() {
+        checkContextState();
+        try {
+            activemqSession.rollback();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void recover() {
+        checkContextState();
+        try {
+            activemqSession.recover();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createConsumer(Destination destination) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return new ActiveMQConsumer(this, activemqSession.createConsumer(destination));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createConsumer(Destination destination, String messageSelector) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return new ActiveMQConsumer(this, activemqSession.createConsumer(destination, messageSelector));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return new ActiveMQConsumer(this, activemqSession.createConsumer(destination, messageSelector, noLocal));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public Queue createQueue(String queueName) {
+        checkContextState();
+        try {
+            return activemqSession.createQueue(queueName);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public Topic createTopic(String topicName) {
+        checkContextState();
+        try {
+            return activemqSession.createTopic(topicName);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createDurableConsumer(Topic topic, String name) {
+        throw new UnsupportedOperationException("createDurableConsumer(topic, name) is not supported");
+    }
+
+    @Override
+    public JMSConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal) {
+        throw new UnsupportedOperationException("createDurableConsumer(topic, name, messageSelector, noLocal) is not supported");
+    }

Review comment:
       Surprising that these 1.1 features arent implemented.

##########
File path: activemq-client/src/main/java/org/apache/activemq/ActiveMQSession.java
##########
@@ -1974,7 +1997,9 @@ protected void send(ActiveMQMessageProducer producer, ActiveMQDestination destin
 
             // Set the message id.
             if (msg != message) {
-                message.setJMSMessageID(msg.getMessageId().toString());
+                if(!disableMessageID && !producer.getDisableMessageID()) {
+                    message.setJMSMessageID(msg.getMessageId().toString());
+                }

Review comment:
       If it is disabled it should be clearing the value that might already exist, similar to the timestamp handling does above.

##########
File path: activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java
##########
@@ -0,0 +1,539 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.jms.BytesMessage;
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.JMSRuntimeException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+import org.apache.activemq.util.JMSExceptionSupport;
+
+/**
+ * In terms of the JMS 1.1 API a JMSContext should be thought of as 
+ * representing both a Connection and a Session. Although the simplified 
+ * API removes the need for applications to use those objects, the concepts 
+ * of connection and session remain important. A connection represents a 
+ * physical link to the JMS server and a session represents a 
+ * single-threaded context for sending and receiving messages. 
+ *
+ *
+ * @see javax.jms.JMSContext
+ */
+
+public class ActiveMQContext implements JMSContext {
+
+    private static final boolean DEFAULT_AUTO_START = true;
+
+    private final ActiveMQConnection activemqConnection;
+    private final AtomicLong connectionCounter;
+    private ActiveMQSession activemqSession = null;
+
+    // Configuration
+    private boolean autoStart = DEFAULT_AUTO_START;
+    private final int sessionMode;
+
+    // State
+    private boolean closeInvoked = false;
+    private final AtomicBoolean startInvoked = new AtomicBoolean(false);
+    private ActiveMQMessageProducer activemqMessageProducer = null;
+
+    ActiveMQContext(final ActiveMQConnection activemqConnection) {
+        this.activemqConnection = activemqConnection;
+        this.sessionMode = AUTO_ACKNOWLEDGE;
+        this.connectionCounter = new AtomicLong(1l);
+    }
+
+    ActiveMQContext(final ActiveMQConnection activemqConnection, final int sessionMode) {
+        this.activemqConnection = activemqConnection;
+        this.sessionMode = sessionMode;
+        this.connectionCounter = new AtomicLong(1l);
+    }
+
+    private ActiveMQContext(final ActiveMQConnection activemqConnection, final int sessionMode, final AtomicLong connectionCounter) {
+        this.activemqConnection = activemqConnection;
+        this.sessionMode = sessionMode;
+        this.connectionCounter = connectionCounter;
+    }
+
+    @Override
+    public JMSContext createContext(int sessionMode) {
+        if(connectionCounter.get() == 0l) {
+            throw new JMSRuntimeException("Context already closed");
+        }
+
+        connectionCounter.incrementAndGet();
+        return new ActiveMQContext(activemqConnection, sessionMode, connectionCounter);
+    }
+
+    @Override
+    public JMSProducer createProducer() {
+        return new ActiveMQProducer(this, getCreatedActiveMQMessageProducer());
+    }
+
+    @Override
+    public String getClientID() {
+        try {
+            return this.activemqConnection.getClientID();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setClientID(String clientID) {
+        try {
+            this.activemqConnection.setClientID(clientID);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ConnectionMetaData getMetaData() {
+        checkContextState();
+        try {
+            return this.activemqConnection.getMetaData();
+        } catch (JMSException e) {
+                throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ExceptionListener getExceptionListener() {
+        checkContextState();
+        try {
+            return this.activemqConnection.getExceptionListener();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setExceptionListener(ExceptionListener listener) {
+        checkContextState();
+        try {
+            this.activemqConnection.setExceptionListener(listener);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void start() {
+        checkContextState();
+        try {
+            if(startInvoked.compareAndSet(false, true)) {
+                this.activemqConnection.start();
+            }
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void stop() {
+        checkContextState();
+        try {
+            if(startInvoked.compareAndSet(true, false)) {
+                this.activemqConnection.stop();
+            }
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void setAutoStart(boolean autoStart) {
+       this.autoStart = autoStart;
+    }
+
+    @Override
+    public boolean getAutoStart() {
+        return this.autoStart;
+    }
+
+    @Override
+    public void close() {
+        JMSRuntimeException firstException = null;
+
+        if(this.activemqMessageProducer != null) {
+            try {
+                this.activemqMessageProducer.close();
+            } catch (JMSException e) {
+                if(firstException == null) { 
+                    firstException = JMSExceptionSupport.convertToJMSRuntimeException(e);
+                }
+            }
+        }
+
+        if(this.activemqSession != null) {
+            try {
+               this.activemqSession.close();
+            } catch (JMSException e) {
+               if(firstException == null) {
+                   firstException = JMSExceptionSupport.convertToJMSRuntimeException(e);
+               }
+            }
+        }
+
+        if(connectionCounter.decrementAndGet() == 0) {
+            if(this.activemqConnection != null) {
+                try {
+                    closeInvoked = true;
+                    this.activemqConnection.close();
+                } catch (JMSException e) {
+                    if(firstException == null) {
+                        firstException = JMSExceptionSupport.convertToJMSRuntimeException(e);
+                    }
+                }
+            }
+        }
+
+        if(firstException != null) {
+            throw firstException;
+        }
+    }
+
+    @Override
+    public BytesMessage createBytesMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createBytesMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+     }
+
+    @Override
+    public MapMessage createMapMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createMapMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public Message createMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ObjectMessage createObjectMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createObjectMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public ObjectMessage createObjectMessage(Serializable object) {
+        checkContextState();
+        try {
+            return activemqSession.createObjectMessage(object);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public StreamMessage createStreamMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createStreamMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public TextMessage createTextMessage() {
+        checkContextState();
+        try {
+            return activemqSession.createTextMessage();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public TextMessage createTextMessage(String text) {
+        checkContextState();
+        try {
+            return activemqSession.createTextMessage(text);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public boolean getTransacted() {
+        checkContextState();
+        try {
+            return activemqSession.getTransacted();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public int getSessionMode() {
+        return this.sessionMode;
+    }
+
+    @Override
+    public void commit() {
+        checkContextState();
+        try {
+            activemqSession.commit();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void rollback() {
+        checkContextState();
+        try {
+            activemqSession.rollback();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void recover() {
+        checkContextState();
+        try {
+            activemqSession.recover();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createConsumer(Destination destination) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return new ActiveMQConsumer(this, activemqSession.createConsumer(destination));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createConsumer(Destination destination, String messageSelector) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return new ActiveMQConsumer(this, activemqSession.createConsumer(destination, messageSelector));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return new ActiveMQConsumer(this, activemqSession.createConsumer(destination, messageSelector, noLocal));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public Queue createQueue(String queueName) {
+        checkContextState();
+        try {
+            return activemqSession.createQueue(queueName);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public Topic createTopic(String topicName) {
+        checkContextState();
+        try {
+            return activemqSession.createTopic(topicName);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public JMSConsumer createDurableConsumer(Topic topic, String name) {
+        throw new UnsupportedOperationException("createDurableConsumer(topic, name) is not supported");
+    }
+
+    @Override
+    public JMSConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal) {
+        throw new UnsupportedOperationException("createDurableConsumer(topic, name, messageSelector, noLocal) is not supported");
+    }
+
+    @Override
+    public JMSConsumer createSharedDurableConsumer(Topic topic, String name) {
+        throw new UnsupportedOperationException("createSharedDurableConsumer(topic, name) is not supported");
+    }
+
+    @Override
+    public JMSConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) {
+        throw new UnsupportedOperationException("createDurableConsumer(topic, name, messageSelector) is not supported");
+    }
+
+    @Override
+    public JMSConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName) {
+        throw new UnsupportedOperationException("createSharedConsumer(topic, sharedSubscriptionName) is not supported");
+    }
+
+    @Override
+    public JMSConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector) {
+        throw new UnsupportedOperationException("createSharedConsumer(topic, sharedSubscriptionName, messageSelector) is not supported");
+    }
+
+    @Override
+    public QueueBrowser createBrowser(Queue queue) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return activemqSession.createBrowser(queue);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public QueueBrowser createBrowser(Queue queue, String messageSelector) {
+        checkContextState();
+        try {
+            if(getAutoStart()) {
+                start();
+            }
+            return activemqSession.createBrowser(queue, messageSelector);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public TemporaryQueue createTemporaryQueue() {
+        checkContextState();
+        try {
+            return activemqSession.createTemporaryQueue();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public TemporaryTopic createTemporaryTopic() {
+        checkContextState();
+        try {
+            return activemqSession.createTemporaryTopic();
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void unsubscribe(String name) {
+        checkContextState();
+        try {
+            activemqSession.unsubscribe(name);
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
+    }
+
+    @Override
+    public void acknowledge() {
+        throw new UnsupportedOperationException("acknowledge() is not supported");

Review comment:
       Surprising that this 1.1 level functionality isnt implemented.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 730332)
    Time Spent: 3h  (was: 2h 50m)

> Implement JMS 2.0 Connection createContext methods
> --------------------------------------------------
>
>                 Key: AMQ-8322
>                 URL: https://issues.apache.org/jira/browse/AMQ-8322
>             Project: ActiveMQ
>          Issue Type: Sub-task
>            Reporter: Matt Pavlovich
>            Assignee: Matt Pavlovich
>            Priority: Major
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> Add support for JMSContext, JMSProducer and JMSConsumer for working with queues



--
This message was sent by Atlassian Jira
(v8.20.1#820001)