Skip to content

Commit 1799025

Browse files
Update Issue 2781
Committing fix + non regression test git-svn-id: https://mobicents.googlecode.com/svn/trunk/servers/sip-servlets@19601 bf0df8d0-2c1f-0410-b170-bd30377b63dc
1 parent 94a3240 commit 1799025

File tree

6 files changed

+97
-86
lines changed

6 files changed

+97
-86
lines changed

sip-servlets-examples/simple-sip-servlet-distributable/src/main/java/org/mobicents/servlet/sip/example/DistributableSimpleSipServlet.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
public class DistributableSimpleSipServlet
5353
extends SipServlet
5454
implements TimerListener, SipApplicationSessionListener {
55+
private static final String SIP_APP_SESSION_ACTIVATION_LISTENER = "sipAppSessionActivationListener";
56+
private static final String SIP_SESSION_ACTIVATION_LISTENER = "sipSessionActivationListener";
5557
private static final long serialVersionUID = 1L;
5658
private static final String RECEIVED = "Received";
5759

@@ -104,9 +106,9 @@ protected void doInvite(SipServletRequest request) throws ServletException,
104106
if(!(((SipURI)request.getFrom().getURI()).getUser()).contains(NO_ATTRIBUTES)) {
105107
if(request.isInitial()) {
106108
request.getSession().setAttribute("INVITE", RECEIVED);
107-
request.getSession().setAttribute("sipSessionActivationListener", new SipSessionActivationListenerAttribute());
109+
request.getSession().setAttribute(SIP_SESSION_ACTIVATION_LISTENER, new SipSessionActivationListenerAttribute());
108110
request.getApplicationSession().setAttribute("INVITE", RECEIVED);
109-
request.getApplicationSession().setAttribute("sipAppSessionActivationListener", new SipApplicationSessionActivationListenerAttribute());
111+
request.getApplicationSession().setAttribute(SIP_APP_SESSION_ACTIVATION_LISTENER, new SipApplicationSessionActivationListenerAttribute());
110112
if(((SipURI)request.getTo().getURI()).getUser().contains("reinvite")) {
111113
if(logger.isInfoEnabled()) {
112114
logger.info("Distributable Simple Servlet: setting isReINVITE");
@@ -152,11 +154,19 @@ protected void doBye(SipServletRequest request) throws ServletException,
152154
String sipApplicationSessionInviteAttribute = (String) request.getApplicationSession().getAttribute("INVITE");
153155
String sipSessionReInviteAttribute = (String) request.getSession().getAttribute("REINVITE");
154156
String sipApplicationSessionReInviteAttribute = (String) request.getApplicationSession().getAttribute("REINVITE");
157+
Object sipSessionActivationListener = request.getSession().getAttribute(SIP_SESSION_ACTIVATION_LISTENER);
158+
Object sipApplicationSessionActivationListener = request.getApplicationSession().getAttribute(SIP_APP_SESSION_ACTIVATION_LISTENER);
159+
Object sipSessionActivated = request.getSession().getAttribute(SipSessionActivationListenerAttribute.SIP_SESSION_ACTIVATED);
160+
Object sipApplicationSessionActivated = request.getApplicationSession().getAttribute(SipApplicationSessionActivationListenerAttribute.SIP_APPLICATION_SESSION_ACTIVATED);
155161
if(logger.isInfoEnabled()) {
156162
logger.info("Distributable Simple Servlet: attributes previously set in sip session INVITE : "+ sipSessionInviteAttribute);
157163
logger.info("Distributable Simple Servlet: attributes previously set in sip application session INVITE : "+ sipApplicationSessionInviteAttribute);
158164
logger.info("Distributable Simple Servlet: attributes previously set in sip session REINVITE : "+ sipSessionReInviteAttribute);
159165
logger.info("Distributable Simple Servlet: attributes previously set in sip application session REINVITE : "+ sipApplicationSessionReInviteAttribute);
166+
logger.info("Distributable Simple Servlet: attributes previously set in sip session sipSessionActivationListener : "+ sipSessionActivationListener);
167+
logger.info("Distributable Simple Servlet: attributes previously set in sip application session sipApplciationSessionActivationListener : "+ sipApplicationSessionActivationListener);
168+
logger.info("Distributable Simple Servlet: attributes previously set in sip session sipSessionActivated : "+ sipSessionActivated);
169+
logger.info("Distributable Simple Servlet: attributes previously set in sip application session sipApplicationSessionActivated : "+ sipApplicationSessionActivated);
160170
}
161171
if(!(((SipURI)request.getFrom().getURI()).getUser()).contains(NO_ATTRIBUTES)) {
162172
if(sipSessionInviteAttribute != null && sipApplicationSessionInviteAttribute != null
@@ -173,7 +183,16 @@ protected void doBye(SipServletRequest request) throws ServletException,
173183
return;
174184
}
175185
}
176-
186+
if(sipApplicationSessionActivationListener != null && sipApplicationSessionActivated == null) {
187+
SipServletResponse sipServletResponse = request.createResponse(500, "sipApplicationSessionActivationListener not called");
188+
sipServletResponse.send();
189+
return;
190+
}
191+
if(sipSessionActivationListener != null && sipSessionActivated == null) {
192+
SipServletResponse sipServletResponse = request.createResponse(500, "sipSessionActivationListener not called");
193+
sipServletResponse.send();
194+
return;
195+
}
177196
if(request.getSession().getAttribute("ISREINVITE") !=null && sipSessionReInviteAttribute != null && sipApplicationSessionReInviteAttribute != null
178197
&& RECEIVED.equalsIgnoreCase(sipSessionReInviteAttribute)
179198
&& RECEIVED.equalsIgnoreCase(sipApplicationSessionReInviteAttribute)) {

sip-servlets-examples/simple-sip-servlet-distributable/src/main/java/org/mobicents/servlet/sip/example/SipApplicationSessionActivationListenerAttribute.java

+2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
public class SipApplicationSessionActivationListenerAttribute implements
3737
Serializable, SipApplicationSessionActivationListener {
3838

39+
public static final String SIP_APPLICATION_SESSION_ACTIVATED = "sipApplicationSessionActivated";
3940
private static Logger logger = Logger.getLogger(SipApplicationSessionActivationListenerAttribute.class);
4041

4142
/* (non-Javadoc)
4243
* @see javax.servlet.sip.SipApplicationSessionActivationListener#sessionDidActivate(javax.servlet.sip.SipApplicationSessionEvent)
4344
*/
4445
public void sessionDidActivate(SipApplicationSessionEvent event) {
4546
logger.info("Following sip application session just activated " + event.getApplicationSession().getId());
47+
event.getApplicationSession().setAttribute(SIP_APPLICATION_SESSION_ACTIVATED, "true" );
4648

4749
}
4850

sip-servlets-examples/simple-sip-servlet-distributable/src/main/java/org/mobicents/servlet/sip/example/SipSessionActivationListenerAttribute.java

+2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
public class SipSessionActivationListenerAttribute implements Serializable,
3737
SipSessionActivationListener {
3838

39+
public static final String SIP_SESSION_ACTIVATED = "sipSessionActivated";
3940
private static Logger logger = Logger.getLogger(SipSessionActivationListenerAttribute.class);
4041

4142
/* (non-Javadoc)
4243
* @see javax.servlet.sip.SipSessionActivationListener#sessionDidActivate(javax.servlet.sip.SipSessionEvent)
4344
*/
4445
public void sessionDidActivate(SipSessionEvent event) {
4546
logger.info("Following sip session just activated " + event.getSession().getId());
47+
event.getSession().setAttribute(SIP_SESSION_ACTIVATED, "true" );
4648
}
4749

4850
/* (non-Javadoc)

sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipApplicationSession.java

+22-32
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Iterator;
3535
import java.util.List;
3636
import java.util.Map;
37+
import java.util.Map.Entry;
3738
import java.util.Set;
3839
import java.util.concurrent.ConcurrentHashMap;
3940
import java.util.concurrent.CopyOnWriteArraySet;
@@ -936,42 +937,31 @@ public boolean isSessionDirty() {
936937
return sessionAttributesDirty || sessionMetadataDirty;
937938
}
938939

939-
/** Inform any SipApplicationSessionListener of the creation of this session */
940-
public void tellNew(ClusteredSessionNotificationCause cause) {
941-
// Notify interested session event listeners
942-
// fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
943-
944-
// Notify interested application event listeners
945-
if (notificationPolicy.isSipApplicationSessionListenerInvocationAllowed(
946-
this.clusterStatus, cause, true)) {
947-
Context context = (Context) manager.getContainer();
948-
Object lifecycleListeners[] = context
949-
.getApplicationLifecycleListeners();
950-
if (lifecycleListeners != null) {
951-
SipApplicationSessionEvent event = new SipApplicationSessionEvent(this);
952-
for (int i = 0; i < lifecycleListeners.length; i++) {
953-
if (!(lifecycleListeners[i] instanceof SipApplicationSessionListener))
954-
continue;
955-
SipApplicationSessionListener listener = (SipApplicationSessionListener) lifecycleListeners[i];
956-
try {
957-
fireContainerEvent(context, "beforeSessionCreated",
958-
listener);
959-
listener.sessionCreated(event);
960-
fireContainerEvent(context, "afterSessionCreated",
961-
listener);
962-
} catch (Throwable t) {
940+
/** Inform any SipApplicationSessionActivationListener of the activation of this session */
941+
public void tellActivation(ClusteredSessionNotificationCause cause) {
942+
if(attributes != null) {
943+
for(Entry<String, Object> attribute : attributes.entrySet()) {
944+
SipApplicationSessionEvent sipApplicationSessionEvent = new SipApplicationSessionEvent(this);
945+
ClassLoader oldLoader = java.lang.Thread.currentThread().getContextClassLoader();
946+
java.lang.Thread.currentThread().setContextClassLoader(sipContext.getLoader().getClassLoader());
947+
948+
if(attribute.getValue() instanceof SipApplicationSessionActivationListener) {
949+
if (notificationPolicy.isSipApplicationSessionActivationListenerInvocationAllowed(
950+
this.clusterStatus, cause, attribute.getKey())) {
963951
try {
964-
fireContainerEvent(context, "afterSessionCreated",
965-
listener);
966-
} catch (Exception e) {
967-
;
952+
if(logger.isDebugEnabled()) {
953+
logger.debug("notifying sip application session activation listener " + attribute.getValue() + " of sip application session activation " +
954+
key);
955+
}
956+
((SipApplicationSessionActivationListener)attribute.getValue()).sessionDidActivate(sipApplicationSessionEvent);
957+
} catch (Throwable t) {
958+
logger.error("SipApplicationSessionActivationListener " + attribute.getValue() + " threw exception", t);
968959
}
969-
manager.getContainer().getLogger().error(
970-
sm.getString("clusteredSession.sessionEvent"),
971-
t);
972960
}
973961
}
974-
}
962+
963+
java.lang.Thread.currentThread().setContextClassLoader(oldLoader);
964+
}
975965
}
976966
}
977967

sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/ClusteredSipSession.java

+23-35
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import java.util.Iterator;
3737
import java.util.List;
3838
import java.util.Map;
39-
import java.util.Set;
4039
import java.util.Map.Entry;
40+
import java.util.Set;
4141
import java.util.concurrent.ConcurrentHashMap;
4242
import java.util.concurrent.atomic.AtomicInteger;
4343
import java.util.concurrent.atomic.AtomicLong;
@@ -49,7 +49,6 @@
4949
import javax.servlet.sip.SipSessionBindingEvent;
5050
import javax.servlet.sip.SipSessionBindingListener;
5151
import javax.servlet.sip.SipSessionEvent;
52-
import javax.servlet.sip.SipSessionListener;
5352
import javax.sip.Dialog;
5453
import javax.sip.ServerTransaction;
5554
import javax.sip.SipStack;
@@ -1190,45 +1189,34 @@ public boolean isSessionDirty() {
11901189
return sessionAttributesDirty || sessionMetadataDirty;
11911190
}
11921191

1193-
/** Inform any SipSessionListener of the creation of this session */
1194-
public void tellNew(ClusteredSessionNotificationCause cause) {
1195-
// Notify interested session event listeners
1196-
// fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
1197-
1198-
// Notify interested application event listeners
1199-
if (notificationPolicy.isSipSessionListenerInvocationAllowed(
1200-
this.clusterStatus, cause, true)) {
1201-
Context context = (Context) manager.getContainer();
1202-
Object lifecycleListeners[] = context
1203-
.getApplicationLifecycleListeners();
1204-
if (lifecycleListeners != null) {
1205-
SipSessionEvent event = new SipSessionEvent(this);
1206-
for (int i = 0; i < lifecycleListeners.length; i++) {
1207-
if (!(lifecycleListeners[i] instanceof SipSessionListener))
1208-
continue;
1209-
SipSessionListener listener = (SipSessionListener) lifecycleListeners[i];
1210-
try {
1211-
fireContainerEvent(context, "beforeSessionCreated",
1212-
listener);
1213-
listener.sessionCreated(event);
1214-
fireContainerEvent(context, "afterSessionCreated",
1215-
listener);
1216-
} catch (Throwable t) {
1192+
/** Inform any SipApplicationSessionActivationListener of the activation of this session */
1193+
public void tellActivation(ClusteredSessionNotificationCause cause) {
1194+
if(attributes != null) {
1195+
for(Entry<String, Object> attribute : attributes.entrySet()) {
1196+
SipSessionEvent sipSessionEvent = new SipSessionEvent(this);
1197+
ClassLoader oldLoader = java.lang.Thread.currentThread().getContextClassLoader();
1198+
java.lang.Thread.currentThread().setContextClassLoader(getSipApplicationSession().getSipContext().getLoader().getClassLoader());
1199+
1200+
if(attribute.getValue() instanceof SipSessionActivationListener) {
1201+
if (notificationPolicy.isSipSessionActivationListenerInvocationAllowed(
1202+
this.clusterStatus, cause, attribute.getKey())) {
12171203
try {
1218-
fireContainerEvent(context, "afterSessionCreated",
1219-
listener);
1220-
} catch (Exception e) {
1221-
;
1204+
if(logger.isDebugEnabled()) {
1205+
logger.debug("notifying sip session activation listener " + attribute.getValue() + " of sip session activation " +
1206+
key);
1207+
}
1208+
((SipSessionActivationListener)attribute.getValue()).sessionDidActivate(sipSessionEvent);
1209+
} catch (Throwable t) {
1210+
logger.error("SipSessionActivationListener " + attribute.getValue() + " threw exception", t);
12221211
}
1223-
manager.getContainer().getLogger().error(
1224-
sm.getString("clusteredSession.sessionEvent"),
1225-
t);
12261212
}
12271213
}
1228-
}
1214+
1215+
java.lang.Thread.currentThread().setContextClassLoader(oldLoader);
1216+
}
12291217
}
12301218
}
1231-
1219+
12321220
private String[] keys() {
12331221
Set<String> keySet = getAttributesInternal().keySet();
12341222
return ((String[]) keySet.toArray(new String[keySet.size()]));

sip-servlets-jboss5/src/main/java/org/jboss/web/tomcat/service/session/JBossCacheSipManager.java

+26-16
Original file line numberDiff line numberDiff line change
@@ -2509,15 +2509,21 @@ protected ClusteredSipSession loadSipSession(final SipSessionKey key, final bool
25092509
session = (ClusteredSipSession<? extends OutgoingDistributableSessionData>)
25102510
((ClusteredSipManagerDelegate)sipManagerDelegate).getNewMobicentsSipSession(key, sipFactory, sipApplicationSessionImpl, true);
25112511
OwnedSessionUpdate osu = unloadedSipSessions_.get(key);
2512-
passivated = (osu != null && osu.passivated);
2512+
passivated = (osu != null && osu.passivated);
25132513
} else {
25142514
if(logger.isDebugEnabled()) {
25152515
logger.debug("beware null parent sip application for session " + key);
25162516
}
25172517
}
25182518
}
25192519
if(session!= null) {
2520-
session.update(data);
2520+
session.update(data);
2521+
if (mustAdd && initialLoad) {
2522+
if(logger.isDebugEnabled()) {
2523+
logger.debug("notifying listeners for activation of sip session " + key + " found in the distributed cache");
2524+
}
2525+
session.tellActivation(!passivated ? ClusteredSessionNotificationCause.FAILOVER : ClusteredSessionNotificationCause.ACTIVATION);
2526+
}
25212527
}
25222528
} else if(logger.isDebugEnabled()) {
25232529
logger.debug("no data for sip session " + key + " in the distributed cache");
@@ -2561,22 +2567,19 @@ protected ClusteredSipSession loadSipSession(final SipSessionKey key, final bool
25612567
}
25622568
if (session != null) {
25632569
if (mustAdd) {
2564-
unloadedSipSessions_.remove(key);
2565-
if (!passivated) {
2566-
session.tellNew(ClusteredSessionNotificationCause.FAILOVER);
2567-
}
2570+
unloadedSipSessions_.remove(key);
25682571
}
25692572
long elapsed = System.currentTimeMillis() - begin;
25702573
stats_.updateLoadStats(key.toString(), elapsed);
25712574

25722575
if (log_.isDebugEnabled()) {
25732576
log_
2574-
.debug("loadSession(): id= " + key + ", session="
2577+
.debug("loadSipSession(): id= " + key + ", session="
25752578
+ session);
25762579
}
25772580
return session;
25782581
} else if (log_.isDebugEnabled()) {
2579-
log_.debug("loadSession(): session " + key
2582+
log_.debug("loadSipSession(): session " + key
25802583
+ " not found in distributed cache");
25812584
}
25822585
if(session != null) {
@@ -2609,6 +2612,10 @@ protected ClusteredSipApplicationSession loadSipApplicationSession(
26092612
return null;
26102613
}
26112614

2615+
if(logger.isDebugEnabled()) {
2616+
logger.debug("load sip application session " + key + ", create = " + create);
2617+
}
2618+
26122619
long begin = System.currentTimeMillis();
26132620
boolean mustAdd = false;
26142621
boolean passivated = false;
@@ -2655,10 +2662,16 @@ protected ClusteredSipApplicationSession loadSipApplicationSession(
26552662
session = (ClusteredSipApplicationSession)
26562663
((ClusteredSipManagerDelegate)sipManagerDelegate).getNewMobicentsSipApplicationSession(key, ((SipContext)getContainer()), true);
26572664
OwnedSessionUpdate osu = unloadedSipApplicationSessions_.get(key);
2658-
passivated = (osu != null && osu.passivated);
2665+
passivated = (osu != null && osu.passivated);
26592666
}
26602667
if(session != null) {
2661-
session.update(data);
2668+
session.update(data);
2669+
if (mustAdd && initialLoad) {
2670+
if(logger.isDebugEnabled()) {
2671+
logger.debug("notifying listeners for activation of sip application session " + key + " found in the distributed cache");
2672+
}
2673+
session.tellActivation(!passivated ? ClusteredSessionNotificationCause.FAILOVER : ClusteredSessionNotificationCause.ACTIVATION);
2674+
}
26622675
}
26632676
if(mustAdd && ((SipContext)getContainer()).getConcurrencyControlMode() == ConcurrencyControlMode.SipApplicationSession) {
26642677
if(logger.isInfoEnabled()) {
@@ -2705,21 +2718,18 @@ protected ClusteredSipApplicationSession loadSipApplicationSession(
27052718
}
27062719
if (session != null) {
27072720
if (mustAdd) {
2708-
unloadedSipApplicationSessions_.remove(key);
2709-
if (!passivated) {
2710-
session.tellNew(ClusteredSessionNotificationCause.FAILOVER);
2711-
}
2721+
unloadedSipApplicationSessions_.remove(key);
27122722
}
27132723
long elapsed = System.currentTimeMillis() - begin;
27142724
stats_.updateLoadStats(key.toString(), elapsed);
27152725

27162726
if (log_.isDebugEnabled()) {
2717-
log_.debug("loadSession(): id= " + key.toString()
2727+
log_.debug("loadSipApplicationSession(): id= " + key.toString()
27182728
+ ", session=" + session);
27192729
}
27202730
return session;
27212731
} else if (log_.isDebugEnabled()) {
2722-
log_.debug("loadSession(): session " + key.toString()
2732+
log_.debug("loadSipApplicationSession(): session " + key.toString()
27232733
+ " not found in distributed cache");
27242734
}
27252735
if(session != null) {

0 commit comments

Comments
 (0)