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