1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.lifecycle.processor; |
12 | |
|
13 | |
import org.mule.api.MessagingException; |
14 | |
import org.mule.api.MuleEvent; |
15 | |
import org.mule.api.MuleException; |
16 | |
import org.mule.api.lifecycle.LifecycleState; |
17 | |
import org.mule.api.lifecycle.Startable; |
18 | |
import org.mule.config.i18n.CoreMessages; |
19 | |
import org.mule.service.Pausable; |
20 | |
|
21 | |
public class ProcessIfStartedWaitIfPausedMessageProcessor extends ProcessIfStartedMessageProcessor |
22 | |
{ |
23 | |
|
24 | |
public ProcessIfStartedWaitIfPausedMessageProcessor(Startable startable, LifecycleState lifecycleState) |
25 | |
{ |
26 | 0 | super(startable, lifecycleState); |
27 | 0 | } |
28 | |
|
29 | |
@Override |
30 | |
protected MuleEvent processNext(MuleEvent event) throws MuleException |
31 | |
{ |
32 | 0 | if (isPaused()) |
33 | |
{ |
34 | |
try |
35 | |
{ |
36 | 0 | if (logger.isDebugEnabled()) |
37 | |
{ |
38 | 0 | logger.debug(startable.getClass().getName() + " " + getStartableName(startable) |
39 | |
+ " is paused. Blocking call until resumd"); |
40 | |
} |
41 | 0 | while (isPaused()) |
42 | |
{ |
43 | 0 | Thread.sleep(500); |
44 | |
} |
45 | |
} |
46 | 0 | catch (InterruptedException e) |
47 | |
{ |
48 | 0 | throw new MessagingException( |
49 | |
CoreMessages.interruptedWaitingForPaused(getStartableName(startable)), |
50 | |
event, e); |
51 | 0 | } |
52 | |
} |
53 | 0 | return super.processNext(event); |
54 | |
} |
55 | |
|
56 | |
@Override |
57 | |
protected boolean accept(MuleEvent event) |
58 | |
{ |
59 | 0 | return lifecycleState.isStarted() || isPaused(); |
60 | |
} |
61 | |
|
62 | |
protected boolean isPaused() |
63 | |
{ |
64 | 0 | return lifecycleState.isPhaseComplete(Pausable.PHASE_NAME); |
65 | |
} |
66 | |
|
67 | |
} |