]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 25 Aug 2016 09:44:37 +0000 (11:44 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 27 Aug 2016 14:42:03 +0000 (16:42 +0200)
- added message-driven bean (unfinished) for adding user activity log
- this is asynchronous and won't cause application freezes if inserting takes some time

src/java/org/mxchange/jusercore/model/user/activity/LandingUserActivityLogMessageBean.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/jusercore/model/user/activity/LandingUserActivityLogMessageBean.java b/src/java/org/mxchange/jusercore/model/user/activity/LandingUserActivityLogMessageBean.java
new file mode 100644 (file)
index 0000000..c4a865b
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2016 Cho-Time GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.user.activity;
+
+import de.chotime.landingpage.database.BaseLandingDatabaseBean;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery;
+
+/**
+ * A message-driven bean for adding user activity log
+ * <p>
+ * @author Roland Haeder<rhaeder@cho-time.de>
+ */
+@MessageDriven (
+               name = "userActivityLog",
+               description = "A message-driven bean for adding user activity log",
+               activationConfig = {
+                       @ActivationConfigProperty (
+                                       propertyName = "destinationLookup",
+                                       propertyValue = "jms/jlanding-user-activity-log"
+                       ),
+                       @ActivationConfigProperty (
+                                       propertyName = "destinationType",
+                                       propertyValue = "javax.jms.Queue"
+                       )
+               }
+)
+public class LandingUserActivityLogMessageBean extends BaseLandingDatabaseBean implements MessageListener {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 14_920_686_785_732_054L;
+
+       /**
+        * Default constructor
+        */
+       public LandingUserActivityLogMessageBean () {
+       }
+
+       @Override
+       public void onMessage (final Message message) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N
+
+               // The parameter should be valid
+               if (null == message) {
+                       // Throw NPE
+                       throw new NullPointerException("message is null"); //NOI18N
+               } else if (!(message instanceof ObjectMessage)) {
+                       // Not implementing right interface
+                       throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
+               }
+
+               // Securely cast it
+               ObjectMessage objectMessage = (ObjectMessage) message;
+
+               // Init variable
+               Serializable serializable;
+
+               try {
+                       // Get object from message
+                       serializable = objectMessage.getObject();
+               } catch (final JMSException ex) {
+                       // Log it and don't continue any further
+                       this.getLoggerBeanLocal().logException(ex);
+                       return;
+               }
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N
+
+               // Okay, is it the right interface?
+               if (null == serializable) {
+                       // Throw NPE
+                       throw new NullPointerException("serializable is null"); //NOI18N
+               } else if (!(serializable instanceof WrapableEmailDelivery)) {
+                       // Not correct object send
+                       throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N
+               }
+       }
+
+}