Revision 35648
Added by Michele Artini about 9 years ago
modules/dnet-components/trunk/src/main/resources/eu/dnetlib/common/services/locators/applicationContext-locators.properties | ||
---|---|---|
1 |
default.service.comparator = preferLocalRunningInstanceComparator |
modules/dnet-components/trunk/src/main/resources/eu/dnetlib/common/services/locators/applicationContext-locators.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" |
|
4 |
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" |
|
5 |
xmlns:util="http://www.springframework.org/schema/util" |
|
6 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
7 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd |
|
8 |
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd |
|
9 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> |
|
10 |
|
|
11 |
<bean id="defaultDnetServiceLocator" |
|
12 |
class="eu.dnetlib.common.services.locators.DefaultDnetServiceLocator" |
|
13 |
p:defaultComparator-ref="defaultServiceComparator"/> |
|
14 |
|
|
15 |
<bean id="preferLocalRunningInstanceComparator" |
|
16 |
class="eu.dnetlib.common.services.locators.comparators.PreferLocalRunningInstanceComparator" /> |
|
17 |
|
|
18 |
<alias name="${default.service.comparator}" alias="defaultServiceComparator" /> |
|
19 |
|
|
20 |
</beans> |
modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/enabling/is/hib/utils/HibObjectHelper.java | ||
---|---|---|
108 | 108 |
final HibBlackboardMessage hib = dao.find(message.getId()); |
109 | 109 |
hib.setAction(message.getAction()); |
110 | 110 |
hib.setDate(message.getDate()); |
111 |
hib.setParams(new Gson().toJson(message.getParameters()));
|
|
111 |
hib.setMessage(message.getJsonMessage());
|
|
112 | 112 |
hib.setStatus(message.getStatus().toString()); |
113 | 113 |
dao.save(hib); |
114 | 114 |
} |
modules/dnet-information-service/trunk/src/main/java/eu/dnetlib/enabling/is/hib/objects/HibBlackboardMessage.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.Serializable; |
4 | 4 |
import java.util.Date; |
5 |
import java.util.Map; |
|
6 | 5 |
|
7 | 6 |
import javax.persistence.Entity; |
8 | 7 |
import javax.persistence.Id; |
... | ... | |
13 | 12 |
|
14 | 13 |
import org.hibernate.Session; |
15 | 14 |
|
16 |
import com.google.gson.Gson; |
|
17 |
import com.google.gson.reflect.TypeToken; |
|
18 |
|
|
19 | 15 |
import eu.dnetlib.rmi.objects.is.BlackboardActionStatus; |
20 | 16 |
import eu.dnetlib.rmi.objects.is.BlackboardMessage; |
21 | 17 |
|
... | ... | |
36 | 32 |
private Date date; |
37 | 33 |
private String action; |
38 | 34 |
private String status; |
39 |
private String params;
|
|
35 |
private String message;
|
|
40 | 36 |
|
41 | 37 |
public HibBlackboardMessage() {} |
42 | 38 |
|
43 |
public HibBlackboardMessage(final HibService service, final String id, final Date date, final String action, final String status, final String params) {
|
|
39 |
public HibBlackboardMessage(final HibService service, final String id, final Date date, final String action, final String status, final String message) {
|
|
44 | 40 |
this.service = service; |
45 | 41 |
this.id = id; |
46 | 42 |
this.date = date; |
47 | 43 |
this.action = action; |
48 | 44 |
this.status = status; |
49 |
this.params = params;
|
|
45 |
this.setMessage(message);
|
|
50 | 46 |
} |
51 | 47 |
|
52 | 48 |
public HibBlackboardMessage(final HibService service, final BlackboardMessage b) { |
... | ... | |
54 | 50 |
setAction(b.getAction()); |
55 | 51 |
setDate(b.getDate()); |
56 | 52 |
setId(b.getId()); |
57 |
setParams(new Gson().toJson(b.getParameters()));
|
|
53 |
setMessage(b.getJsonMessage());
|
|
58 | 54 |
setService(service); |
59 | 55 |
setStatus(b.getStatus().toString()); |
60 | 56 |
} |
... | ... | |
99 | 95 |
this.status = status; |
100 | 96 |
} |
101 | 97 |
|
102 |
public String getParams() {
|
|
103 |
return params;
|
|
98 |
public String getMessage() {
|
|
99 |
return message;
|
|
104 | 100 |
} |
105 | 101 |
|
106 |
public void setParams(final String params) {
|
|
107 |
this.params = params;
|
|
102 |
public void setMessage(final String message) {
|
|
103 |
this.message = message;
|
|
108 | 104 |
} |
109 | 105 |
|
110 | 106 |
public BlackboardMessage asDnetBlackboardMessage() { |
111 |
final BlackboardMessage message = new BlackboardMessage(); |
|
112 |
final Map<String, String> mapParams = new Gson().fromJson(params, new TypeToken<Map<String, String>>() {}.getType()); |
|
113 |
message.setId(id); |
|
114 |
message.setAction(action); |
|
115 |
message.setStatus(BlackboardActionStatus.valueOf(status)); |
|
116 |
message.setDate(date); |
|
117 |
message.setParameters(mapParams); |
|
118 |
return message; |
|
107 |
final BlackboardMessage bb = new BlackboardMessage(); |
|
108 |
bb.setId(id); |
|
109 |
bb.setAction(action); |
|
110 |
bb.setStatus(BlackboardActionStatus.valueOf(status)); |
|
111 |
bb.setDate(date); |
|
112 |
bb.setJsonMessage(message); |
|
113 |
return bb; |
|
119 | 114 |
} |
120 | 115 |
|
121 | 116 |
@Override |
... | ... | |
129 | 124 |
public int hashCode() { |
130 | 125 |
return id.hashCode(); |
131 | 126 |
} |
127 |
|
|
132 | 128 |
} |
modules/dnet-information-service/trunk/src/main/resources/eu/dnetlib/enabling/is/setup/is_base.sql | ||
---|---|---|
27 | 27 |
id varchar(255) NOT NULL PRIMARY KEY, |
28 | 28 |
action varchar(255) NOT NULL, |
29 | 29 |
date timestamp, |
30 |
params text,
|
|
30 |
message text,
|
|
31 | 31 |
status varchar(255) NOT NULL |
32 | 32 |
); |
33 | 33 |
|
modules/dnet-components/trunk/src/main/java/eu/dnetlib/enabling/annotations/Blackboard.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.annotations; |
|
2 |
|
|
3 |
import java.lang.annotation.ElementType; |
|
4 |
import java.lang.annotation.Retention; |
|
5 |
import java.lang.annotation.RetentionPolicy; |
|
6 |
import java.lang.annotation.Target; |
|
7 |
|
|
8 |
import eu.dnetlib.rmi.soap.BaseService; |
|
9 |
|
|
10 |
@Retention(RetentionPolicy.RUNTIME) |
|
11 |
@Target(ElementType.TYPE) |
|
12 |
public @interface Blackboard { |
|
13 |
|
|
14 |
String action(); |
|
15 |
|
|
16 |
Class<? extends BaseService> serviceClass(); |
|
17 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/rmi/soap/TestService.java | ||
---|---|---|
1 |
package eu.dnetlib.rmi.soap; |
|
2 |
|
|
3 |
import javax.jws.WebService; |
|
4 |
|
|
5 |
@WebService(targetNamespace = "http://services.dnetlib.eu/") |
|
6 |
public interface TestService extends BaseService { |
|
7 |
|
|
8 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/rmi/blackboard/SumMessage.java | ||
---|---|---|
1 |
package eu.dnetlib.rmi.blackboard; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.annotations.Blackboard; |
|
4 |
import eu.dnetlib.rmi.soap.TestService; |
|
5 |
|
|
6 |
@Blackboard(action = "ADD", serviceClass = TestService.class) |
|
7 |
public class SumMessage { |
|
8 |
|
|
9 |
private int x = 0; |
|
10 |
private int y = 0; |
|
11 |
private int res = 0; |
|
12 |
|
|
13 |
public SumMessage() {} |
|
14 |
|
|
15 |
public SumMessage(final int x, final int y) { |
|
16 |
this.x = x; |
|
17 |
this.y = y; |
|
18 |
} |
|
19 |
|
|
20 |
public SumMessage(final int x, final int y, final int res) { |
|
21 |
this.x = x; |
|
22 |
this.y = y; |
|
23 |
this.res = res; |
|
24 |
} |
|
25 |
|
|
26 |
public int getX() { |
|
27 |
return x; |
|
28 |
} |
|
29 |
|
|
30 |
public void setX(final int x) { |
|
31 |
this.x = x; |
|
32 |
} |
|
33 |
|
|
34 |
public int getY() { |
|
35 |
return y; |
|
36 |
} |
|
37 |
|
|
38 |
public void setY(final int y) { |
|
39 |
this.y = y; |
|
40 |
} |
|
41 |
|
|
42 |
public int getRes() { |
|
43 |
return res; |
|
44 |
} |
|
45 |
|
|
46 |
public void setRes(final int res) { |
|
47 |
this.res = res; |
|
48 |
} |
|
49 |
|
|
50 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/rmi/objects/is/BlackboardMessage.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.rmi.objects.is; |
2 | 2 |
|
3 | 3 |
import java.util.Date; |
4 |
import java.util.Map; |
|
5 | 4 |
|
6 | 5 |
import javax.xml.bind.annotation.XmlRootElement; |
7 | 6 |
|
... | ... | |
12 | 11 |
private String action; |
13 | 12 |
private BlackboardActionStatus status; |
14 | 13 |
private Date date; |
15 |
private Map<String, String> parameters;
|
|
14 |
private String jsonMessage;
|
|
16 | 15 |
|
17 | 16 |
public BlackboardMessage() {} |
18 | 17 |
|
19 |
public BlackboardMessage(final String id, final String action, final BlackboardActionStatus status, final Date date, final Map<String, String> parameters) {
|
|
18 |
public BlackboardMessage(final String id, final String action, final BlackboardActionStatus status, final Date date, final String jsonMessage) {
|
|
20 | 19 |
this.id = id; |
21 | 20 |
this.action = action; |
22 | 21 |
this.status = status; |
23 | 22 |
this.date = date; |
24 |
this.parameters = parameters;
|
|
23 |
this.jsonMessage = jsonMessage;
|
|
25 | 24 |
} |
26 | 25 |
|
27 | 26 |
public String getId() { |
... | ... | |
56 | 55 |
this.date = date; |
57 | 56 |
} |
58 | 57 |
|
59 |
public Map<String, String> getParameters() {
|
|
60 |
return parameters;
|
|
58 |
public String getJsonMessage() {
|
|
59 |
return jsonMessage;
|
|
61 | 60 |
} |
62 | 61 |
|
63 |
public void setParameters(final Map<String, String> parameters) {
|
|
64 |
this.parameters = parameters;
|
|
62 |
public void setJsonMessage(final String jsonMessage) {
|
|
63 |
this.jsonMessage = jsonMessage;
|
|
65 | 64 |
} |
66 | 65 |
|
67 | 66 |
@Override |
68 | 67 |
public int hashCode() { |
69 | 68 |
return id.hashCode(); |
70 | 69 |
} |
70 |
|
|
71 | 71 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/common/services/ServiceNameResolver.java | ||
---|---|---|
7 | 7 |
public class ServiceNameResolver { |
8 | 8 |
|
9 | 9 |
public static String resolveServiceName(final Class<? extends BaseService> clazz) { |
10 |
for (Class<?> ifc : clazz.getInterfaces()) { |
|
11 |
if (ifc.getAnnotation(WebService.class) != null) { return ifc.getSimpleName(); } |
|
10 |
if (clazz.isInterface() && clazz.isAnnotationPresent(WebService.class)) { |
|
11 |
return clazz.getSimpleName(); |
|
12 |
} else { |
|
13 |
for (Class<?> ifc : clazz.getInterfaces()) { |
|
14 |
if (ifc.isAnnotationPresent(WebService.class)) { return ifc.getSimpleName(); } |
|
15 |
} |
|
16 |
for (Class<?> ifc : clazz.getInterfaces()) { |
|
17 |
if (BaseService.class.isAssignableFrom(ifc)) { return ifc.getSimpleName(); } |
|
18 |
} |
|
12 | 19 |
} |
13 |
for (Class<?> ifc : clazz.getInterfaces()) { |
|
14 |
if (BaseService.class.isAssignableFrom(ifc)) { return ifc.getSimpleName(); } |
|
15 |
} |
|
16 | 20 |
return clazz.getSimpleName(); |
17 | 21 |
} |
18 | 22 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/common/blackboard/BlackboardDispatcher.java | ||
---|---|---|
1 |
package eu.dnetlib.common.blackboard; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
import java.util.UUID; |
|
5 |
import java.util.concurrent.Callable; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
|
|
12 |
import com.google.gson.Gson; |
|
13 |
|
|
14 |
import eu.dnetlib.common.services.locators.DnetServiceLocator; |
|
15 |
import eu.dnetlib.enabling.annotations.Blackboard; |
|
16 |
import eu.dnetlib.rmi.objects.is.BlackboardActionStatus; |
|
17 |
import eu.dnetlib.rmi.objects.is.BlackboardMessage; |
|
18 |
import eu.dnetlib.rmi.soap.BaseService; |
|
19 |
import eu.dnetlib.rmi.soap.InformationService; |
|
20 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
|
21 |
|
|
22 |
public class BlackboardDispatcher { |
|
23 |
|
|
24 |
@Resource |
|
25 |
private DnetServiceLocator serviceLocator; |
|
26 |
|
|
27 |
private static final Log log = LogFactory.getLog(BlackboardDispatcher.class); |
|
28 |
|
|
29 |
public <T> void createDispatcher(final T message, final Callable<T> onSuccess, final Callable<T> onFail, final Callable<T> onOngoing) |
|
30 |
throws InformationServiceException { |
|
31 |
if (message != null && message.getClass().isAnnotationPresent(Blackboard.class)) { |
|
32 |
final Blackboard annotation = message.getClass().getAnnotation(Blackboard.class); |
|
33 |
final Class<? extends BaseService> serviceClass = annotation.serviceClass(); |
|
34 |
log.info("**** " + serviceClass); |
|
35 |
|
|
36 |
final String serviceId = serviceLocator.getServiceId(serviceClass); |
|
37 |
log.info("**** " + serviceId); |
|
38 |
|
|
39 |
serviceLocator.getService(InformationService.class).addBlackBoardMessage(serviceId, asSoapMessage(annotation.action(), message)); |
|
40 |
} else if (message != null) { |
|
41 |
log.error("Missing BlackboardMessage annotation, class: " + message.getClass()); |
|
42 |
} else { |
|
43 |
log.error("Message is null"); |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
private BlackboardMessage asSoapMessage(final String action, final Object message) { |
|
48 |
final BlackboardMessage bb = new BlackboardMessage(); |
|
49 |
bb.setAction(action); |
|
50 |
bb.setDate(new Date()); |
|
51 |
bb.setId("bb-" + UUID.randomUUID()); |
|
52 |
bb.setStatus(BlackboardActionStatus.ASSIGNED); |
|
53 |
bb.setJsonMessage(new Gson().toJson(message)); |
|
54 |
return bb; |
|
55 |
} |
|
56 |
} |
modules/dnet-components/trunk/src/main/resources/eu/dnetlib/common/applicationContext-common.properties | ||
---|---|---|
1 |
default.service.comparator = preferLocalRunningInstanceComparator |
modules/dnet-components/trunk/src/main/resources/eu/dnetlib/common/applicationContext-common.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" |
|
4 |
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" |
|
5 |
xmlns:util="http://www.springframework.org/schema/util" |
|
6 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
7 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd |
|
8 |
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd |
|
9 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> |
|
10 |
|
|
11 |
<bean id="defaultDnetServiceLocator" |
|
12 |
class="eu.dnetlib.common.services.locators.DefaultDnetServiceLocator" |
|
13 |
p:defaultComparator-ref="defaultServiceComparator"/> |
|
14 |
|
|
15 |
<bean id="preferLocalRunningInstanceComparator" |
|
16 |
class="eu.dnetlib.common.services.locators.comparators.PreferLocalRunningInstanceComparator" /> |
|
17 |
|
|
18 |
<alias name="${default.service.comparator}" alias="defaultServiceComparator" /> |
|
19 |
|
|
20 |
<bean id="blackboardDispatche" class="eu.dnetlib.common.blackboard.BlackboardDispatcher" /> |
|
21 |
|
|
22 |
</beans> |
modules/dnet-components/trunk/.springBeans | ||
---|---|---|
7 | 7 |
</configSuffixes> |
8 | 8 |
<enableImports><![CDATA[false]]></enableImports> |
9 | 9 |
<configs> |
10 |
<config>src/main/resources/eu/dnetlib/common/services/locators/applicationContext-locators.xml</config>
|
|
10 |
<config>src/main/resources/eu/dnetlib/common/applicationContext-common.xml</config>
|
|
11 | 11 |
</configs> |
12 | 12 |
<autoconfigs> |
13 | 13 |
</autoconfigs> |
modules/dnet-core-services/trunk/src/main/java/eu/dnetlib/enabling/test/TestServiceImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.test; |
|
2 |
|
|
3 |
import eu.dnetlib.common.services.AbstractBaseService; |
|
4 |
import eu.dnetlib.rmi.soap.TestService; |
|
5 |
|
|
6 |
public class TestServiceImpl extends AbstractBaseService implements TestService { |
|
7 |
|
|
8 |
} |
modules/dnet-core-services/trunk/src/main/java/eu/dnetlib/enabling/test/TestController.java | ||
---|---|---|
1 |
package eu.dnetlib.enabling.test; |
|
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import org.springframework.stereotype.Controller; |
|
6 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
7 |
import org.springframework.web.bind.annotation.RequestParam; |
|
8 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
9 |
|
|
10 |
import eu.dnetlib.common.blackboard.BlackboardDispatcher; |
|
11 |
import eu.dnetlib.rmi.blackboard.SumMessage; |
|
12 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
|
13 |
|
|
14 |
@Controller |
|
15 |
public class TestController { |
|
16 |
|
|
17 |
@Resource |
|
18 |
private BlackboardDispatcher blackboardDispatcher; |
|
19 |
|
|
20 |
@RequestMapping("/sum") |
|
21 |
public @ResponseBody |
|
22 |
String sum(@RequestParam(value = "x", required = true) final int x, @RequestParam(value = "y", required = true) final int y) |
|
23 |
throws InformationServiceException { |
|
24 |
blackboardDispatcher.createDispatcher(new SumMessage(x, y), null, null, null); |
|
25 |
|
|
26 |
return String.format("%d + %d = %d", x, y, x + y); |
|
27 |
} |
|
28 |
} |
modules/dnet-core-services/trunk/src/main/java/eu/dnetlib/enabling/node/NodeManagerServiceImpl.java | ||
---|---|---|
11 | 11 |
public String echo(final String message) { |
12 | 12 |
return Joiner.on(", ").join(message, message, message); |
13 | 13 |
} |
14 |
|
|
14 | 15 |
} |
modules/dnet-core-services/trunk/src/main/resources/eu/dnetlib/enabling/test/applicationContext-test-service.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" |
|
4 |
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing" |
|
5 |
xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration" |
|
6 |
xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template" |
|
7 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
8 |
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd |
|
9 |
http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd |
|
10 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd |
|
11 |
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd |
|
12 |
http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"> |
|
13 |
|
|
14 |
<!-- beans --> |
|
15 |
<bean id="testService" |
|
16 |
class="eu.dnetlib.enabling.test.TestServiceImpl" /> |
|
17 |
|
|
18 |
<!-- endpoints --> |
|
19 |
<jaxws:endpoint id="testServiceEndpoint" implementor="#testService" |
|
20 |
implementorClass="eu.dnetlib.rmi.soap.TestService" |
|
21 |
address="/test" /> |
|
22 |
|
|
23 |
|
|
24 |
<bean id="testServiceRegistrator" |
|
25 |
class="eu.dnetlib.common.services.DnetServiceRegistrator" |
|
26 |
p:service-ref="testService"> |
|
27 |
<property name="protocols"> |
|
28 |
<map> |
|
29 |
<entry key="SOAP" value="http://${container.hostname}:${container.port}/${container.context}/services/test"/> |
|
30 |
</map> |
|
31 |
</property> |
|
32 |
</bean> |
|
33 |
|
|
34 |
</beans> |
Also available in: Unified diff
add blackboard message