1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.model; |
8 | |
|
9 | |
import org.mule.api.MuleException; |
10 | |
import org.mule.api.lifecycle.Disposable; |
11 | |
import org.mule.api.lifecycle.Initialisable; |
12 | |
import org.mule.api.lifecycle.LifecycleCallback; |
13 | |
import org.mule.api.lifecycle.Startable; |
14 | |
import org.mule.api.lifecycle.Stoppable; |
15 | |
import org.mule.context.notification.ModelNotification; |
16 | |
import org.mule.lifecycle.SimpleLifecycleManager; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
public class ModelLifecycleManager extends SimpleLifecycleManager<AbstractModel> |
22 | |
{ |
23 | |
public ModelLifecycleManager(AbstractModel model) |
24 | |
{ |
25 | 0 | super(model.getName(), model); |
26 | 0 | } |
27 | |
|
28 | |
@Override |
29 | |
public void fireInitialisePhase(LifecycleCallback<AbstractModel> callback) throws MuleException |
30 | |
{ |
31 | 0 | checkPhase(Initialisable.PHASE_NAME); |
32 | |
|
33 | 0 | if(logger.isInfoEnabled()) logger.info("Initialising model: " + getLifecycleObject().getName()); |
34 | 0 | invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback); |
35 | 0 | fireNotification(ModelNotification.MODEL_INITIALISED); |
36 | 0 | } |
37 | |
|
38 | |
@Override |
39 | |
public void fireStartPhase(LifecycleCallback<AbstractModel> callback) throws MuleException |
40 | |
{ |
41 | 0 | checkPhase(Startable.PHASE_NAME); |
42 | |
|
43 | 0 | if(logger.isInfoEnabled()) logger.info("Starting model: " + getLifecycleObject().getName()); |
44 | 0 | invokePhase(Startable.PHASE_NAME, getLifecycleObject(), callback); |
45 | 0 | fireNotification(ModelNotification.MODEL_STARTED); |
46 | 0 | } |
47 | |
|
48 | |
@Override |
49 | |
public void fireStopPhase(LifecycleCallback<AbstractModel> callback) throws MuleException |
50 | |
{ |
51 | 0 | checkPhase(Stoppable.PHASE_NAME); |
52 | |
|
53 | 0 | if(logger.isInfoEnabled()) logger.info("Stopping model: " + getLifecycleObject().getName()); |
54 | 0 | invokePhase(Stoppable.PHASE_NAME, getLifecycleObject(), callback); |
55 | 0 | fireNotification(ModelNotification.MODEL_STOPPED); |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
public void fireDisposePhase(LifecycleCallback<AbstractModel> callback) throws MuleException |
60 | |
{ |
61 | 0 | checkPhase(Disposable.PHASE_NAME); |
62 | |
|
63 | 0 | if(logger.isInfoEnabled()) logger.info("Disposing model: " + getLifecycleObject().getName()); |
64 | 0 | invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback); |
65 | 0 | fireNotification(ModelNotification.MODEL_DISPOSED); |
66 | 0 | } |
67 | |
|
68 | |
void fireNotification(int action) |
69 | |
{ |
70 | 0 | getLifecycleObject().getMuleContext().fireNotification(new ModelNotification(getLifecycleObject(), action)); |
71 | 0 | } |
72 | |
} |