1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.objectremoting; |
17 | |
|
18 | |
import javax.xml.namespace.QName; |
19 | |
|
20 | |
import org.apache.log4j.Logger; |
21 | |
import org.kuali.rice.core.config.ConfigContext; |
22 | |
import org.kuali.rice.core.lifecycle.BaseLifecycle; |
23 | |
import org.kuali.rice.core.reflect.ObjectDefinition; |
24 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
25 | |
import org.kuali.rice.ksb.messaging.JavaServiceDefinition; |
26 | |
import org.kuali.rice.ksb.messaging.ServiceInfo; |
27 | |
import org.kuali.rice.ksb.messaging.config.ServiceBasedServiceDefinitionRegisterer; |
28 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
29 | |
|
30 | |
|
31 | 0 | public class ObjectRemoterServiceImpl extends BaseLifecycle implements ObjectRemoterService { |
32 | |
|
33 | 0 | private static final Logger LOG = Logger.getLogger(ObjectRemoterServiceImpl.class); |
34 | |
|
35 | |
private ServiceBasedServiceDefinitionRegisterer defRegisterer; |
36 | 0 | private static long counter = 0; |
37 | |
|
38 | |
public ServiceInfo getRemotedClassURL(ObjectDefinition objectDefinition) { |
39 | 0 | LOG.debug("Looking for object " + objectDefinition.getClassName()); |
40 | 0 | objectDefinition.setAtRemotingLayer(true); |
41 | 0 | Object target = GlobalResourceLoader.getResourceLoader().getObject(objectDefinition); |
42 | |
|
43 | 0 | if (target == null) { |
44 | 0 | LOG.debug("Didn't find object " + objectDefinition); |
45 | 0 | return null; |
46 | |
} |
47 | |
|
48 | 0 | LOG.debug("Found object " + objectDefinition); |
49 | 0 | JavaServiceDefinition serviceDefinition = new JavaServiceDefinition(); |
50 | 0 | serviceDefinition.setLocalServiceName(objectDefinition.getClassName() + counter++); |
51 | 0 | serviceDefinition.setService(target); |
52 | 0 | serviceDefinition.validate(); |
53 | |
|
54 | 0 | KSBServiceLocator.getServiceDeployer().registerTempService(serviceDefinition, target); |
55 | 0 | serviceDefinition.setService(null); |
56 | 0 | return new ServiceInfo(serviceDefinition); |
57 | |
} |
58 | |
|
59 | |
public void removeService(QName serviceName) { |
60 | 0 | LOG.debug("Removing service " + serviceName + " from service namespace" + ConfigContext.getCurrentContextConfig().getServiceNamespace()); |
61 | 0 | KSBServiceLocator.getServiceDeployer().removeRemoteServiceFromRegistry(serviceName); |
62 | 0 | } |
63 | |
|
64 | |
public void start() throws Exception { |
65 | 0 | this.defRegisterer = new ServiceBasedServiceDefinitionRegisterer("ksb.objectRemoterServiceDefinition"); |
66 | 0 | this.defRegisterer.registerServiceDefinition(false); |
67 | 0 | setStarted(true); |
68 | 0 | } |
69 | |
|
70 | |
public void stop() throws Exception { |
71 | 0 | this.defRegisterer.unregisterServiceDefinition(); |
72 | 0 | setStarted(false); |
73 | 0 | } |
74 | |
} |