]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/database/BaseDatabaseBean.java
log also class name
[jcore-utils.git] / src / org / mxchange / jcoreee / database / BaseDatabaseBean.java
index e9073ee524d8deba48c4d75d3be7ee4b5338d483..07e54ae2a5224b37b75d68c29bcfb639da4669ec 100644 (file)
 package org.mxchange.jcoreee.database;
 
 import java.io.Serializable;
+import java.text.MessageFormat;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -61,7 +65,7 @@ public abstract class BaseDatabaseBean implements Serializable {
                        this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
                } catch (final NamingException ex) {
                        // Continue to throw
-                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
                }
        }
 
@@ -82,4 +86,33 @@ public abstract class BaseDatabaseBean implements Serializable {
        protected LoggerBeanLocal getLoggerBeanLocal () {
                return this.loggerBeanLocal;
        }
+
+       /**
+        * Sends given message to configured queue
+        * <p>
+        * @param message Message to send
+        * @param messageProducer Message producer
+        * <p>
+        * @throws JMSException if something went wrong
+        */
+       protected void sendMessage (final ObjectMessage message, final MessageProducer messageProducer) throws JMSException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: message={1},messageProducer={2} - CALLED!", this.getClass().getSimpleName(), message, messageProducer)); //NOI18N
+
+               // The parameter should be valid
+               if (null == message) {
+                       // Throw NPE
+                       throw new NullPointerException("message is null"); //NOI18N
+               } else if (null == messageProducer) {
+                       // Throw NPE again
+                       throw new NullPointerException("messageProvider is null"); //NOI18N
+               }
+
+               // Send it
+               messageProducer.send(message);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.sendMessage: EXIT!", this.getClass().getSimpleName())); //NOI18N
+       }
+
 }