Revision: 15691
Author: [email protected]
Date: Thu Dec 9 10:49:05 2010
Log: Update Issue 1872
Fixing recovery of rescheduling the timers locally
http://code.google.com/p/mobicents/source/detail?r=15691
Modified:
/trunk/servers/cluster/timers/src/main/java/org/mobicents/timers/FaultTolerantScheduler.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipApplicationSession.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantSasTimerService.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantTimerServiceImpl.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/SipApplicationSessionTaskFactory.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/TimerServiceTaskFactory.java
/trunk/servers/sip-servlets/sip-servlets-jboss5-ha-server-cache/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSipApplicationSessionMetadata.java
=======================================
---
/trunk/servers/cluster/timers/src/main/java/org/mobicents/timers/FaultTolerantScheduler.java
Thu Dec 9 08:03:23 2010
+++
/trunk/servers/cluster/timers/src/main/java/org/mobicents/timers/FaultTolerantScheduler.java
Thu Dec 9 10:49:05 2010
@@ -347,13 +347,26 @@
*/
private void recover(TimerTaskData taskData) {
TimerTask task = timerTaskFactory.newTimerTask(taskData);
- if (logger.isDebugEnabled()) {
- logger.debug("Recovering task with id
"+taskData.getTaskID());
- }
- task.beforeRecover();
- // on recovery the task will already be in the cache so we don't check
for it
- // or an IllegalStateException will be thrown
- schedule(task, false);
+ if(task != null) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Recovering task with id
"+taskData.getTaskID());
+ }
+ task.beforeRecover();
+ // on recovery the task will already be in the cache so we don't check
for it
+ // or an IllegalStateException will be thrown
+ schedule(task, false);
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Not Recovering task with id "+taskData.getTaskID() + "
since the factory returned a null task");
+ }
+ task = localRunningTasks.get(taskData.getTaskID());
+ if(task == null) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Task with task id "+taskData.getTaskID() + " is not
present locally neither, removing it from the cache");
+ }
+ remove(taskData.getTaskID(), true);
+ }
+ }
}
public void shutdownNow() {
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipApplicationSession.java
Thu Dec 9 08:58:48 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipApplicationSession.java
Thu Dec 9 10:49:05 2010
@@ -84,6 +84,7 @@
protected static final String HTTP_SESSIONS = "hs";
protected static final String SIP_SESSIONS = "ss";
+ protected static final String SERVLETS_TIMERS = "st";
protected static final String IS_VALID = "iv";
protected static final String INVALIDATION_POLICY = "ip";
protected static final String CREATION_TIME = "ct";
@@ -295,6 +296,8 @@
* call
*/
private transient boolean needsPostReplicateActivation;
+
+ private transient String[] servletTimerIds;
// ------------------------------------------------------------
Constructors
@@ -660,6 +663,9 @@
if(metadata.isHttpSessionsMapModified()) {
this.metadata.getMetaData().put(HTTP_SESSIONS, httpSessions.toArray(new
String[httpSessions.size()]));
}
+ if(metadata.isServletTimersMapModified()) {
+ this.metadata.getMetaData().put(SERVLETS_TIMERS,
servletTimers.keySet().toArray(new String[servletTimers.keySet().size()]));
+ }
}
protected boolean isSessionAttributeMapDirty() {
@@ -712,6 +718,8 @@
sipSessions.add(sipSessionKey);
}
}
+ servletTimerIds =
(String[])md.getMetaData().get(SERVLETS_TIMERS);
+
String[] httpSessionIds =
(String[])md.getMetaData().get(HTTP_SESSIONS);
if(httpSessionIds != null && httpSessionIds.length > 0) {
if(httpSessions == null) {
@@ -1416,6 +1424,18 @@
}
return sessionKey;
}
+
+ @Override
+ public void addServletTimer(ServletTimer servletTimer) {
+ super.addServletTimer(servletTimer);
+ metadata.setServletTimersMapModified(true);
+ }
+
+ @Override
+ public void removeServletTimer(ServletTimer servletTimer) {
+ super.removeServletTimer(servletTimer);
+ metadata.setServletTimersMapModified(true);
+ }
@Override
public boolean addHttpSession(HttpSession httpSession) {
@@ -1448,12 +1468,12 @@
public void rescheduleTimersLocally() {
((ClusteredSipApplicationSessionTimerService)sipContext.getSipApplicationSessionTimerService()).rescheduleTimerLocally(this);
- if(servletTimers != null) {
+ if(servletTimerIds != null) {
if(logger.isInfoEnabled()) {
- logger.info("SipApplicationSession " + key + " number of servletTimers
to reschedule locally " + servletTimers.size());
- }
- for(String key : servletTimers.keySet()) {
-
((ClusteredSipServletTimerService)sipContext.getTimerService()).rescheduleTimerLocally(this,
key);
+ logger.info("SipApplicationSession " + key + " number of servletTimers
to reschedule locally " + servletTimerIds.length);
+ }
+ for(String servletTimerId : servletTimerIds) {
+
((ClusteredSipServletTimerService)sipContext.getTimerService()).rescheduleTimerLocally(this,
servletTimerId);
}
}
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantSasTimerService.java
Thu Dec 9 08:01:47 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantSasTimerService.java
Thu Dec 9 10:49:05 2010
@@ -176,19 +176,24 @@
TimerTask timerTask =
getScheduler().getLocalRunningTask(taskId);
if(timerTask == null) {
SipApplicationSessionTaskData timerTaskData =
(SipApplicationSessionTaskData) getScheduler().getTimerTaskData(taskId);
- if(timerTaskData == null) {
+ // we recreate the task locally
+ FaultTolerantSasTimerTask faultTolerantSasTimerTask = new
FaultTolerantSasTimerTask(sipApplicationSession, timerTaskData);
+
sipApplicationSession.setExpirationTimerTask(faultTolerantSasTimerTask);
+ if(timerTaskData != null) {
if(logger.isInfoEnabled()) {
logger.info("Task for sip application session " + taskId + " is not
present locally, but on another node, rescheduling it locally.");
}
// we cancel it, this will cause the remote owner node to remove it
and cancel its local task
getScheduler().cancel(taskId);
- // we recreate the task locally
- FaultTolerantSasTimerTask faultTolerantSasTimerTask = new
FaultTolerantSasTimerTask(sipApplicationSession, timerTaskData);
// and reset its start time to the correct one
- faultTolerantSasTimerTask.beforeRecover();
-
sipApplicationSession.setExpirationTimerTask(faultTolerantSasTimerTask);
+ faultTolerantSasTimerTask.beforeRecover();
// and reschedule it locally
getScheduler().schedule(faultTolerantSasTimerTask);
+ } else {
+ if(logger.isInfoEnabled()) {
+ logger.info("Task for sip application session " + taskId + " is not
present locally, nor on another node, rescheduling it.");
+ }
+
getScheduler().schedule(faultTolerantSasTimerTask);
}
} else {
if(logger.isInfoEnabled()) {
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantTimerServiceImpl.java
Thu Dec 9 08:01:47 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantTimerServiceImpl.java
Thu Dec 9 10:49:05 2010
@@ -213,19 +213,26 @@
TimerTask timerTask =
getScheduler().getLocalRunningTask(timerId);
if(timerTask == null) {
TimerServiceTaskData timerTaskData = (TimerServiceTaskData)
getScheduler().getTimerTaskData(timerId);
- if(timerTaskData == null) {
+ // we recreate the task locally
+ ServletTimerImpl servletTimerImpl = new
ServletTimerImpl(timerTaskData.getData(), timerTaskData.getDelay(),
sipApplicationSession.getSipContext().getListeners().getTimerListener(),
sipApplicationSession);
+ TimerServiceTask timerServiceTask = new TimerServiceTask(sipManager,
servletTimerImpl, timerTaskData);
+
+ if(timerTaskData != null) {
if(logger.isInfoEnabled()) {
logger.info("Task " + timerId + " is not present locally, but on
another node, rescheduling it locally.");
}
// we cancel it, this will cause the remote owner node to remove it
and cancel its local task
- getScheduler().cancel(timerId);
- // we recreate the task locally
- ServletTimerImpl servletTimerImpl = new
ServletTimerImpl(timerTaskData.getData(), timerTaskData.getDelay(),
sipApplicationSession.getSipContext().getListeners().getTimerListener(),
sipApplicationSession);
- TimerServiceTask timerServiceTask = new TimerServiceTask(sipManager,
servletTimerImpl, timerTaskData);
+ getScheduler().cancel(timerId);
// and reset its start time to the correct one
timerServiceTask.beforeRecover();
// and reschedule it locally
getScheduler().schedule(timerServiceTask);
+ } else {
+ if(logger.isInfoEnabled()) {
+ logger.info("Task " + timerId + " is not present locally, nor on
another node, rescheduling it.");
+ }
+ // and reschedule it locally
+ getScheduler().schedule(timerServiceTask);
}
} else {
if(logger.isInfoEnabled()) {
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/SipApplicationSessionTaskFactory.java
Wed Jan 27 13:25:57 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/SipApplicationSessionTaskFactory.java
Thu Dec 9 10:49:05 2010
@@ -24,7 +24,9 @@
import org.apache.log4j.Logger;
import org.jboss.web.tomcat.service.session.ClusteredSipManager;
import
org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+import org.mobicents.servlet.sip.annotation.ConcurrencyControlMode;
import
org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
+import org.mobicents.servlet.sip.startup.SipContext;
import org.mobicents.timers.TimerTask;
import org.mobicents.timers.TimerTaskData;
import org.mobicents.timers.TimerTaskFactory;
@@ -51,19 +53,21 @@
public TimerTask newTimerTask(TimerTaskData data) {
SipApplicationSessionTaskData sasData =
(SipApplicationSessionTaskData)data;
MobicentsSipApplicationSession sipApplicationSession =
sipManager.getSipApplicationSession(sasData.getKey(), false);
- if(logger.isDebugEnabled()) {
- if(sipApplicationSession == null) {
- logger.debug("sip application session for key " + sasData.getKey() + "
was not found neither locally or in the cache, sas expiration timer
recreation will be problematic");
- } else {
- logger.debug("sip application session for key " + sasData.getKey() + "
was found");
- }
- }
- FaultTolerantSasTimerTask faultTolerantSasTimerTask = new
FaultTolerantSasTimerTask(sipApplicationSession, sasData);
- if(sipApplicationSession != null) {
-
sipApplicationSession.setExpirationTimerTask(faultTolerantSasTimerTask);
- }
-
- return faultTolerantSasTimerTask;
+
if(((SipContext)sipManager.getContainer()).getConcurrencyControlMode() !=
ConcurrencyControlMode.SipApplicationSession) {
+ if(logger.isDebugEnabled()) {
+ if(sipApplicationSession == null) {
+ logger.debug("sip application session for key " + sasData.getKey()
+ " was not found neither locally or in the cache, sas expiration timer
recreation will be problematic");
+ } else {
+ logger.debug("sip application session for key " + sasData.getKey()
+ " was found");
+ }
+ }
+ FaultTolerantSasTimerTask faultTolerantSasTimerTask = new
FaultTolerantSasTimerTask(sipApplicationSession, sasData);
+ if(sipApplicationSession != null) {
+
sipApplicationSession.setExpirationTimerTask(faultTolerantSasTimerTask);
+ }
+ return faultTolerantSasTimerTask;
+ }
+ return null;
}
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/TimerServiceTaskFactory.java
Thu Jan 7 05:16:33 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/TimerServiceTaskFactory.java
Thu Dec 9 10:49:05 2010
@@ -23,6 +23,9 @@
import org.jboss.web.tomcat.service.session.ClusteredSipManager;
import
org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+import org.mobicents.servlet.sip.annotation.ConcurrencyControlMode;
+import
org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
+import org.mobicents.servlet.sip.startup.SipContext;
import org.mobicents.timers.TimerTask;
import org.mobicents.timers.TimerTaskData;
import org.mobicents.timers.TimerTaskFactory;
@@ -44,8 +47,12 @@
/* (non-Javadoc)
* @see
org.mobicents.timers.TimerTaskFactory#newTimerTask(org.mobicents.timers.TimerTaskData)
*/
- public TimerTask newTimerTask(TimerTaskData data) {
- return new TimerServiceTask(sipManager, null,
(TimerServiceTaskData)data);
+ public TimerTask newTimerTask(TimerTaskData data) {
+ MobicentsSipApplicationSession sipApplicationSession =
sipManager.getSipApplicationSession(((TimerServiceTaskData)data).getKey(),
false);
+
if(((SipContext)sipManager.getContainer()).getConcurrencyControlMode() !=
ConcurrencyControlMode.SipApplicationSession) {
+ return new TimerServiceTask(sipManager, null,
(TimerServiceTaskData)data);
+ }
+ return null;
}
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5-ha-server-cache/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSipApplicationSessionMetadata.java
Thu Jan 7 05:05:02 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5-ha-server-cache/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/spi/DistributableSipApplicationSessionMetadata.java
Thu Dec 9 10:49:05 2010
@@ -33,6 +33,7 @@
DistributableSessionMetadata {
private transient boolean sipSessionsMapModified;
private transient boolean httpSessionsMapModified;
+ private transient boolean servletTimersMapModified;
// map to store meta data changes for replication.
private transient Map<String, Object> metaData = new HashMap<String,
Object>();
@@ -79,4 +80,18 @@
public boolean isHttpSessionsMapModified() {
return httpSessionsMapModified;
}
-}
+
+ /**
+ * @param servletTimersMapModified the servletTimersMapModified to set
+ */
+ public void setServletTimersMapModified(boolean servletTimersMapModified)
{
+ this.servletTimersMapModified = servletTimersMapModified;
+ }
+
+ /**
+ * @return the servletTimersMapModified
+ */
+ public boolean isServletTimersMapModified() {
+ return servletTimersMapModified;
+ }
+}