1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.component; |
12 | |
|
13 | |
import org.mule.api.MuleException; |
14 | |
import org.mule.api.component.LifecycleAdapter; |
15 | |
import org.mule.api.lifecycle.InitialisationCallback; |
16 | |
import org.mule.api.lifecycle.InitialisationException; |
17 | |
import org.mule.api.model.EntryPointResolverSet; |
18 | |
import org.mule.api.object.ObjectFactory; |
19 | |
import org.mule.api.routing.NestedRouterCollection; |
20 | |
import org.mule.config.PoolingProfile; |
21 | |
import org.mule.util.pool.DefaultLifecycleEnabledObjectPool; |
22 | |
import org.mule.util.pool.LifecyleEnabledObjectPool; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class PooledJavaComponent extends AbstractJavaComponent |
28 | |
{ |
29 | |
|
30 | |
protected PoolingProfile poolingProfile; |
31 | |
protected LifecyleEnabledObjectPool lifecycleAdapterPool; |
32 | |
|
33 | |
public PooledJavaComponent() |
34 | |
{ |
35 | 0 | super(); |
36 | 0 | } |
37 | |
|
38 | |
public PooledJavaComponent(ObjectFactory objectFactory) |
39 | |
{ |
40 | 0 | this(objectFactory, null); |
41 | 0 | } |
42 | |
|
43 | |
public PooledJavaComponent(ObjectFactory objectFactory, PoolingProfile poolingProfile) |
44 | |
{ |
45 | 24 | super(objectFactory); |
46 | 24 | this.poolingProfile = poolingProfile; |
47 | 24 | } |
48 | |
|
49 | |
public PooledJavaComponent(ObjectFactory objectFactory, |
50 | |
PoolingProfile poolingProfile, |
51 | |
EntryPointResolverSet entryPointResolverSet, |
52 | |
NestedRouterCollection nestedRouterCollection) |
53 | |
{ |
54 | 0 | super(objectFactory, entryPointResolverSet, nestedRouterCollection); |
55 | 0 | this.poolingProfile = poolingProfile; |
56 | 0 | } |
57 | |
|
58 | |
protected LifecycleAdapter borrowComponentLifecycleAdaptor() throws Exception |
59 | |
{ |
60 | 56 | return (LifecycleAdapter) lifecycleAdapterPool.borrowObject(); |
61 | |
} |
62 | |
|
63 | |
protected void returnComponentLifecycleAdaptor(LifecycleAdapter lifecycleAdapter) |
64 | |
{ |
65 | 8 | lifecycleAdapterPool.returnObject(lifecycleAdapter); |
66 | 8 | } |
67 | |
|
68 | |
protected void doStart() throws MuleException |
69 | |
{ |
70 | 26 | super.doStart(); |
71 | |
|
72 | |
|
73 | 26 | lifecycleAdapterPool = new DefaultLifecycleEnabledObjectPool(new LifeCycleAdaptorFactory(), poolingProfile); |
74 | 26 | lifecycleAdapterPool.initialise(); |
75 | 26 | lifecycleAdapterPool.start(); |
76 | 26 | } |
77 | |
|
78 | |
protected void doStop() throws MuleException |
79 | |
{ |
80 | 8 | super.doStop(); |
81 | 8 | if (lifecycleAdapterPool != null) |
82 | |
{ |
83 | 8 | lifecycleAdapterPool.stop(); |
84 | 8 | lifecycleAdapterPool.close(); |
85 | 8 | lifecycleAdapterPool = null; |
86 | |
} |
87 | 8 | } |
88 | |
|
89 | |
public void setPoolingProfile(PoolingProfile poolingProfile) |
90 | |
{ |
91 | |
|
92 | |
|
93 | |
|
94 | 0 | this.poolingProfile = poolingProfile; |
95 | 0 | } |
96 | |
|
97 | |
public PoolingProfile getPoolingProfile() |
98 | |
{ |
99 | 6 | return poolingProfile; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | 26 | protected class LifeCycleAdaptorFactory implements ObjectFactory |
112 | |
{ |
113 | |
|
114 | |
public Object getInstance() throws Exception |
115 | |
{ |
116 | 50 | return createLifeCycleAdaptor(); |
117 | |
} |
118 | |
|
119 | |
public Class getObjectClass() |
120 | |
{ |
121 | 0 | return LifecycleAdapter.class; |
122 | |
} |
123 | |
|
124 | |
public void initialise() throws InitialisationException |
125 | |
{ |
126 | 0 | objectFactory.initialise(); |
127 | 0 | } |
128 | |
|
129 | |
public void dispose() |
130 | |
{ |
131 | 0 | objectFactory.dispose(); |
132 | 0 | } |
133 | |
|
134 | |
public void addObjectInitialisationCallback(InitialisationCallback callback) |
135 | |
{ |
136 | 0 | objectFactory.addObjectInitialisationCallback(callback); |
137 | 0 | } |
138 | |
|
139 | |
public boolean isSingleton() |
140 | |
{ |
141 | 0 | return false; |
142 | |
} |
143 | |
} |
144 | |
|
145 | |
} |