Revision: 15685
Author: [email protected]
Date: Thu Dec 9 08:01:47 2010
Log: Update Issue 1872
gravitate the timers where the LB decided to fail over the subsequent
request for a sipapplication session which would work better with any kind
of Load Balancer but it is done only if the concurrency control mode is
SipApplicationSession.basically the timer is cancelled remotely and
rescheduled locally. the most recent node that recreate a sip application
session will move the timers locally in recreating the sip application
session
if the sip application session is present on multiple nodes because there
is no affinity then the timers will sit where the sipappsession was
recreated last (note recreated, not updated).
it would stay at the node where it was recreated last it the sip
application session flip flop due to LB flip flopping to different nodes if
there is no affinity then there is no guarantees anyway wrt to concurrency
control
so no need to flip flop the timers
http://code.google.com/p/mobicents/source/detail?r=15685
Added:
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipServletTimerService.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/ClusteredSipApplicationSessionTimerService.java
Modified:
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/JainSipUtils.java
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
/trunk/servers/sip-servlets/sip-servlets-jboss5/.classpath
/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/jboss/web/tomcat/service/session/JBossCacheSipManager.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
=======================================
--- /dev/null
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipServletTimerService.java
Thu Dec 9 08:01:47 2010
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.service.session;
+
+import
org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
+import org.mobicents.servlet.sip.core.timers.SipServletTimerService;
+
+/**
+ * @author [email protected]
+ *
+ */
+public interface ClusteredSipServletTimerService extends
SipServletTimerService {
+
+ void rescheduleTimerLocally(MobicentsSipApplicationSession
sipApplicationSession, String timerId);
+
+}
=======================================
--- /dev/null
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/ClusteredSipApplicationSessionTimerService.java
Thu Dec 9 08:01:47 2010
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.mobicents.servlet.sip.core.timers;
+
+import
org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
+
+/**
+ * @author [email protected]
+ *
+ */
+public interface ClusteredSipApplicationSessionTimerService extends
SipApplicationSessionTimerService {
+ void rescheduleTimerLocally(MobicentsSipApplicationSession
sipApplicationSession);
+}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/JainSipUtils.java
Wed Dec 8 01:41:00 2010
+++
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/JainSipUtils.java
Thu Dec 9 08:01:47 2010
@@ -99,11 +99,9 @@
import javax.sip.message.Request;
import org.apache.log4j.Logger;
-import org.mobicents.servlet.sip.address.SipURIImpl;
import org.mobicents.servlet.sip.core.ExtendedListeningPoint;
import org.mobicents.servlet.sip.core.SipNetworkInterfaceManager;
import org.mobicents.servlet.sip.core.dispatchers.MessageDispatcher;
-import org.mobicents.servlet.sip.message.SipServletRequestImpl;
import org.mobicents.servlet.sip.message.SipFactoryImpl.NamesComparator;
/**
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
Tue Dec 7 08:15:47 2010
+++
/trunk/servers/sip-servlets/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/message/SipServletRequestImpl.java
Thu Dec 9 08:01:47 2010
@@ -59,7 +59,6 @@
import javax.sip.ClientTransaction;
import javax.sip.Dialog;
import javax.sip.DialogState;
-import javax.sip.ObjectInUseException;
import javax.sip.ServerTransaction;
import javax.sip.SipException;
import javax.sip.SipProvider;
=======================================
--- /trunk/servers/sip-servlets/sip-servlets-jboss5/.classpath Tue Nov 16
12:46:45 2010
+++ /trunk/servers/sip-servlets/sip-servlets-jboss5/.classpath Thu Dec 9
08:01:47 2010
@@ -167,9 +167,9 @@
<classpathentry combineaccessrules="false" kind="src"
path="/sip-servlets-spec"/>
<classpathentry combineaccessrules="false" kind="src"
path="/sip-servlets-jboss5-metadata"/>
<classpathentry combineaccessrules="false" kind="src"
path="/sip-servlets-client"/>
- <classpathentry kind="var"
path="M2_REPO/org/mobicents/cluster/core/1.6-SNAPSHOT/core-1.6-SNAPSHOT.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/mobicents/cluster/cache/1.6-SNAPSHOT/cache-1.6-SNAPSHOT.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/mobicents/cluster/timers/1.6-SNAPSHOT/timers-1.6-SNAPSHOT.jar"/>
+ <classpathentry kind="var"
path="M2_REPO/org/mobicents/cluster/core/1.7-SNAPSHOT/core-1.7-SNAPSHOT.jar"/>
+ <classpathentry kind="var"
path="M2_REPO/org/mobicents/cluster/cache/1.7-SNAPSHOT/cache-1.7-SNAPSHOT.jar"/>
+ <classpathentry kind="var"
path="M2_REPO/org/mobicents/cluster/timers/1.7-SNAPSHOT/timers-1.7-SNAPSHOT.jar"/>
<classpathentry combineaccessrules="false" kind="src"
path="/sip-servlets-jboss5-ha-server-cache"/>
<classpathentry combineaccessrules="false" kind="src"
path="/sip-servlets-jruby"/>
<classpathentry kind="var"
path="M2_REPO/org/mobicents/ha/javax/sip/mobicents-jain-sip-ha-core/0.14-SNAPSHOT/mobicents-jain-sip-ha-core-0.14-SNAPSHOT.jar"/>
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipApplicationSession.java
Mon Nov 22 09:01:53 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipApplicationSession.java
Thu Dec 9 08:01:47 2010
@@ -64,6 +64,7 @@
import org.mobicents.servlet.sip.core.session.SipListenersHolder;
import org.mobicents.servlet.sip.core.session.SipManager;
import org.mobicents.servlet.sip.core.session.SipSessionKey;
+import
org.mobicents.servlet.sip.core.timers.ClusteredSipApplicationSessionTimerService;
import org.mobicents.servlet.sip.core.timers.FaultTolerantSasTimerTask;
import org.mobicents.servlet.sip.core.timers.TimerServiceTask;
import org.mobicents.servlet.sip.startup.SipContext;
@@ -1444,4 +1445,14 @@
public String getHaId() {
return key.getId();
}
-}
+
+ public void rescheduleTimersLocally() {
+
((ClusteredSipApplicationSessionTimerService)sipContext.getSipApplicationSessionTimerService()).rescheduleTimerLocally(this);
+ 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);
+ }
+ }
+}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java
Thu Dec 2 08:11:40 2010
+++
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java
Thu Dec 9 08:01:47 2010
@@ -79,6 +79,7 @@
import org.mobicents.cluster.election.DefaultClusterElector;
import org.mobicents.ha.javax.sip.ClusteredSipStack;
import org.mobicents.ha.javax.sip.ReplicationStrategy;
+import org.mobicents.servlet.sip.annotation.ConcurrencyControlMode;
import
org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
import org.mobicents.servlet.sip.core.session.MobicentsSipSession;
import org.mobicents.servlet.sip.core.session.SessionManagerUtil;
@@ -2647,6 +2648,13 @@
if(session != null) {
session.update(data);
}
+ if(mustAdd &&
((SipContext)getContainer()).getConcurrencyControlMode() ==
ConcurrencyControlMode.SipApplicationSession) {
+ if(logger.isInfoEnabled()) {
+ logger.info("SipApplicationSession " + key + " has just been
recreated and concurrency control is set to SipApplicationSession,
colocating the timers here to ensure no concurrent access across the
cluster");
+ }
+ // if the session has been recreated, reschedule the FT timers
locally if they are not local already
+
((ClusteredSipApplicationSession) session).rescheduleTimersLocally();
+ }
} else if(logger.isDebugEnabled()) {
logger.debug("no data for sip application session " + key + "
in the distributed cache");
}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantSasTimerService.java
Tue Nov 16 09:38:47 2010
+++
/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
@@ -32,6 +32,7 @@
import org.mobicents.servlet.sip.startup.SipContext;
import org.mobicents.timers.FaultTolerantScheduler;
import org.mobicents.timers.TimerTask;
+import org.mobicents.timers.TimerTaskData;
import org.mobicents.timers.TimerTaskFactory;
/**
@@ -41,7 +42,7 @@
* @author [email protected]
*
*/
-public class FaultTolerantSasTimerService implements
SipApplicationSessionTimerService {
+public class FaultTolerantSasTimerService implements
ClusteredSipApplicationSessionTimerService {
private static final Logger logger =
Logger.getLogger(FaultTolerantSasTimerService.class
.getName());
@@ -66,6 +67,10 @@
return new FaultTolerantSasTimerTask(sipManager,
sipApplicationSession);
}
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.servlet.sip.core.timers.SipApplicationSessionTimerService#schedule(org.mobicents.servlet.sip.core.timers.SipApplicationSessionTimerTask,
long, java.util.concurrent.TimeUnit)
+ */
public SipApplicationSessionTimerTask
schedule(SipApplicationSessionTimerTask expirationTimerTask,
long delay,
TimeUnit unit) {
@@ -88,6 +93,10 @@
throw new IllegalArgumentException("the task to schedule is not an
instance of FaultTolerantSasTimerTask");
}
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.servlet.sip.core.timers.SipApplicationSessionTimerService#cancel(org.mobicents.servlet.sip.core.timers.SipApplicationSessionTimerTask)
+ */
public boolean cancel(SipApplicationSessionTimerTask expirationTimerTask)
{
if(expirationTimerTask instanceof FaultTolerantSasTimerTask) {
TimerTask cancelledTask =
getScheduler().cancel(((FaultTolerantSasTimerTask)expirationTimerTask).getData().getTaskID());
@@ -108,6 +117,10 @@
// method not exposed by Mobicents FaultTolerantScheduler
}
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.servlet.sip.core.timers.SipApplicationSessionTimerService#stop()
+ */
public void stop() {
// return super.shutdownNow();
// method not exposed by Mobicents FaultTolerantScheduler
@@ -146,8 +159,41 @@
}
}
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.servlet.sip.core.timers.SipApplicationSessionTimerService#isStarted()
+ */
public boolean isStarted() {
return started.get();
}
-}
+ /*
+ * (non-Javadoc)
+ * @see
org.mobicents.servlet.sip.core.timers.ClusteredSipApplicationSessionTimerService#rescheduleTimerLocally(org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession)
+ */
+ public void rescheduleTimerLocally(MobicentsSipApplicationSession
sipApplicationSession) {
+ final String taskId = sipApplicationSession.getId();
+ TimerTask timerTask =
getScheduler().getLocalRunningTask(taskId);
+ if(timerTask == null) {
+ SipApplicationSessionTaskData timerTaskData =
(SipApplicationSessionTaskData) getScheduler().getTimerTaskData(taskId);
+ 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);
+ // and reschedule it locally
+
getScheduler().schedule(faultTolerantSasTimerTask);
+ }
+ } else {
+ if(logger.isInfoEnabled()) {
+ logger.info("Task for sip application session " + taskId + " is
already present locally no need to reschedule it.");
+ }
+ }
+ }
+}
=======================================
---
/trunk/servers/sip-servlets/sip-servlets-jboss5/src/main/java/org/mobicents/servlet/sip/core/timers/FaultTolerantTimerServiceImpl.java
Tue Nov 16 12:22:49 2010
+++
/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
@@ -22,16 +22,17 @@
import javax.servlet.sip.ServletTimer;
import javax.servlet.sip.SipApplicationSession;
import javax.servlet.sip.TimerListener;
-import javax.servlet.sip.TimerService;
import org.apache.log4j.Logger;
import org.jboss.web.tomcat.service.session.ClusteredSipManager;
+import
org.jboss.web.tomcat.service.session.ClusteredSipServletTimerService;
import
org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
import org.mobicents.servlet.sip.core.session.DistributableSipManager;
import
org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
import org.mobicents.servlet.sip.startup.SipContext;
import org.mobicents.timers.FaultTolerantScheduler;
import org.mobicents.timers.PeriodicScheduleStrategy;
+import org.mobicents.timers.TimerTask;
import org.mobicents.timers.TimerTaskFactory;
/**
@@ -40,7 +41,7 @@
* @author [email protected]
*
*/
-public class FaultTolerantTimerServiceImpl implements
SipServletTimerService {
+public class FaultTolerantTimerServiceImpl implements
ClusteredSipServletTimerService {
private static final long serialVersionUID = 1L;
private static final Logger logger =
Logger.getLogger(FaultTolerantTimerServiceImpl.class
@@ -203,6 +204,35 @@
public boolean isStarted() {
return started.get();
}
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.web.tomcat.service.session.ClusteredSipServletTimerService#rescheduleTimerLocally(org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession,
java.lang.String)
+ */
+ public void rescheduleTimerLocally(MobicentsSipApplicationSession
sipApplicationSession, String timerId) {
+ TimerTask timerTask =
getScheduler().getLocalRunningTask(timerId);
+ if(timerTask == null) {
+ TimerServiceTaskData timerTaskData = (TimerServiceTaskData)
getScheduler().getTimerTaskData(timerId);
+ 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);
+ // 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 already present locally no need
to reschedule it.");
+ }
+ }
+ }
}