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