]> git.mxchange.org Git - addressbook-mailer-ejb.git/blob - src/java/org/mxchange/addressbook/mailer/model/delivery/EmailDeliveryMessageBean.java
Continued:
[addressbook-mailer-ejb.git] / src / java / org / mxchange / addressbook / mailer / model / delivery / EmailDeliveryMessageBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.mailer.model.delivery;
18
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import javax.ejb.ActivationConfigProperty;
22 import javax.ejb.MessageDriven;
23 import javax.jms.JMSException;
24 import javax.jms.Message;
25 import javax.jms.MessageListener;
26 import javax.jms.ObjectMessage;
27 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
28
29 /**
30  * A message-driven bean for sending out emails
31  * <p>
32  * @author Roland Haeder<roland@mxchange.org>
33  */
34 @MessageDriven (activationConfig = {
35         @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
36         @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
37 })
38 public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener {
39
40         /**
41          * Serial number
42          */
43         private static final long serialVersionUID = 75_638_176_619_024L;
44
45         /**
46          * Mailer instance
47          */
48         private final DeliverableAddressbookEmail mailer;
49
50         /**
51          * Default constructor
52          */
53         public EmailDeliveryMessageBean () {
54                 // Init mailer instance
55                 this.mailer = new AddressbookMailer();
56         }
57
58         @Override
59         public void onMessage (final Message message) {
60                 // Trace message
61                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
62
63                 // The parameter should be valid
64                 if (null == message) {
65                         // Throw NPE
66                         throw new NullPointerException("message is null"); //NOI18N
67                 } else if (!(message instanceof ObjectMessage)) {
68                         // Not implementing right interface
69                         throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
70                 }
71
72                 // Securely cast it
73                 ObjectMessage objectMessage = (ObjectMessage) message;
74
75                 // Init variable
76                 Serializable serializable;
77
78                 try {
79                         // Get object from message
80                         serializable = objectMessage.getObject();
81                 } catch (final JMSException ex) {
82                         // Log it and don't continue any further
83                         this.getLoggerBeanLocal().logException(ex);
84                         return;
85                 }
86
87                 // Debug message
88                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
89
90                 // Trace message
91                 this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
92         }
93
94 }