You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/11/20 12:01:47 UTC

[3/3] tomee git commit: Add injection point name for log

Add injection point name for log


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/70ac3f9c
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/70ac3f9c
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/70ac3f9c

Branch: refs/heads/tomee-1.7.x
Commit: 70ac3f9ceb46244a7a3d774e4ba76e903698601b
Parents: 4662843
Author: AndyGee <an...@gmx.de>
Authored: Fri Nov 20 12:01:12 2015 +0100
Committer: AndyGee <an...@gmx.de>
Committed: Fri Nov 20 12:01:12 2015 +0100

----------------------------------------------------------------------
 .../org/apache/openejb/InjectionProcessor.java  | 14 +++++---
 .../activemq/ConnectionFactoryWrapper.java      | 26 ++++++++------
 .../resource/activemq/ConnectionWrapper.java    | 16 ++++++---
 .../resource/activemq/SessionWrapper.java       | 37 +++++++++++++++++++-
 4 files changed, 71 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/70ac3f9c/container/openejb-core/src/main/java/org/apache/openejb/InjectionProcessor.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/InjectionProcessor.java b/container/openejb-core/src/main/java/org/apache/openejb/InjectionProcessor.java
index 6586214..a8e3b9d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/InjectionProcessor.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/InjectionProcessor.java
@@ -250,10 +250,7 @@ public class InjectionProcessor<T> {
 
                 if (value != null) {
 
-                    if("org.apache.activemq.ra.ActiveMQConnectionFactory".equals(value.getClass().getName())){
-                        //Wrap
-                        value = new ConnectionFactoryWrapper(value);
-                    }
+
 
                     final String prefix;
                     if (usePrefix) {
@@ -262,7 +259,14 @@ public class InjectionProcessor<T> {
                         prefix = "";
                     }
 
-                    objectRecipe.setProperty(prefix + injection.getName(), value);
+                    final String name = prefix + injection.getName();
+
+                    if("org.apache.activemq.ra.ActiveMQConnectionFactory".equals(value.getClass().getName())){
+                        //Wrap
+                        value = new ConnectionFactoryWrapper(name, value);
+                    }
+
+                    objectRecipe.setProperty(name, value);
                 } else {
                     logger.warning("Injection data not found in JNDI context: jndiName='" + injection.getJndiName() + "', target=" + injection.getTarget().getName() + "/" + injection.getName());
                 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/70ac3f9c/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionFactoryWrapper.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionFactoryWrapper.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionFactoryWrapper.java
index d0034f1..0e94c1d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionFactoryWrapper.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionFactoryWrapper.java
@@ -27,23 +27,25 @@ public class ConnectionFactoryWrapper implements ConnectionFactory, TopicConnect
     private static final ArrayList<ConnectionWrapper> connections = new ArrayList<ConnectionWrapper>();
 
     private final org.apache.activemq.ra.ActiveMQConnectionFactory factory;
+    private final String name;
 
-    public ConnectionFactoryWrapper(final Object factory) {
+    public ConnectionFactoryWrapper(final String name, final Object factory) {
+        this.name = name;
         this.factory = org.apache.activemq.ra.ActiveMQConnectionFactory.class.cast(factory);
     }
 
     @Override
     public Connection createConnection() throws JMSException {
-        return getConnection(this.factory.createConnection());
+        return getConnection(this.name, this.factory.createConnection());
     }
 
     @Override
     public Connection createConnection(final String userName, final String password) throws JMSException {
-        return getConnection(this.factory.createConnection(userName, password));
+        return getConnection(this.name, this.factory.createConnection(userName, password));
     }
 
-    private static Connection getConnection(final Connection connection) {
-        final ConnectionWrapper wrapper = new ConnectionWrapper(connection);
+    private static Connection getConnection(final String name, final Connection connection) {
+        final ConnectionWrapper wrapper = new ConnectionWrapper(name, connection);
         connections.add(wrapper);
         return wrapper;
     }
@@ -55,36 +57,38 @@ public class ConnectionFactoryWrapper implements ConnectionFactory, TopicConnect
     public static void closeConnections() {
         final Iterator<ConnectionWrapper> iterator = connections.iterator();
 
+        ConnectionWrapper next;
         while (iterator.hasNext()) {
-            final ConnectionWrapper next = iterator.next();
+            next = iterator.next();
             iterator.remove();
             try {
                 next.close();
             } catch (final Exception e) {
                 //no-op
             } finally {
-                Logger.getLogger(ConnectionFactoryWrapper.class.getName()).log(Level.SEVERE, "Closed a JMS connection. You have an application that fails to close this connection");
+                Logger.getLogger(ConnectionFactoryWrapper.class.getName()).log(Level.SEVERE, "Closed a JMS connection. You have an application that fails to close a connection "
+                        + "created by this injection path: " + next.getName());
             }
         }
     }
 
     @Override
     public QueueConnection createQueueConnection() throws JMSException {
-        return QueueConnection.class.cast(getConnection(this.factory.createQueueConnection()));
+        return QueueConnection.class.cast(getConnection(this.name, this.factory.createQueueConnection()));
     }
 
     @Override
     public QueueConnection createQueueConnection(final String userName, final String password) throws JMSException {
-        return QueueConnection.class.cast(getConnection(this.factory.createQueueConnection(userName, password)));
+        return QueueConnection.class.cast(getConnection(this.name, this.factory.createQueueConnection(userName, password)));
     }
 
     @Override
     public TopicConnection createTopicConnection() throws JMSException {
-        return TopicConnection.class.cast(getConnection(this.factory.createTopicConnection()));
+        return TopicConnection.class.cast(getConnection(this.name, this.factory.createTopicConnection()));
     }
 
     @Override
     public TopicConnection createTopicConnection(final String userName, final String password) throws JMSException {
-        return TopicConnection.class.cast(getConnection(this.factory.createTopicConnection(userName, password)));
+        return TopicConnection.class.cast(getConnection(this.name, this.factory.createTopicConnection(userName, password)));
     }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/70ac3f9c/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionWrapper.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionWrapper.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionWrapper.java
index c5a4783..707e9bd 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionWrapper.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ConnectionWrapper.java
@@ -33,15 +33,17 @@ public class ConnectionWrapper implements Connection, TopicConnection, QueueConn
 
     private final ArrayList<SessionWrapper> sessions = new ArrayList<SessionWrapper>();
 
+    private final String name;
     private final Connection con;
 
-    public ConnectionWrapper(final Connection con) {
+    public ConnectionWrapper(final String name, final Connection con) {
+        this.name = name;
         this.con = con;
     }
 
     @Override
     public Session createSession(final boolean transacted, final int acknowledgeMode) throws JMSException {
-        return getSession(con.createSession(transacted, acknowledgeMode));
+        return this.getSession(con.createSession(transacted, acknowledgeMode));
     }
 
     private Session getSession(final Session session) {
@@ -61,7 +63,7 @@ public class ConnectionWrapper implements Connection, TopicConnection, QueueConn
 
     @Override
     public TopicSession createTopicSession(final boolean transacted, final int acknowledgeMode) throws JMSException {
-        return TopicConnection.class.cast(this.con).createTopicSession(transacted, acknowledgeMode);
+        return TopicSession.class.cast(this.getSession(TopicConnection.class.cast(this.con).createTopicSession(transacted, acknowledgeMode)));
     }
 
     @Override
@@ -71,7 +73,7 @@ public class ConnectionWrapper implements Connection, TopicConnection, QueueConn
 
     @Override
     public QueueSession createQueueSession(final boolean transacted, final int acknowledgeMode) throws JMSException {
-        return QueueConnection.class.cast(this.con).createQueueSession(transacted, acknowledgeMode);
+        return QueueSession.class.cast(this.getSession(QueueConnection.class.cast(this.con).createQueueSession(transacted, acknowledgeMode)));
     }
 
     @Override
@@ -117,7 +119,8 @@ public class ConnectionWrapper implements Connection, TopicConnection, QueueConn
             } catch (final Exception e) {
                 //no-op
             } finally {
-                Logger.getLogger(ConnectionFactoryWrapper.class.getName()).log(Level.SEVERE, "Closed a JMS session. You have an application that fails to close this session");
+                Logger.getLogger(ConnectionFactoryWrapper.class.getName()).log(Level.SEVERE, "Closed a JMS session. You have an application that fails to close a session "
+                        + "created by this injection path: " + this.name);
             }
         }
 
@@ -164,4 +167,7 @@ public class ConnectionWrapper implements Connection, TopicConnection, QueueConn
     }
 
 
+    public String getName() {
+        return this.name;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/70ac3f9c/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/SessionWrapper.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/SessionWrapper.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/SessionWrapper.java
index 8d45658..5b19890 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/SessionWrapper.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/SessionWrapper.java
@@ -21,16 +21,21 @@ import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Queue;
 import javax.jms.QueueBrowser;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
 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 javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
 import javax.jms.TopicSubscriber;
 import java.io.Serializable;
 
-public class SessionWrapper implements Session {
+public class SessionWrapper implements Session, TopicSession, QueueSession {
 
     private final ConnectionWrapper connectionWrapper;
     private final Session session;
@@ -140,6 +145,11 @@ public class SessionWrapper implements Session {
     }
 
     @Override
+    public TopicPublisher createPublisher(final Topic topic) throws JMSException {
+        return TopicSession.class.cast(this.session).createPublisher(topic);
+    }
+
+    @Override
     public ObjectMessage createObjectMessage() throws JMSException {
         return session.createObjectMessage();
     }
@@ -150,6 +160,16 @@ public class SessionWrapper implements Session {
     }
 
     @Override
+    public TopicSubscriber createSubscriber(final Topic topic) throws JMSException {
+        return TopicSession.class.cast(this.session).createSubscriber(topic);
+    }
+
+    @Override
+    public TopicSubscriber createSubscriber(final Topic topic, final String messageSelector, final boolean noLocal) throws JMSException {
+        return TopicSession.class.cast(this.session).createSubscriber(topic, messageSelector, noLocal);
+    }
+
+    @Override
     public void setMessageListener(final MessageListener listener) throws JMSException {
         session.setMessageListener(listener);
     }
@@ -170,6 +190,21 @@ public class SessionWrapper implements Session {
     }
 
     @Override
+    public QueueReceiver createReceiver(final Queue queue) throws JMSException {
+        return QueueSession.class.cast(this.session).createReceiver(queue);
+    }
+
+    @Override
+    public QueueReceiver createReceiver(final Queue queue, final String messageSelector) throws JMSException {
+        return QueueSession.class.cast(this.session).createReceiver(queue, messageSelector);
+    }
+
+    @Override
+    public QueueSender createSender(final Queue queue) throws JMSException {
+        return QueueSession.class.cast(this.session).createSender(queue);
+    }
+
+    @Override
     public TopicSubscriber createDurableSubscriber(final Topic topic, final String name) throws JMSException {
         return session.createDurableSubscriber(topic, name);
     }