1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.ksb.cache; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
|
21 | |
import javax.xml.namespace.QName; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.kuali.rice.core.exception.RiceRuntimeException; |
26 | |
import org.kuali.rice.ksb.messaging.JavaServiceDefinition; |
27 | |
import org.kuali.rice.ksb.messaging.RemotedServiceRegistry; |
28 | |
import org.kuali.rice.ksb.messaging.service.KSBJavaService; |
29 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
30 | |
|
31 | |
import com.opensymphony.oscache.base.Cache; |
32 | |
import com.opensymphony.oscache.base.Config; |
33 | |
import com.opensymphony.oscache.base.FinalizationException; |
34 | |
import com.opensymphony.oscache.base.InitializationException; |
35 | |
import com.opensymphony.oscache.plugins.clustersupport.AbstractBroadcastingListener; |
36 | |
import com.opensymphony.oscache.plugins.clustersupport.ClusterNotification; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class RiceDistributedCacheListener extends AbstractBroadcastingListener implements KSBJavaService { |
47 | |
|
48 | 0 | private static final Logger LOG = Logger.getLogger(RiceDistributedCacheListener.class); |
49 | |
|
50 | |
private String serviceName; |
51 | |
|
52 | |
protected RemotedServiceRegistry remotedServiceRegistry; |
53 | |
|
54 | |
@Override |
55 | |
public void initialize(Cache cache, Config config) throws InitializationException { |
56 | |
|
57 | 0 | LOG.info("Initializing cache listener"); |
58 | 0 | super.initialize(cache, config); |
59 | |
|
60 | |
|
61 | 0 | this.serviceName = config.getProperty(RiceCacheAdministrator.SERVICE_NAME_KEY); |
62 | 0 | boolean forceRegistryRefresh = new Boolean((Boolean)config.getProperties().get(RiceCacheAdministrator.FORCE_REGISTRY_REFRESH_KEY)); |
63 | 0 | remotedServiceRegistry = (RemotedServiceRegistry)config.getProperties().get(RiceCacheAdministrator.REMOTED_SERVICE_REGISTRY); |
64 | 0 | if (StringUtils.isBlank(this.serviceName)) { |
65 | 0 | throw new RiceRuntimeException("Cannot create DistributedCacheListener with empty serviceName"); |
66 | |
} |
67 | 0 | LOG.info("Publishing Cache Service on bus under service name " + this.serviceName); |
68 | 0 | JavaServiceDefinition serviceDef = new JavaServiceDefinition(); |
69 | 0 | serviceDef.setPriority(3); |
70 | 0 | serviceDef.setRetryAttempts(1); |
71 | 0 | serviceDef.setService(this); |
72 | 0 | serviceDef.setLocalServiceName(this.serviceName); |
73 | 0 | serviceDef.setServiceNameSpaceURI(""); |
74 | 0 | serviceDef.setQueue(false); |
75 | |
try { |
76 | 0 | serviceDef.validate(); |
77 | 0 | } catch (Exception e) { |
78 | 0 | throw new RiceRuntimeException(e); |
79 | 0 | } |
80 | 0 | if(remotedServiceRegistry!=null) |
81 | 0 | remotedServiceRegistry.registerService(serviceDef, forceRegistryRefresh); |
82 | |
else |
83 | 0 | KSBServiceLocator.getServiceDeployer().registerService(serviceDef, forceRegistryRefresh); |
84 | 0 | } |
85 | |
|
86 | |
@Override |
87 | |
protected void sendNotification(ClusterNotification notification) { |
88 | 0 | if (LOG.isDebugEnabled()) { |
89 | 0 | LOG.debug("Sending cache notification " + notification); |
90 | |
} |
91 | |
try { |
92 | 0 | KSBJavaService oscacheNotificationService = (KSBJavaService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(new QName(this.serviceName)); |
93 | 0 | oscacheNotificationService.invoke(notification); |
94 | 0 | } catch (Exception e) { |
95 | 0 | throw new RiceRuntimeException(e); |
96 | 0 | } |
97 | 0 | } |
98 | |
|
99 | |
public void finialize() throws FinalizationException { |
100 | |
|
101 | 0 | } |
102 | |
|
103 | |
public void invoke(Serializable payLoad) { |
104 | 0 | super.handleClusterNotification((ClusterNotification) payLoad); |
105 | 0 | } |
106 | |
|
107 | |
} |