19 package org.turro.mail.sender;
21 import java.util.concurrent.locks.Lock;
22 import java.util.concurrent.locks.ReentrantLock;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.string.Strings;
26 import org.apache.commons.mail.EmailException;
27 import org.turro.action.queue.NotificationCategory;
28 import org.turro.annotation.ElephantPlugin;
29 import org.turro.elephant.context.ElephantContext;
35 @ElephantPlugin(label =
"heavy")
39 private Object entity;
40 private String
template, subject, message;
44 this.category = category;
46 this.
template =
template;
47 this.subject = subject;
53 this.category = category;
54 this.subject = subject;
55 this.message = message;
59 private void doBuild() {
61 Thread sender =
new Thread(
this,
"HeavySenderTask");
70 boolean lockAcquired = HEAVY_LOCK.tryLock();
73 if(onStart !=
null) onStart.accept(
MailHeavy.this);
75 if(!Strings.isBlank(
template)) {
76 super.doSendTemplate(category, entity,
template, subject);
78 super.doSend(category, subject, message);
80 }
catch (Exception ex) {
86 if(onCancel !=
null) onCancel.accept(
MailHeavy.this);
92 private static final Lock HEAVY_LOCK =
new ReentrantLock();
static String logMsg(String msg)
void doSend(NotificationCategory category, String subject, String message)
void doSendTemplate(NotificationCategory category, Object entity, String template, String subject)