]> git.mxchange.org Git - addressbook-mailer-ejb.git/blob - src/java/org/mxchange/addressbook/beans/resendlink/AddressbookResendLinkSessionBean.java
63790338c27370b057bcbd412e17b121701f565d
[addressbook-mailer-ejb.git] / src / java / org / mxchange / addressbook / beans / resendlink / AddressbookResendLinkSessionBean.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.beans.resendlink;
18
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import javax.ejb.Stateless;
22 import javax.jms.JMSException;
23 import javax.jms.Message;
24 import javax.jms.ObjectMessage;
25 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
26 import org.mxchange.addressbook.mailer.model.delivery.AddressbookMailer;
27 import org.mxchange.addressbook.mailer.model.delivery.DeliverableAddressbookEmail;
28
29 /**
30  * A session-based EJB for resending confirmation links
31  * <p>
32  * @author Roland Haeder<roland@mxchange.org>
33  */
34 @Stateless (name = "resendLink", description = "A bean resending confirmation links")
35 public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBean implements ResendLinkSessionBeanRemote {
36
37         /**
38          * Serial number
39          */
40         private static final long serialVersionUID = 75_638_176_619_024L;
41
42         /**
43          * Mailer instance
44          */
45         private final DeliverableAddressbookEmail mailer;
46
47         /**
48          * Default constructor
49          */
50         public AddressbookResendLinkSessionBean () {
51                 // Init mailer instance
52                 this.mailer = new AddressbookMailer();
53         }
54
55         @Override
56         public void onMessage (final Message message) {
57                 // Trace message
58                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("onMessage: message={0} - CALLED!", message)); //NOI18N
59                 // The parameter should be valid
60                 if (null == message) {
61                         // Throw NPE
62                         throw new NullPointerException("message is null"); //NOI18N
63                 } else if (!(message instanceof ObjectMessage)) {
64                         // Not implementing right interface
65                         throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N
66                 }
67
68                 // Securely cast it
69                 ObjectMessage objectMessage = (ObjectMessage) message;
70
71                 // Init variable
72                 Serializable serializable;
73
74                 try {
75                         // Get object from message
76                         serializable = objectMessage.getObject();
77                 } catch (final JMSException ex) {
78                         // Log it and don't continue any further
79                         this.getLoggerBeanLocal().logException(ex);
80                         return;
81                 }
82
83                 // Debug message
84                 this.getLoggerBeanLocal().logDebug(MessageFormat.format("onMessage: serializable={0}", serializable)); //NOI18N
85
86                 // Trace message
87                 this.getLoggerBeanLocal().logTrace("onMessage - EXIT!"); //NOI18N
88         }
89
90 }