Revision: 22771
Author: [email protected]
Date: Mon Jul 23 04:49:44 2012
Log: Fixes Issue 3239
http://code.google.com/p/mobicents/source/detail?r=22771
Modified:
/trunk/servers/jain-slee/core/server-all-beans/src/main/resources/META-INF/jboss-beans.xml
/trunk/servers/jain-slee/core/server-default-beans/src/main/resources/META-INF/jboss-beans.xml
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/container/management/jmx/TimerFacilityConfiguration.java
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/container/management/jmx/TimerFacilityConfigurationMBean.java
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/runtime/facilities/TimerFacilityImpl.java
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/runtime/facilities/TimerFacilityTimerTask.java
=======================================
---
/trunk/servers/jain-slee/core/server-all-beans/src/main/resources/META-INF/jboss-beans.xml
Fri Apr 20 09:19:36 2012
+++
/trunk/servers/jain-slee/core/server-all-beans/src/main/resources/META-INF/jboss-beans.xml
Mon Jul 23 04:49:44 2012
@@ -137,7 +137,8 @@
class="org.mobicents.slee.container.management.jmx.TimerFacilityConfiguration">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="org.mobicents.slee:name=TimerFacilityConfiguration",exposedInterface=org.mobicents.slee.container.management.jmx.TimerFacilityConfigurationMBean.class,registerDirectly=true)</annotation>
<property name="timerThreads">4</property>
- <property name="purgePeriod">0</property>
+ <property name="purgePeriod">0</property>
+ <property
name="taskExecutionWaitsForTxCommitConfirmation">true</property>
</bean>
<bean name="Mobicents.JAINSLEE.TimerFacility"
=======================================
---
/trunk/servers/jain-slee/core/server-default-beans/src/main/resources/META-INF/jboss-beans.xml
Fri Apr 20 09:19:36 2012
+++
/trunk/servers/jain-slee/core/server-default-beans/src/main/resources/META-INF/jboss-beans.xml
Mon Jul 23 04:49:44 2012
@@ -143,6 +143,7 @@
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="org.mobicents.slee:name=TimerFacilityConfiguration",exposedInterface=org.mobicents.slee.container.management.jmx.TimerFacilityConfigurationMBean.class,registerDirectly=true)</annotation>
<property name="timerThreads">4</property>
<property name="purgePeriod">0</property>
+ <property
name="taskExecutionWaitsForTxCommitConfirmation">true</property>
</bean>
<bean name="Mobicents.JAINSLEE.TimerFacility"
=======================================
---
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/container/management/jmx/TimerFacilityConfiguration.java
Tue Dec 27 09:13:12 2011
+++
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/container/management/jmx/TimerFacilityConfiguration.java
Mon Jul 23 04:49:44 2012
@@ -40,6 +40,18 @@
private Integer timerThreads;
private Integer purgePeriod;
+
+ private boolean taskExecutionWaitsForTxCommitConfirmation = true;
+
+ @Override
+ public boolean getTaskExecutionWaitsForTxCommitConfirmation() {
+ return taskExecutionWaitsForTxCommitConfirmation;
+ }
+
+ @Override
+ public void setTaskExecutionWaitsForTxCommitConfirmation(boolean value)
{
+ taskExecutionWaitsForTxCommitConfirmation = value;
+ }
/*
* (non-Javadoc)
=======================================
---
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/container/management/jmx/TimerFacilityConfigurationMBean.java
Tue Dec 27 09:13:12 2011
+++
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/container/management/jmx/TimerFacilityConfigurationMBean.java
Mon Jul 23 04:49:44 2012
@@ -59,4 +59,23 @@
*/
public void setPurgePeriod(int value);
-}
+ /**
+ * Indicates if the timer task should wait for confirmation that the tx,
+ * which set the timer, finished commit. This confirmation is the only
+ * guarantee that short timers (such as the ones with 0 delay), set on
new
+ * tx aware activities, will not execute before all state (such as the
actual AC), is committed.
+ *
+ * @return
+ */
+ public boolean getTaskExecutionWaitsForTxCommitConfirmation();
+
+ /**
+ * Defines if the timer task should wait for confirmation that the tx,
+ * which set the timer, finished commit. This confirmation is the only
+ * guarantee that short timers (such as the ones with 0 delay), set on
new
+ * tx aware activities, will not execute before all state (such as the
actual AC), is committed.
+ * @param value
+ */
+ public void setTaskExecutionWaitsForTxCommitConfirmation(boolean value);
+
+}
=======================================
---
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/runtime/facilities/TimerFacilityImpl.java
Tue Dec 27 09:13:12 2011
+++
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/runtime/facilities/TimerFacilityImpl.java
Mon Jul 23 04:49:44 2012
@@ -22,6 +22,8 @@
package org.mobicents.slee.runtime.facilities;
+import java.util.concurrent.CountDownLatch;
+
import javax.slee.ActivityContextInterface;
import javax.slee.Address;
import javax.slee.TransactionRequiredLocalException;
@@ -36,6 +38,8 @@
import org.mobicents.slee.container.facilities.TimerFacility;
import
org.mobicents.slee.container.management.jmx.TimerFacilityConfiguration;
import org.mobicents.slee.container.transaction.SleeTransactionManager;
+import org.mobicents.slee.container.transaction.TransactionContext;
+import org.mobicents.slee.container.transaction.TransactionalAction;
import org.mobicents.slee.container.util.JndiRegistrationManager;
import org.mobicents.timers.FaultTolerantScheduler;
@@ -164,7 +168,21 @@
// schedule timer task
TimerFacilityTimerTaskData taskData = new
TimerFacilityTimerTaskData(timerID,
aciImpl.getActivityContext().getActivityContextHandle(), address,
startTime, period, numRepetitions, timerOptions);
- scheduler.schedule(new TimerFacilityTimerTask(taskData));
+ final TimerFacilityTimerTask task = new
TimerFacilityTimerTask(taskData);
+ if(configuration.getTaskExecutionWaitsForTxCommitConfirmation()) {
+ final CountDownLatch countDownLatch = new CountDownLatch(1);
+ task.setCountDownLatch(countDownLatch);
+ TransactionalAction action = new TransactionalAction() {
+ @Override
+ public void execute() {
+ countDownLatch.countDown();
+ }
+ };
+ TransactionContext txContext = txMgr.getTransactionContext();
+ txContext.getAfterCommitActions().add(action);
+ txContext.getAfterRollbackActions().add(action);
+ }
+ scheduler.schedule(task);
// If we started a tx for this operation, we commit it now
if (startedTx) {
=======================================
---
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/runtime/facilities/TimerFacilityTimerTask.java
Tue Apr 19 07:36:27 2011
+++
/trunk/servers/jain-slee/core/timers/src/main/java/org/mobicents/slee/runtime/facilities/TimerFacilityTimerTask.java
Mon Jul 23 04:49:44 2012
@@ -22,6 +22,8 @@
package org.mobicents.slee.runtime.facilities;
+import java.util.concurrent.CountDownLatch;
+
import javax.slee.facilities.TimerOptions;
import javax.slee.facilities.TimerPreserveMissed;
@@ -42,6 +44,8 @@
private final static SleeContainer sleeContainer = SleeContainer
.lookupFromJndi();
+ private CountDownLatch countDownLatch = null;
+
public TimerFacilityTimerTask(TimerFacilityTimerTaskData data) {
super(data);
this.data = data;
@@ -52,22 +56,33 @@
return data;
}
+ public void setCountDownLatch(CountDownLatch countDownLatch) {
+ this.countDownLatch = countDownLatch;
+ }
+
public void runTask() {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing task with timer ID "
- + getData().getTaskID());
- }
-
- try {
- runInternal();
- } catch (Throwable t) {
- logger.error(t.getMessage(), t);
- }
+ if(countDownLatch != null) {
+ try {
+ countDownLatch.await();
+ } catch (InterruptedException e) {
+ logger.error("failed to wait on tx commit
confirmation", e);
+ }
+ }
+ runInternal();
+
}
private void runInternal() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing task with timer ID "
+ + getData().getTaskID());
+ }
+
+ try {
+
+
int remainingRepetitions = data.getRemainingRepetitions();
// till the actual task cancellation (in the scheduler) a
periodic timer
@@ -195,9 +210,8 @@
final ActivityContext ac =
acFactory.getActivityContext(data
.getActivityContextHandle());
- // the AC can be null in the edge case when the
activity was
- // removed while the basic timer is firing an
event
- // and thus the timer cancelation came a bit
late
+ // the AC can be null if the activity is
+ // removed concurrently with the task execution
if (ac == null) {
logger.warn("Cannot fire timer event with id
"
+ data.getTaskID()
@@ -230,6 +244,10 @@
}
}
}
+
+ } catch (Throwable t) {
+ logger.error(t.getMessage(), t);
+ }
}
@@ -247,7 +265,6 @@
@SuppressWarnings("deprecation")
@Override
public void beforeRecover() {
-
long period = data.getPeriod();
long startTime = data.getStartTime();
long now = System.currentTimeMillis();