Author: knguyen
Date: Mon Jun 4 15:32:36 2007
New Revision: 17454
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17454&repname=
=3Djahia
Log:
ordering of aggregate events is necessary.
Modified:
trunk/core/src/java/org/jahia/services/events/JahiaEventGeneratorBaseSe=
rvice.java
trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-services.xml
Modified: trunk/core/src/java/org/jahia/services/events/JahiaEventGenerator=
BaseService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/java/o=
rg/jahia/services/events/JahiaEventGeneratorBaseService.java&rev=3D17454&re=
pname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/java/org/jahia/services/events/JahiaEventGeneratorBaseSe=
rvice.java (original)
+++ trunk/core/src/java/org/jahia/services/events/JahiaEventGeneratorBaseSe=
rvice.java Mon Jun 4 15:32:36 2007
@@ -48,6 +48,9 @@
=
private ThreadLocal tlevents =3D new ThreadLocal();
=
+ private Map aggregatedEventWeigth =3D new HashMap();
+ private static final int AGGREGATED_EVENT_DEFAULT_WEIGHT =3D 1;
+
/**
* constructor
*/
@@ -89,20 +92,24 @@
for (; !events.isEmpty(); ) {
logger.debug("Fire aggregate for events : "+events);
Map aggregateEvents =3D new HashMap();
+ AggregatedEvents aggEvent =3D null;
for (; !events.isEmpty(); ) {
MethodWithEvent methodWithEvent =3D (MethodWithEvent) =
events.remove(0);
- List alls =3D (List) aggregateEvents.get(methodWithEve=
nt.name);
- if (alls =3D=3D null) {
- alls =3D new ArrayList();
- aggregateEvents.put(methodWithEvent.name, alls);
+ aggEvent =3D (AggregatedEvents)aggregateEvents.get(met=
hodWithEvent.name);
+ if ( aggEvent =3D=3D null ){
+ aggEvent =3D new AggregatedEvents(methodWithEvent.=
name);
+ aggregateEvents.put(methodWithEvent.name,aggEvent);
}
- alls.add(methodWithEvent.event);
+ aggEvent.getEvents().add(methodWithEvent.event);
}
- for (Iterator iterator =3D aggregateEvents.keySet().iterat=
or(); iterator.hasNext();) {
- String name =3D (String) iterator.next();
+ SortedSet orderedEvents =3D new TreeSet();
+ orderedEvents.addAll(aggregateEvents.values());
+ for (Iterator iterator =3D orderedEvents.iterator(); itera=
tor.hasNext();) {
+ aggEvent =3D (AggregatedEvents) iterator.next();
try {
- JahiaEvent event =3D new JahiaEvent(this,null,aggr=
egateEvents.get(name));
- JahiaListenersRegistry.getInstance ().wakeupListen=
ers ("aggregated"+StringUtils.capitalize(name),event);
+ JahiaEvent event =3D new JahiaEvent(this,null,aggE=
vent.getEvents());
+ JahiaListenersRegistry.getInstance ().wakeupListen=
ers ("aggregated"
+ +StringUtils.capitalize(aggEvent.getName()=
),event);
} catch (JahiaException e) {
e.printStackTrace();
}
@@ -442,6 +449,14 @@
JahiaListenersRegistry.getInstance ().wakeupListeners ("templateDe=
leted", theEvent);
}
=
+ public Map getAggregatedEventWeigth() {
+ return aggregatedEventWeigth;
+ }
+
+ public void setaggregatedEventWeigth(Map aggregatedEventWeigth) {
+ this.aggregatedEventWeigth =3D aggregatedEventWeigth;
+ }
+
// Nicol=C3=A1s Charczewski - Neoris Argentina - added 28/03/2006 - end
// =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=
@@ -482,4 +497,57 @@
}
}
=
+ class AggregatedEvents implements Comparable {
+
+ String name;
+ List events;
+ int weight =3D AGGREGATED_EVENT_DEFAULT_WEIGHT;
+
+ public AggregatedEvents(String aName) {
+ this.name =3D aName;
+ Object weightVal =3D getAggregatedEventWeigth().get(aName);
+ if ( weightVal !=3D null ){
+ try {
+ weight =3D Integer.parseInt(weightVal.toString());
+ } catch (Throwable t){
+ }
+ }
+ this.events =3D new ArrayList();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name =3D name;
+ }
+
+ public List getEvents() {
+ return events;
+ }
+
+ public void setEvents(List events) {
+ this.events =3D events;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight =3D weight;
+ }
+
+ public int compareTo(Object o){
+ AggregatedEvents obj =3D (AggregatedEvents) o;
+ if ( obj.getWeight()>this.weight ){
+ return 1;
+ } else if ( this.weight=3D=3Dobj.getWeight() ){
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+ }
}
Modified: trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-servi=
ces.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/core/src/webapp=
/WEB-INF/etc/spring/applicationcontext-services.xml&rev=3D17454&repname=3Dj=
ahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-services.xm=
l (original)
+++ trunk/core/src/webapp/WEB-INF/etc/spring/applicationcontext-services.xm=
l Mon Jun 4 15:32:36 2007
@@ -647,6 +647,13 @@
<bean id=3D"JahiaEventService" parent=3D"proxyTemplate">
<property name=3D"target">
<bean class=3D"org.jahia.services.events.JahiaEventGeneratorBa=
seService" parent=3D"jahiaServiceTemplate" factory-method=3D"getInstance">
+ <property name=3D"aggregatedEventWeigth">
+ <map>
+ <entry key=3D"contentObjectCreated">
+ <value>2</value><!-- As default is 1, contentO=
bjectCreated event will always be fired before all event of weight 1. -->
+ </entry>
+ </map>
+ </property>
</bean>
</property>
</bean>
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list