PageRenderTime 172ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 133 lines | 68 code | 17 blank | 48 comment | 5 complexity | 970556da41ad2d7833512e72104b64a7 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.web.tomcat.service.session;
  23. import java.util.HashMap;
  24. import java.util.Map;
  25. import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSipSessionMetadata;
  26. import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData;
  27. import org.mobicents.servlet.sip.core.session.MobicentsSipApplicationSession;
  28. import org.mobicents.servlet.sip.core.session.SessionManagerUtil;
  29. import org.mobicents.servlet.sip.core.session.SipApplicationSessionKey;
  30. import org.mobicents.servlet.sip.core.session.SipSessionKey;
  31. import org.mobicents.servlet.sip.message.SipFactoryImpl;
  32. /**
  33. * This class is based on the following Jboss class
  34. * org.jboss.web.tomcat.service.session.SessionBasedClusteredSession JBOSS AS
  35. * 5.1.0.GA Tag
  36. *
  37. * ClusteredSession where the replication granularity level is session based;
  38. * that is, we replicate the entire attribute map whenever a request makes any
  39. * attribute dirty.
  40. *
  41. * @author Ben Wang
  42. * @author Brian Stansberry
  43. *
  44. *
  45. * @author <A HREF="mailto:jean.deruelle@gmail.com">Jean Deruelle</A>
  46. *
  47. */
  48. public class SessionBasedClusteredSipSession extends
  49. ClusteredSipSession<OutgoingSessionGranularitySessionData> {
  50. /**
  51. * Descriptive information describing this Session implementation.
  52. */
  53. protected static final String info = "SessionBasedClusteredSipSession/1.0";
  54. /**
  55. * @param key
  56. * @param sipFactoryImpl
  57. * @param mobicentsSipApplicationSession
  58. */
  59. public SessionBasedClusteredSipSession(SipSessionKey key,
  60. SipFactoryImpl sipFactoryImpl,
  61. MobicentsSipApplicationSession mobicentsSipApplicationSession,
  62. boolean useJK) {
  63. super(key, sipFactoryImpl, mobicentsSipApplicationSession, useJK);
  64. }
  65. // ---------------------------------------------- Overridden Public Methods
  66. @Override
  67. public String getInfo() {
  68. return (info);
  69. }
  70. @Override
  71. protected OutgoingSessionGranularitySessionData getOutgoingSipSessionData() {
  72. Map<String, Object> attrs = isSessionAttributeMapDirty() ? getSessionAttributeMap() : null;
  73. DistributableSipSessionMetadata metadata = isSessionMetadataDirty() ? (DistributableSipSessionMetadata) getSessionMetadata() : null;
  74. Long timestamp = attrs != null || metadata != null
  75. || getMustReplicateTimestamp() ? Long
  76. .valueOf(getSessionTimestamp()) : null;
  77. OutgoingData outgoingData = new OutgoingData(null, getVersion(), timestamp, sipApplicationSessionKey.getId(), SessionManagerUtil.getSipSessionHaKey(key), metadata,
  78. attrs);
  79. outgoingData.setSessionMetaDataDirty(isSessionMetadataDirty());
  80. return outgoingData;
  81. }
  82. @Override
  83. protected Object removeAttributeInternal(String name, boolean localCall,
  84. boolean localOnly) {
  85. if (localCall)
  86. sessionAttributesDirty();
  87. return getAttributesInternal().remove(name);
  88. }
  89. @Override
  90. protected Object setAttributeInternal(String name, Object value) {
  91. sessionAttributesDirty();
  92. return getAttributesInternal().put(name, value);
  93. }
  94. // ----------------------------------------------------------------- Private
  95. private Map<String, Object> getSessionAttributeMap() {
  96. Map<String, Object> attrs = new HashMap<String, Object>(
  97. getAttributesInternal());
  98. removeExcludedAttributes(attrs);
  99. return attrs;
  100. }
  101. // ----------------------------------------------------------------- Classes
  102. private static class OutgoingData extends
  103. OutgoingDistributableSipSessionDataImpl implements
  104. OutgoingSessionGranularitySessionData {
  105. private final Map<String, Object> attributes;
  106. public OutgoingData(String realId, int version, Long timestamp, String sipApplicationSessionKey, String sipSessionKey,
  107. DistributableSipSessionMetadata metadata,
  108. Map<String, Object> attributes) {
  109. super(realId, version, timestamp, sipApplicationSessionKey, sipSessionKey, metadata);
  110. this.attributes = attributes;
  111. }
  112. public Map<String, Object> getSessionAttributes() {
  113. return attributes;
  114. }
  115. }
  116. }