19 package org.turro.mail.pool;
21 import java.util.Collection;
22 import java.util.concurrent.BlockingQueue;
23 import java.util.concurrent.LinkedBlockingQueue;
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.atomic.AtomicBoolean;
26 import java.util.function.Consumer;
27 import org.turro.action.IElephantCloseable;
28 import org.turro.annotation.ElephantCloseable;
29 import org.turro.log.WebLoggers;
30 import org.turro.mail.message.MailMessage;
43 public void addToQueue(Collection<MailMessage> pool, Consumer onFinish) {
44 if(pool ==
null)
return;
45 int index = 0,
size = pool.size();
61 if(!QUEUE.offer(
new MailQueueItem(mail, onFinish), 60L, TimeUnit.MINUTES)) {
64 }
catch (InterruptedException ex) {
73 private void addTrigger() {
82 while (running.get()) {
84 if(!running.get())
break;
87 }
catch(Exception ex) {
92 }
catch (InterruptedException e) {
93 Thread.currentThread().interrupt();
99 private static final BlockingQueue<MailQueueItem> QUEUE =
new LinkedBlockingQueue<>(500);
104 private static Thread MAIL_QUEUE;
105 private static final AtomicBoolean running =
new AtomicBoolean(
false);
108 if(INSTANCE ==
null) {
110 MAIL_QUEUE =
new Thread(INSTANCE,
"ElephantMailQueue");
117 if(INSTANCE !=
null) {
128 @Deprecated(forRemoval =
false)
static WebLoggers warning(Object entity)
WebLoggers message(String text, Object... parameters)
static WebLoggers severe(Object entity)
WebLoggers exception(Throwable throwable)
static MailQueueConsumer getInstance()
void addToQueue(MailMessage mail)
void addToQueue(MailMessage mail, Consumer onFinish)
void addToQueue(Collection< MailMessage > pool)
void addToQueue(Collection< MailMessage > pool, Consumer onFinish)