Project

General

Profile

« Previous | Next » 

Revision 47777

[maven-release-plugin] copy for tag cnr-notifications-common-2.1.1

View differences:

modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/cnr-notifications-common.iml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
4
    <output url="file://$MODULE_DIR$/target/classes" />
5
    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
    <content url="file://$MODULE_DIR$">
7
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9
      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10
      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
11
      <excludeFolder url="file://$MODULE_DIR$/target" />
12
    </content>
13
    <orderEntry type="inheritedJdk" />
14
    <orderEntry type="sourceFolder" forTests="false" />
15
    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-service-common:2.1.6-SNAPSHOT" level="project" />
16
    <orderEntry type="library" name="Maven: org.antlr:stringtemplate:3.2" level="project" />
17
    <orderEntry type="library" name="Maven: org.antlr:antlr:2.7.7" level="project" />
18
    <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.2.5.RELEASE" level="project" />
19
    <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.5.RELEASE" level="project" />
20
    <orderEntry type="module" module-name="cnr-misc-utils" />
21
    <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
22
    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.8" level="project" />
23
    <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
24
    <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
25
    <orderEntry type="library" name="Maven: jaxen:jaxen:1.1.6" level="project" />
26
    <orderEntry type="library" name="Maven: saxonica:saxon:9.1.0.8" level="project" />
27
    <orderEntry type="library" name="Maven: saxonica:saxon-dom:9.1.0.8" level="project" />
28
    <orderEntry type="library" name="Maven: jgrapht:jgrapht:0.7.2" level="project" />
29
    <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache:2.8.0" level="project" />
30
    <orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
31
    <orderEntry type="library" name="Maven: org.springframework:spring-test:4.2.5.RELEASE" level="project" />
32
    <orderEntry type="module" module-name="cnr-service-utils" />
33
    <orderEntry type="library" name="Maven: apache:oro:2.0.8" level="project" />
34
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-jaxws:3.1.5" level="project" />
35
    <orderEntry type="library" name="Maven: xml-resolver:xml-resolver:1.2" level="project" />
36
    <orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.4" level="project" />
37
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-core:3.1.5" level="project" />
38
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-soap:3.1.5" level="project" />
39
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-wsdl:3.1.5" level="project" />
40
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-databinding-jaxb:3.1.5" level="project" />
41
    <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.2.11" level="project" />
42
    <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.2.11" level="project" />
43
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-xml:3.1.5" level="project" />
44
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-simple:3.1.5" level="project" />
45
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-addr:3.1.5" level="project" />
46
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-policy:3.1.5" level="project" />
47
    <orderEntry type="library" name="Maven: org.apache.neethi:neethi:3.0.3" level="project" />
48
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-api:2.7.8" level="project" />
49
    <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.2.0" level="project" />
50
    <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.1" level="project" />
51
    <orderEntry type="library" name="Maven: org.apache.ws.xmlschema:xmlschema-core:2.0.3" level="project" />
52
    <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.7.1" level="project" />
53
    <orderEntry type="library" name="Maven: wsdl4j:wsdl4j:1.6.3" level="project" />
54
    <orderEntry type="module" module-name="cnr-spring-utils" />
55
    <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
56
    <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.5.RELEASE" level="project" />
57
    <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
58
    <orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.5.RELEASE" level="project" />
59
    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.2.5.RELEASE" level="project" />
60
    <orderEntry type="library" name="Maven: jparsec:jparsec:2.0" level="project" />
61
    <orderEntry type="library" name="Maven: runcc:runcc:0.7" level="project" />
62
    <orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.2.5.RELEASE" level="project" />
63
    <orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.5.RELEASE" level="project" />
64
    <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" />
65
    <orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.5.RELEASE" level="project" />
66
    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
67
    <orderEntry type="library" name="Maven: org.quartz-scheduler:quartz:2.2.2" level="project" />
68
    <orderEntry type="library" name="Maven: c3p0:c3p0:0.9.1.1" level="project" />
69
    <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
70
    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
71
  </component>
72
</module>
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-notifications-common/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "cnr-notifications-common"}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/actions/SubscriptionAction.java
1
package eu.dnetlib.enabling.actions;
2

  
3
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
4

  
5
/**
6
 * Manager subscription action.
7
 *
8
 * @author marko
9
 *
10
 */
