1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.bam; |
17 | |
|
18 | |
import java.lang.reflect.InvocationTargetException; |
19 | |
import java.lang.reflect.Method; |
20 | |
import java.lang.reflect.Proxy; |
21 | |
|
22 | |
import org.kuali.rice.core.api.config.property.Config; |
23 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
24 | |
import org.kuali.rice.core.impl.resourceloader.ContextClassLoaderProxy; |
25 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
26 | |
import org.kuali.rice.core.util.reflect.BaseTargetedInvocationHandler; |
27 | |
import org.kuali.rice.ksb.api.bus.ServiceConfiguration; |
28 | |
import org.kuali.rice.ksb.impl.registry.ServiceInfoBo; |
29 | |
import org.kuali.rice.ksb.messaging.bam.service.BAMService; |
30 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public class BAMClientProxy extends BaseTargetedInvocationHandler { |
42 | |
|
43 | |
private ServiceConfiguration serviceConfiguration; |
44 | |
|
45 | |
private BAMClientProxy(Object target, ServiceConfiguration serviceConfiguration) { |
46 | 0 | super(target); |
47 | 0 | this.serviceConfiguration = serviceConfiguration; |
48 | 0 | } |
49 | |
|
50 | |
public static boolean isBamSupported() { |
51 | 0 | return KSBServiceLocator.getBAMService() != null && Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(Config.BAM_ENABLED)); |
52 | |
} |
53 | |
|
54 | |
public static Object wrap(Object target, ServiceConfiguration serviceConfiguration) { |
55 | 0 | if (!isBamSupported()) { |
56 | 0 | return target; |
57 | |
} |
58 | 0 | return Proxy.newProxyInstance(ClassLoaderUtils.getDefaultClassLoader(), ContextClassLoaderProxy.getInterfacesToProxy(target), new BAMClientProxy(target, serviceConfiguration)); |
59 | |
} |
60 | |
|
61 | |
protected Object invokeInternal(Object proxyObject, Method method, Object[] arguments) throws Throwable { |
62 | 0 | BAMTargetEntry bamTargetEntry = KSBServiceLocator.getBAMService().recordClientInvocation(this.serviceConfiguration, getTarget(), method, arguments); |
63 | |
try { |
64 | 0 | return method.invoke(getTarget(), arguments); |
65 | 0 | } catch (Throwable throwable) { |
66 | 0 | if (throwable instanceof InvocationTargetException) { |
67 | 0 | throwable = throwable.getCause(); |
68 | |
} |
69 | 0 | KSBServiceLocator.getBAMService().recordClientInvocationError(throwable, bamTargetEntry); |
70 | 0 | throw throwable; |
71 | |
} |
72 | |
} |
73 | |
} |