2 * Copyright (C) 2016 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.addressbook.mailer.model.delivery;
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;
30 * A message-driven bean for sending out emails
32 * @author Roland Haeder<roland@mxchange.org>
34 @MessageDriven (activationConfig = {
35 @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jlandingpage-email-queue"),
36 @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue")
38 public class EmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener {
43 private static final long serialVersionUID = 75_638_176_619_024L;
48 private final DeliverableAddressbookEmail mailer;
53 public EmailDeliveryMessageBean () {
54 // Init mailer instance
55 this.mailer = new AddressbookMailer();
59 public void onMessage (final Message message) {
61 this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
63 // The parameter should be valid
64 if (null == message) {
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
73 ObjectMessage objectMessage = (ObjectMessage) message;
76 Serializable serializable;
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);
88 this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
91 this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N