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