1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.component; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleException; |
11 | |
import org.mule.api.component.Component; |
12 | |
import org.mule.api.lifecycle.Disposable; |
13 | |
import org.mule.api.lifecycle.Initialisable; |
14 | |
import org.mule.api.lifecycle.InitialisationException; |
15 | |
import org.mule.api.lifecycle.LifecycleCallback; |
16 | |
import org.mule.api.lifecycle.LifecycleException; |
17 | |
import org.mule.api.lifecycle.Startable; |
18 | |
import org.mule.api.lifecycle.Stoppable; |
19 | |
import org.mule.config.i18n.CoreMessages; |
20 | |
import org.mule.lifecycle.SimpleLifecycleManager; |
21 | |
|
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
public class ComponentLifecycleManager extends SimpleLifecycleManager<Component> |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | 0 | protected transient final Log logger = LogFactory.getLog(ComponentLifecycleManager.class); |
36 | |
protected MuleContext muleContext; |
37 | |
|
38 | |
public ComponentLifecycleManager(String name, Component component) |
39 | |
{ |
40 | 0 | super(name, component); |
41 | 0 | } |
42 | |
|
43 | |
@Override |
44 | |
public void fireInitialisePhase(LifecycleCallback<Component> callback) throws InitialisationException |
45 | |
{ |
46 | 0 | checkPhase(Initialisable.PHASE_NAME); |
47 | 0 | if (logger.isInfoEnabled()) logger.info("Initialising component: " + lifecycleManagerId); |
48 | |
try |
49 | |
{ |
50 | 0 | invokePhase(Initialisable.PHASE_NAME, getLifecycleObject(), callback); |
51 | |
} |
52 | 0 | catch (InitialisationException e) |
53 | |
{ |
54 | 0 | throw e; |
55 | |
} |
56 | 0 | catch (LifecycleException e) |
57 | |
{ |
58 | 0 | throw new InitialisationException(e, (Initialisable) object); |
59 | 0 | } |
60 | 0 | } |
61 | |
|
62 | |
@Override |
63 | |
public void fireStartPhase(LifecycleCallback<Component> callback) throws MuleException |
64 | |
{ |
65 | 0 | checkPhase(Startable.PHASE_NAME); |
66 | 0 | if (logger.isInfoEnabled()) logger.info("Starting component: " + lifecycleManagerId); |
67 | 0 | invokePhase(Startable.PHASE_NAME, getLifecycleObject(), callback); |
68 | 0 | } |
69 | |
|
70 | |
@Override |
71 | |
public void fireStopPhase(LifecycleCallback<Component> callback) throws MuleException |
72 | |
{ |
73 | 0 | checkPhase(Stoppable.PHASE_NAME); |
74 | 0 | if (logger.isInfoEnabled()) logger.info("Stopping component: " + lifecycleManagerId); |
75 | 0 | invokePhase(Stoppable.PHASE_NAME, getLifecycleObject(), callback); |
76 | 0 | } |
77 | |
|
78 | |
@Override |
79 | |
public void fireDisposePhase(LifecycleCallback<Component> callback) |
80 | |
{ |
81 | 0 | checkPhase(Disposable.PHASE_NAME); |
82 | 0 | if (logger.isInfoEnabled()) logger.info("Disposing component: " + lifecycleManagerId); |
83 | |
try |
84 | |
{ |
85 | 0 | invokePhase(Disposable.PHASE_NAME, getLifecycleObject(), callback); |
86 | |
} |
87 | 0 | catch (LifecycleException e) |
88 | |
{ |
89 | 0 | logger.warn(CoreMessages.failedToDispose(lifecycleManagerId), e); |
90 | 0 | } |
91 | 0 | } |
92 | |
|
93 | |
} |