1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal.thread; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.slf4j.LoggerFactory; |
32 |
|
import org.xwiki.bridge.event.ApplicationReadyEvent; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.component.manager.ComponentLifecycleException; |
35 |
|
import org.xwiki.component.phase.Disposable; |
36 |
|
import org.xwiki.observation.EventListener; |
37 |
|
import org.xwiki.observation.event.Event; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named(MailSenderInitializerListener.LISTENER_NAME) |
49 |
|
@Singleton |
|
|
| 96.9% |
Uncovered Elements: 1 (32) |
Complexity: 8 |
Complexity Density: 0.35 |
|
50 |
|
public class MailSenderInitializerListener implements EventListener, Disposable |
51 |
|
{ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public static final String LISTENER_NAME = "MailSenderInitializationEventListener"; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private static final List<Event> EVENTS = new ArrayList<Event>(Arrays.asList(new ApplicationReadyEvent())); |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
private static final Logger SHUTDOWN_LOGGER = LoggerFactory.getLogger("org.xwiki.shutdown"); |
66 |
|
|
67 |
|
@Inject |
68 |
|
@Named("prepare") |
69 |
|
private MailRunnable prepareMailRunnable; |
70 |
|
|
71 |
|
@Inject |
72 |
|
@Named("send") |
73 |
|
private MailRunnable sendMailRunnable; |
74 |
|
|
75 |
|
private Thread prepareMailThread; |
76 |
|
|
77 |
|
private Thread sendMailThread; |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
28 |
@Override... |
80 |
|
public String getName() |
81 |
|
{ |
82 |
28 |
return LISTENER_NAME; |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
7 |
@Override... |
86 |
|
public List<Event> getEvents() |
87 |
|
{ |
88 |
7 |
return EVENTS; |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
91 |
10 |
@Override... |
92 |
|
public void onEvent(Event event, Object o, Object o1) |
93 |
|
{ |
94 |
|
|
95 |
10 |
this.prepareMailThread = new Thread(this.prepareMailRunnable); |
96 |
10 |
this.prepareMailThread.setName("Mail Prepare Thread"); |
97 |
10 |
this.prepareMailThread.setDaemon(true); |
98 |
10 |
this.prepareMailThread.start(); |
99 |
|
|
100 |
|
|
101 |
10 |
this.sendMailThread = new Thread(this.sendMailRunnable); |
102 |
10 |
this.sendMailThread.setName("Mail Sender Thread"); |
103 |
10 |
this.sendMailThread.setDaemon(true); |
104 |
10 |
this.sendMailThread.start(); |
105 |
|
|
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@throws |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
113 |
19 |
private void stopMailThreads() throws InterruptedException... |
114 |
|
{ |
115 |
|
|
116 |
|
|
117 |
19 |
if (this.sendMailThread != null) { |
118 |
16 |
this.sendMailRunnable.stopProcessing(); |
119 |
|
|
120 |
16 |
this.sendMailThread.interrupt(); |
121 |
|
|
122 |
16 |
this.sendMailThread.join(); |
123 |
16 |
SHUTDOWN_LOGGER.debug(String.format("Mail Prepare Thread has been stopped")); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
19 |
if (this.prepareMailThread != null) { |
129 |
16 |
this.prepareMailRunnable.stopProcessing(); |
130 |
|
|
131 |
16 |
this.prepareMailThread.interrupt(); |
132 |
|
|
133 |
16 |
this.prepareMailThread.join(); |
134 |
16 |
SHUTDOWN_LOGGER.debug(String.format("Mail Sender Thread has been stopped")); |
135 |
|
} |
136 |
|
} |
137 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
138 |
19 |
@Override... |
139 |
|
public void dispose() throws ComponentLifecycleException |
140 |
|
{ |
141 |
19 |
try { |
142 |
19 |
stopMailThreads(); |
143 |
|
} catch (InterruptedException e) { |
144 |
0 |
SHUTDOWN_LOGGER.debug("Mail threads shutdown has been interruped", e); |
145 |
|
} |
146 |
|
} |
147 |
|
} |