11
public interface SubscriptionAction extends NotificationHandler {
12
	/**
13
	 * topic expression associated with this subscription action.
14
	 *
15
	 * @return SN topic expression
16
	 */
17
	String getTopicExpression();
18

  
19
	/**
20
	 * react on this topic prefix. Might be shorter than the topic expression.
21
	 *
22
	 * @return SN topic prefix
23
	 */
24
	String getTopicPrefix();
25
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/actions/AbstractSubscriptionAction.java
1
package eu.dnetlib.enabling.actions;
2

  
3
import javax.annotation.PostConstruct;
4

  
5
import org.springframework.beans.factory.annotation.Required;
6

  
7
import eu.dnetlib.enabling.actions.SubscriptionAction;
8
import eu.dnetlib.enabling.tools.Enableable;
9

  
10
/**
11
 * Common subscription action.
12
 *
13
 * @author marko
14
 *
15
 */
16
public abstract class AbstractSubscriptionAction implements SubscriptionAction, Enableable {
17

  
18
	/**
19
	 * topic expression.
20
	 */
21
	private String topicExpression;
22
	
23
	/**
24
	 * topic prefix.
25
	 */
26
	private String topicPrefix;
27

  
28
	/**
29
	 * true if enabled.
30
	 */
31
	private boolean enabled = true;
32

  
33
	/**
34
	 * init the default topic prefix.
35
	 */
36
	@PostConstruct
37
	public void init() {
38
		if (topicPrefix == null)
39
			topicPrefix = getTopicExpression().replace("/", ".");
40
	}
41

  
42
	@Override
43
	public String getTopicExpression() {
44
		return topicExpression;
45
	}
46
	
47
	@Required
48
	public void setTopicExpression(final String topicExpression) {
49
		this.topicExpression = topicExpression;
50
	}
51

  
52
	@Override
53
	public String getTopicPrefix() {
54
		return topicPrefix;
55
	}
56

  
57
	public void setTopicPrefix(final String topicPrefix) {
58
		this.topicPrefix = topicPrefix;
59
	}
60

  
61
	@Override
62
	public boolean isEnabled() {
63
		return enabled;
64
	}
65

  
66
	@Override
67
	public void setEnabled(boolean enabled) {
68
		this.enabled = enabled;
69
	}
70

  
71
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/AbstractSchedulable.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.text.ParseException;
4

  
5
import javax.annotation.PostConstruct;
6
import javax.annotation.Resource;
7

  
8
import org.quartz.*;
9
import org.quartz.Trigger.TriggerState;
10
import org.quartz.impl.JobDetailImpl;
11
import org.quartz.impl.triggers.CronTriggerImpl;
12
import org.springframework.beans.factory.BeanNameAware;
13
import org.springframework.beans.factory.annotation.Required;
14

  
15
/**
16
 * Common implementation for schedulable beans.
17
 * 
18
 * @author claudio
19
 * 
20
 */
21
public abstract class AbstractSchedulable implements Schedulable, Job, BeanNameAware {
22

  
23
	private static final String THIS = "this";
24

  
25
	private final static String GROUP = "schedulableJobs";
26

  
27
	private boolean enabled;
28

  
29
	private CronExpression cronExpression;
30

  
31
	private String beanName;
32

  
33
	@Resource(name = "dnetJobScheduler")
34
	private Scheduler jobScheduler;
35

  
36
	@PostConstruct
37
	protected void init() {
38
		try {
39

  
40
			JobDataMap jobDataMap = new JobDataMap();
41
			jobDataMap.put(THIS, this);
42

  
43
			JobDetailImpl jd = new JobDetailImpl();
44
			jd.setName(getBeanName());
45
			jd.setGroup(GROUP);
46
			jd.setJobDataMap(jobDataMap);
47
			jd.setJobClass(this.getClass());
48

  
49
			jobScheduler.scheduleJob(jd, createTrigger());
50

  
51
		} catch (SchedulerException e) {
52
			throw new RuntimeException(e);
53
		}
54
	}
55

  
56
	private Trigger createTrigger() {
57
		try {
58
			CronTriggerImpl trigger = new CronTriggerImpl(getBeanName(), GROUP, getCronExpression());
59
			trigger.setMisfireInstruction(Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY);
60
			trigger.setJobGroup(GROUP);
61
			trigger.setJobName(getBeanName());
62
			return trigger;
63
		} catch (ParseException e) {
64
			throw new IllegalArgumentException("invalid cron expression: " + cronExpression, e);
65
		}
66
	}
67

  
68
	protected abstract void doExecute();
69

  
70
	@Override
71
	public void execute() {
72
		// bean represents the quartz instance of this object
73
		if (isEnabled()) {
74
			doExecute();
75
		}
76
	}
77

  
78
	@Override
79
	public void execute(JobExecutionContext context) throws JobExecutionException {
80
		AbstractSchedulable bean = (AbstractSchedulable) context.getJobDetail().getJobDataMap().get(THIS);
81

  
82
		// bean represents the quartz instance of this object
83
		if (bean.isEnabled()) {
84
			bean.doExecute();
85
		}
86
	}
87

  
88
	@Override
89
	public boolean isEnabled() {
90
		return enabled;
91
	}
92

  
93
	@Override
94
	public void setEnabled(boolean enabled) {
95
		this.enabled = enabled;
96
	}
97

  
98
	@Override
99
	public String getCronExpression() {
100
		return cronExpression.getCronExpression();
101
	}
102

  
103
	@Required
104
	public void setCronExpression(String cronExpression) {
105
		try {
106
			this.cronExpression = new CronExpression(cronExpression);
107
		} catch (ParseException e) {
108
			throw new IllegalArgumentException("invalid cron expression: " + cronExpression, e);
109
		}
110
	}
111

  
112
	@Override
113
	public void updateCronExpression(String cronExpression) {
114

  
115
		if (!cronExpression.equals(getCronExpression())) {
116
			setCronExpression(cronExpression);
117
			try {
118
				final TriggerKey tk = new TriggerKey(getBeanName());
119
				jobScheduler.rescheduleJob(tk, createTrigger());
120
			} catch (SchedulerException e) {
121
				throw new RuntimeException("unable to reschedule trigger", e);
122
			}
123
		}
124
	}
125

  
126
	@Override
127
	public String getNextFireTime() {
128
		try {
129
			if (isPaused()) {
130
				return "";
131
			}
132
			if (!isEnabled()) {
133
				return "";
134
			}
135
			final TriggerKey tk = new TriggerKey(getBeanName());
136
			final Trigger t = jobScheduler.getTrigger(tk);
137
			return t != null ? t.getNextFireTime().toString() : "";
138
		} catch (SchedulerException e) {
139
			throw new RuntimeException("unable to get trigger", e);
140
		}
141
	}
142

  
143
	@Override
144
	public boolean isPaused() {
145
		try {
146
			final TriggerKey tk = new TriggerKey(getBeanName());
147
			final TriggerState state = jobScheduler.getTriggerState(tk);
148
			switch (state) {
149
			case PAUSED:
150
			case NONE:
151
			case ERROR:
152
				return true;
153
			default:
154
				return false;
155
			}
156
		} catch (SchedulerException e) {
157
			throw new RuntimeException("unable to get trigger", e);
158
		}
159
	}
160

  
161
	@Override
162
	public void pause() {
163
		try {
164
			final TriggerKey tk = new TriggerKey(getBeanName());
165
			jobScheduler.pauseTrigger(tk);
166
		} catch (SchedulerException e) {
167
			throw new RuntimeException("unable to pause trigger", e);
168
		}
169
	}
170

  
171
	@Override
172
	public void resume() {
173
		try {
174
			final TriggerKey tk = new TriggerKey(getBeanName());
175
			jobScheduler.resumeTrigger(tk);
176
		} catch (SchedulerException e) {
177
			throw new RuntimeException("unable to resume trigger", e);
178
		}
179
	}
180

  
181
	public String getBeanName() {
182
		return beanName;
183
	}
184

  
185
	@Override
186
	@Required
187
	public void setBeanName(String beanName) {
188
		this.beanName = beanName;
189
	}
190

  
191
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/SchedulableProfileUpdater.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import javax.annotation.Resource;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.springframework.beans.factory.annotation.Required;
8

  
9
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
10
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
11
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
12

  
13
/**
14
 * Schedulable implementation of an xUpdate.
15
 * 
16
 * @author claudio
17
 * 
18
 */
19
public class SchedulableProfileUpdater extends AbstractSchedulable {
20

  
21
	private static final Log log = LogFactory.getLog(SchedulableProfileUpdater.class); // NOPMD by marko on 11/24/08 5:02 PM
22

  
23
	private String xUpdate;
24

  
25
	@Resource
26
	private UniqueServiceLocator serviceLocator;
27

  
28
	@Override
29
	protected void doExecute() {
30
		try {
31
			log.info("triggering scheduled reindex: " + getxUpdate());
32
			serviceLocator.getService(ISRegistryService.class).executeXUpdate(getxUpdate());
33
		} catch (ISRegistryException e) {
34

  
35
			throw new RuntimeException(e);
36
		}
37
	}
38

  
39
	public String getxUpdate() {
40
		return xUpdate;
41
	}
42

  
43
	@Required
44
	public void setxUpdate(String xUpdate) {
45
		this.xUpdate = xUpdate;
46
	}
47

  
48
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/blackboard/NotificationInfo.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import eu.dnetlib.miscutils.datetime.DateUtils;
4

  
5
public class NotificationInfo {
6
	private String name;
7
	private String subscrId;
8
	private String topic;
9
	private String rsId;
10
	private String profile;
11
	private String date;
12
	
13
	public NotificationInfo() {	
14
		this.date = DateUtils.now_ISO8601();
15
	}
16
	
17
	public NotificationInfo(String name, String subscrId, String topic, String rsId, String profile) {
18
		super();
19
		this.name = name;
20
		this.subscrId = subscrId;
21
		this.topic = topic;
22
		this.rsId = rsId;
23
		this.profile = profile;
24
		this.date = DateUtils.now_ISO8601();
25
	}
26

  
27
	public String getName() {
28
		return name;
29
	}
30

  
31
	public void setName(String name) {
32
		this.name = name;
33
	}
34

  
35
	public String getSubscrId() {
36
		return subscrId;
37
	}
38

  
39
	public void setSubscrId(String subscrId) {
40
		this.subscrId = subscrId;
41
	}
42

  
43
	public String getTopic() {
44
		return topic;
45
	}
46

  
47
	public void setTopic(String topic) {
48
		this.topic = topic;
49
	}
50

  
51
	public String getRsId() {
52
		return rsId;
53
	}
54

  
55
	public void setRsId(String rsId) {
56
		this.rsId = rsId;
57
	}
58

  
59
	public String getProfile() {
60
		return profile;
61
	}
62

  
63
	public void setProfile(String profile) {
64
		this.profile = profile;
65
	}
66

  
67
	public String getDate() {
68
		return date;
69
	}
70

  
71
	public void setDate(String date) {
72
		this.date = date;
73
	}
74
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/blackboard/NotificationHandler.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3

  
4
/**
5
 * Each service may have a chain of NotificationHandlers, which process incoming notifications.
6
 * 
7
 * @author marko
8
 *
9
 */
10
public interface NotificationHandler {
11
	/**
12
	 * Incoming notification received.
13
	 * 
14
	 * @param subscrId subscriptionId
15
	 * @param topic topic
16
	 * @param rsId resource id
17
	 * @param profile resource profile
18
	 */
19
	void notified(String subscrId, final String topic, final String rsId, final String profile);
20
	
21
	
22
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/blackboard/NotificationHandlerChain.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
/**
4
 * Invokes a chain of notification handlers for each incoming notification. Normally an instance of this class is
5
 * registered as the notification handler for a given service.
6
 * 
7
 * @author marko
8
 * 
9
 */
10
public interface NotificationHandlerChain extends NotificationHandler {
11

  
12
	public void delegateNotification(final String subscrId, final String topic, final String rsId, final String profile, final NotificationHandler handler);
13

  
14
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/blackboard/NotificationHistory.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import java.util.Map;
4

  
5
public interface NotificationHistory {
6

  
7
	/**
8
	 * Return a saved notification associated to a bean and to a rsId.
9
	 * 
10
	 * @param name
11
	 * @return
12
	 */
13
	public NotificationInfo obtainNotification(String bean, String rsId);
14
	
15
	/**
16
	 * Save a notification.
17
	 * 
18
	 * @param info
19
	 */
20
	void saveNotification(NotificationInfo info);
21

  
22
	
23
	/**
24
	 * Return all saved notifications.
25
	 * 
26
	 * @return
27
	 */
28
	Map<String, Map<String, NotificationInfo>> obtainAllNotifications();
29
	
30
	/**
31
	 * Remove a saved notifications.
32
	 * 
33
	 * @return
34
	 */
35
	public void clearNotification(String bean, String rsId);
36
	
37
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/blackboard/NotificationHandlerChainImpl.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import java.util.Collection;
4
import java.util.Map;
5

  
6
import javax.annotation.Resource;
7

  
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.springframework.beans.factory.annotation.Required;
11
import org.springframework.core.task.TaskExecutor;
12

  
13
import eu.dnetlib.enabling.actions.AbstractSubscriptionAction;
14
import eu.dnetlib.enabling.tools.Enableable;
15
import eu.dnetlib.enabling.tools.EnableableEnumerator;
16

  
17
public class NotificationHandlerChainImpl implements NotificationHandlerChain {
18
	
19
	/**
20
	 * logger.
21
	 */
22
	private static final Log log = LogFactory.getLog(NotificationHandlerChain.class); // NOPMD by marko on 11/24/08 5:02 PM
23

  
24
	/**
25
	 * notification handler chain.
26
	 */
27
	private Collection<NotificationHandler> handlers;
28

  
29
	/**
30
	 * task executor used for invoking the handlers.
31
	 */
32
	private TaskExecutor handlerExecutor;
33

  
34
	@Resource
35
	private NotificationHistory notificationHistory;
36

  
37
	@Resource
38
	private EnableableEnumerator enableableEnumerator;
39

  
40
	/**
41
	 * {@inheritDoc}
42
	 * 
43
	 * @see eu.dnetlib.enabling.tools.blackboard.NotificationHandler#notified(java.lang.String, java.lang.String,
44
	 *      java.lang.String, java.lang.String)
45
	 */
46
	@Override
47
	public void notified(final String subscrId, final String topic, final String rsId, final String profile) {
48

  
49
		for (final NotificationHandler handler : handlers) {
50

  
51
			try {
52
				if (handler instanceof AbstractSubscriptionAction)
53
					if (topic.startsWith(((AbstractSubscriptionAction) handler).getTopicPrefix()))
54
						if (!((Enableable) handler).isEnabled()) {
55
							for (Map.Entry<String, Enableable> entry : enableableEnumerator.getAllEnableables().entrySet()) {
56
								if (entry.getValue() == handler) {
57
									NotificationInfo info = new NotificationInfo();
58
									info.setName(entry.getKey());
59
									info.setProfile(profile);
60
									info.setRsId(rsId);
61
									info.setSubscrId(subscrId);
62
									info.setTopic(topic);
63
									notificationHistory.saveNotification(info);
64
								}
65
							}
66
							continue;
67
						}
68
					
69
				delegateNotification(subscrId, topic, rsId, profile, handler);
70
			} catch (final RuntimeException e) {
71
				log.fatal("error processing notification handler " + handler, e);
72
			}
73
		}
74
	}
75

  
76
	@Override
77
	public void delegateNotification(final String subscrId, final String topic, final String rsId, final String profile, final NotificationHandler handler) {
78

  
79
		handlerExecutor.execute(new Runnable() {
80
			@Override
81
			public void run() {
82
				handler.notified(subscrId, topic, rsId, profile);
83
			}
84
		});
85
	}
86

  
87
	public Collection<NotificationHandler> getHandlers() {
88
		return handlers;
89
	}
90

  
91
	@Required
92
	public void setHandlers(final Collection<NotificationHandler> handlers) {
93
		this.handlers = handlers;
94
	}
95

  
96
	public TaskExecutor getHandlerExecutor() {
97
		return handlerExecutor;
98
	}
99

  
100
	@Required
101
	public void setHandlerExecutor(TaskExecutor handlerExecutor) {
102
		this.handlerExecutor = handlerExecutor;
103
	}
104
}
0 105

  
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/blackboard/NotificationHistoryImpl.java
1
package eu.dnetlib.enabling.tools.blackboard;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6

  
7
public class NotificationHistoryImpl implements NotificationHistory {
8
	
9
	private Map<String, Map<String, NotificationInfo>> notifications = new HashMap<String, Map<String, NotificationInfo>>();
10

  
11
	@Override
12
	public NotificationInfo obtainNotification(String bean, String rsId) {
13
		if (!notifications.containsKey(bean))
14
			return null;
15
		return notifications.get(bean).get(rsId);
16
	}
17
	
18
	@Override
19
	public void saveNotification(NotificationInfo info) {
20
		String bean = info.getName();
21
		String rsId = info.getRsId();
22
		
23
		if (!notifications.containsKey(bean))
24
			notifications.put(bean, new HashMap<String, NotificationInfo>());
25
		
26
		notifications.get(bean).put(rsId, info);
27
	}
28

  
29
	@Override
30
	public Map<String, Map<String, NotificationInfo>> obtainAllNotifications() {
31
		return notifications;
32
	}
33

  
34
	@Override
35
	public void clearNotification(String bean, String rsId) {
36
		if (notifications.containsKey(bean))
37
			notifications.get(bean).remove(rsId);
38
	}
39
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/Enableable.java
1
package eu.dnetlib.enabling.tools;
2

  
3
/**
4
 * Simple interface for classes, which's objects can be enabled or disabled.
5
 * 
6
 * 
7
 * @author marko
8
 * 
9
 */
10
public interface Enableable {
11
	/**
12
	 * True if this object enabled.
13
	 * 
14
	 * @return if this object is currently enabled.
15
	 */
16
	boolean isEnabled();
17

  
18
	/**
19
	 * Enables of disables this object.
20
	 * 
21
	 * @param enabled
22
	 *            enabled
23
	 */
24
	void setEnabled(boolean enabled);
25
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/Schedulable.java
1
package eu.dnetlib.enabling.tools;
2

  
3
/**
4
 * Simple interface for classes, which's objects actions can be scheduled.
5
 * 
6
 * @author claudio
7
 */
8
public interface Schedulable extends Enableable {
9
	/**
10
	 * Updates the cron expression.
11
	 * 
12
	 * @param cronExpression
13
	 */
14
	void updateCronExpression(String cronExpression);
15
	
16
	/**
17
	 * Getter for the cron expression.
18
	 * 
19
	 * @return the String representing the cron expression.
20
	 */
21
	String getCronExpression();
22
	
23
	/**
24
	 * Computes the next time the doExecute method will be invoked.
25
	 * 
26
	 * @return the String representing the next fire time.
27
	 */
28
	String getNextFireTime();
29

  
30
	/**
31
	 * True if the object has been paused.
32
	 * 
33
	 * @return if the bean has been paused.
34
	 */
35
	boolean isPaused();
36
	
37
	/**
38
	 * Prevents the bean for being scheduled for future invocations.
39
	 */
40
	void pause();
41
	
42
	/**
43
	 * Resumes the bean for being scheduled for future invocations.
44
	 */
45
	void resume();
46
	
47
	/**
48
	 * Must be implemented to perform the real action.
49
	 */
50
	void execute();	
51
	
52
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/EnableableEnumerator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.util.Map;
4

  
5
import org.springframework.beans.BeansException;
6
import org.springframework.beans.factory.BeanFactory;
7
import org.springframework.beans.factory.BeanFactoryAware;
8
import org.springframework.beans.factory.ListableBeanFactory;
9
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
10

  
11
/**
12
 * This bean has to live in the same bean factory where all enableables live. Thus it cannot be put inside the EnableablController, which
13
 * lives in the webContext.
14
 * 
15
 * @author marko
16
 * 
17
 */
18
public class EnableableEnumerator implements BeanFactoryAware {
19

  
20
	/**
21
	 * bean factory.
22
	 */
23
	private ListableBeanFactory beanFactory;
24

  
25
	/**
26
	 * Get all beans implementing the Enableable interface.
27
	 * 
28
	 * @return
29
	 */
30
	public Map<String, Enableable> getAllEnableables() {
31
		return beanFactory.getBeansOfType(Enableable.class);
32
	}
33

  
34
	@Override
35
	public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
36
		this.beanFactory = (ListableBeanFactory) beanFactory;
37
	}
38

  
39
	public ListableBeanFactory getBeanFactory() {
40
		return beanFactory;
41
	}
42

  
43
	/**
44
	 * Get given enableable or null.
45
	 * 
46
	 * @param name
47
	 * @return
48
	 */
49
	public Enableable getEnableable(final String name) {
50
		try {
51
			return beanFactory.getBean(name, Enableable.class);
52
		} catch (final NoSuchBeanDefinitionException e) {
53
			return null;
54
		}
55
	}
56

  
57
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/java/eu/dnetlib/enabling/tools/SchedulableEnumerator.java
1
package eu.dnetlib.enabling.tools;
2

  
3
import java.util.Map;
4

  
5
import org.springframework.beans.BeansException;
6
import org.springframework.beans.factory.BeanFactory;
7
import org.springframework.beans.factory.BeanFactoryAware;
8
import org.springframework.beans.factory.ListableBeanFactory;
9
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
10

  
11
/**
12
 * This bean has to live in the same bean factory where all schedulables live. Thus it cannot be put inside the EnableablController, which
13
 * lives in the webContext.
14
 * 
15
 * @author claudio
16
 * 
17
 */
18
public class SchedulableEnumerator implements BeanFactoryAware {
19

  
20
	/**
21
	 * bean factory.
22
	 */
23
	private ListableBeanFactory beanFactory;
24

  
25
	/**
26
	 * Get all beans implementing the Schedulable interface.
27
	 * 
28
	 * @return
29
	 */
30
	public Map<String, Schedulable> getAllSchedulables() {
31
		return beanFactory.getBeansOfType(Schedulable.class);
32
	}
33

  
34
	@Override
35
	public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
36
		this.beanFactory = (ListableBeanFactory) beanFactory;
37
	}
38

  
39
	public ListableBeanFactory getBeanFactory() {
40
		return beanFactory;
41
	}
42

  
43
	/**
44
	 * Get given schedulable or null.
45
	 * 
46
	 * @param name
47
	 * @return
48
	 */
49
	public Schedulable getSchedulable(final String name) {
50
		try {
51
			return beanFactory.getBean(name, Schedulable.class);
52
		} catch (final NoSuchBeanDefinitionException e) {
53
			return null;
54
		}
55
	}
56

  
57
}
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/resources/eu/dnetlib/enabling/tools/applicationContext-enableable.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"
4
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
5

  
6
	<bean id="enableableEnumerator"
7
		class="eu.dnetlib.enabling.tools.EnableableEnumerator" />
8
		
9
	<bean id="notificationHistory"
10
		class="eu.dnetlib.enabling.tools.blackboard.NotificationHistoryImpl" />
11

  
12
</beans>
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/src/main/resources/eu/dnetlib/enabling/tools/applicationContext-schedulable.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
	xmlns:util="http://www.springframework.org/schema/util"
8
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
9
						http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
10
						http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
11
						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
12
						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
13
						http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd
14
						http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
15

  
16
	<bean id="dnetJobScheduler"
17
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
18
		destroy-method="destroy">
19
		<property name="jobFactory">
20
			<bean id="jobSchedulerFactory"
21
				class="org.springframework.scheduling.quartz.SpringBeanJobFactory" />
22
		</property>
23
	</bean>
24

  
25
	<bean id="schedulableEnumerator"
26
		class="eu.dnetlib.enabling.tools.SchedulableEnumerator" />
27

  
28
</beans>
modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1/pom.xml
1
<?xml version="1.0" ?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet45-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>cnr-notifications-common</artifactId>
12
	<packaging>jar</packaging>
13
	<version>2.1.1</version>
14
	<scm>
15
	  <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-notifications-common/tags/cnr-notifications-common-2.1.1</developerConnection>
16
	</scm>
17
	<dependencies>
18
		<dependency>
19
			<groupId>eu.dnetlib</groupId>
20
			<artifactId>cnr-service-common</artifactId>
21
			<version>[2.1.0,3.0.0)</version>
22
		</dependency>
23
		<dependency>
24
			<groupId>org.springframework</groupId>
25
			<artifactId>spring-context-support</artifactId>
26
			<version>${spring.version}</version>
27
		</dependency>
28
		<dependency>
29
			<groupId>org.quartz-scheduler</groupId>
30
			<artifactId>quartz</artifactId>
31
			<version>${quartz.version}</version>
32
		</dependency>
33
	</dependencies>
34
</project>

Also available in: Unified diff