PageRenderTime 93ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/servers/jain-slee/resources/diameter-s6a/ra/src/main/java/org/mobicents/slee/resource/diameter/s6a/handlers/S6aSessionFactory.java

http://mobicents.googlecode.com/
Java | 240 lines | 160 code | 31 blank | 49 comment | 7 complexity | cfb880c638e4f26e1bcfd130152c6eb4 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.mobicents.slee.resource.diameter.s6a.handlers;
  23. import org.apache.log4j.Logger;
  24. import org.jdiameter.api.ApplicationId;
  25. import org.jdiameter.api.IllegalDiameterStateException;
  26. import org.jdiameter.api.InternalException;
  27. import org.jdiameter.api.Message;
  28. import org.jdiameter.api.OverloadException;
  29. import org.jdiameter.api.RouteException;
  30. import org.jdiameter.api.SessionFactory;
  31. import org.jdiameter.api.app.AppAnswerEvent;
  32. import org.jdiameter.api.app.AppRequestEvent;
  33. import org.jdiameter.api.app.AppSession;
  34. import org.jdiameter.api.s6a.ClientS6aSession;
  35. import org.jdiameter.api.s6a.ServerS6aSession;
  36. import org.jdiameter.api.s6a.events.JAuthenticationInformationAnswer;
  37. import org.jdiameter.api.s6a.events.JAuthenticationInformationRequest;
  38. import org.jdiameter.api.s6a.events.JCancelLocationAnswer;
  39. import org.jdiameter.api.s6a.events.JCancelLocationRequest;
  40. import org.jdiameter.api.s6a.events.JDeleteSubscriberDataAnswer;
  41. import org.jdiameter.api.s6a.events.JDeleteSubscriberDataRequest;
  42. import org.jdiameter.api.s6a.events.JInsertSubscriberDataAnswer;
  43. import org.jdiameter.api.s6a.events.JInsertSubscriberDataRequest;
  44. import org.jdiameter.api.s6a.events.JNotifyAnswer;
  45. import org.jdiameter.api.s6a.events.JNotifyRequest;
  46. import org.jdiameter.api.s6a.events.JPurgeUEAnswer;
  47. import org.jdiameter.api.s6a.events.JPurgeUERequest;
  48. import org.jdiameter.api.s6a.events.JResetAnswer;
  49. import org.jdiameter.api.s6a.events.JResetRequest;
  50. import org.jdiameter.api.s6a.events.JUpdateLocationAnswer;
  51. import org.jdiameter.api.s6a.events.JUpdateLocationRequest;
  52. import org.jdiameter.client.impl.app.s6a.S6aClientSessionImpl;
  53. import org.jdiameter.common.impl.app.s6a.S6aSessionFactoryImpl;
  54. import org.jdiameter.server.impl.app.s6a.S6aServerSessionImpl;
  55. import org.mobicents.slee.resource.diameter.base.handlers.DiameterRAInterface;
  56. /**
  57. *
  58. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  59. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  60. * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a>
  61. * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a>
  62. */
  63. public class S6aSessionFactory extends S6aSessionFactoryImpl {
  64. private DiameterRAInterface s6aResourceAdaptor;
  65. private static final Logger logger = Logger.getLogger(S6aSessionFactory.class);
  66. public S6aSessionFactory(DiameterRAInterface s6aResourceAdaptor, long messageTimeout, SessionFactory sessionFactory) {
  67. super(sessionFactory);
  68. this.s6aResourceAdaptor = s6aResourceAdaptor;
  69. }
  70. /* (non-Javadoc)
  71. * @see org.jdiameter.common.api.app.IAppSessionFactory#getNewSession(java.lang.String, java.lang.Class, org.jdiameter.api.ApplicationId, java.lang.Object[])
  72. */
  73. @Override
  74. public AppSession getNewSession(String sessionId, Class<? extends AppSession> appSessionClass, ApplicationId applicationId, Object[] args) {
  75. AppSession appSession = null;
  76. if(appSessionClass == ServerS6aSession.class) {
  77. S6aServerSessionImpl serverSession = null;
  78. serverSession = (S6aServerSessionImpl) super.getNewSession(sessionId, appSessionClass, applicationId, args);
  79. appSession = serverSession;
  80. }
  81. else if(appSessionClass == ClientS6aSession.class){
  82. S6aClientSessionImpl clientSession = null;
  83. clientSession = (S6aClientSessionImpl) super.getNewSession(sessionId, appSessionClass, applicationId, args);
  84. appSession = clientSession;
  85. }
  86. else {
  87. throw new IllegalArgumentException("Wrong session class: [" + appSessionClass + "]. Supported[" + ServerS6aSession.class + "," + ClientS6aSession.class + "]");
  88. }
  89. return appSession;
  90. }
  91. /* (non-Javadoc)
  92. * @see org.jdiameter.api.s6a.Servers6aSessionListener#doOtherEvent(org.jdiameter.api.app.AppSession, org.jdiameter.api.app.AppRequestEvent, org.jdiameter.api.app.AppAnswerEvent)
  93. */
  94. @Override
  95. public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  96. logger.info("Diameter S6a Session Factory :: doOtherEvent :: appSession[" + appSession + "], Request[" + request + "]");
  97. doFireEvent(appSession, answer != null ? answer.getMessage() : request.getMessage());
  98. }
  99. /*
  100. * (non-Javadoc)
  101. *
  102. * @see
  103. * org.jdiameter.common.impl.app.sh.ShSessionFactoryImpl#stateChanged(org
  104. * .jdiameter.api.app.AppSession, java.lang.Enum, java.lang.Enum)
  105. */
  106. @Override
  107. public void stateChanged(AppSession source, Enum oldState, Enum newState) {
  108. //s6aResourceAdaptor.stateChanged(source, oldState, newState);
  109. logger.info("Diameter S6a Session Factory :: stateChanged :: source[" + source + "] :: oldState[" + oldState + "], newState[" + newState + "]");
  110. }
  111. /* (non-Javadoc)
  112. * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Enum, java.lang.Enum)
  113. */
  114. @Override
  115. public void stateChanged(Enum oldState, Enum newState) {
  116. logger.info("Diameter S6a Session Factory :: stateChanged :: oldState[" + oldState + "], newState[" + newState + "]");
  117. }
  118. /* (non-Javadoc)
  119. * @see org.jdiameter.common.api.app.s6a.Is6aMessageFactory#getApplicationId()
  120. */
  121. @Override
  122. public long getApplicationId() {
  123. // FIXME: Not needed?
  124. return 16777251;
  125. }
  126. private void doFireEvent(AppSession appSession, Message message) {
  127. this.s6aResourceAdaptor.fireEvent(appSession.getSessions().get(0).getSessionId(), message);
  128. }
  129. @Override
  130. public void doUpdateLocationRequestEvent(ServerS6aSession appSession, JUpdateLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  131. logger.info("Diameter S6a Session Factory :: doUpdateLocationRequest :: appSession[" + appSession + "], Request[" + request + "]");
  132. doFireEvent(appSession, request.getMessage());
  133. }
  134. @Override
  135. public void doUpdateLocationAnswerEvent(ClientS6aSession appSession, JUpdateLocationRequest request, JUpdateLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  136. logger.info("Diameter S6a Session Factory :: doUpdateLocationAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  137. doFireEvent(appSession, answer.getMessage());
  138. }
  139. @Override
  140. public void doAuthenticationInformationRequestEvent(ServerS6aSession appSession, JAuthenticationInformationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  141. logger.info("Diameter S6a Session Factory :: doAuthenticationInformationRequest :: appSession[" + appSession + "], Request[" + request + "]");
  142. doFireEvent(appSession, request.getMessage());
  143. }
  144. @Override
  145. public void doAuthenticationInformationAnswerEvent(ClientS6aSession appSession, JAuthenticationInformationRequest request, JAuthenticationInformationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  146. logger.info("Diameter S6a Session Factory :: doAuthenticationInformationAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  147. doFireEvent(appSession, answer.getMessage());
  148. }
  149. @Override
  150. public void doCancelLocationRequestEvent(ClientS6aSession appSession, JCancelLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  151. logger.info("Diameter S6a Session Factory :: doCancelLocationRequest :: appSession[" + appSession + "], Request[" + request + "]");
  152. doFireEvent(appSession, request.getMessage());
  153. }
  154. @Override
  155. public void doCancelLocationAnswerEvent(ServerS6aSession appSession, JCancelLocationRequest request, JCancelLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  156. logger.info("Diameter S6a Session Factory :: doCancelLocationAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  157. doFireEvent(appSession, answer.getMessage());
  158. }
  159. @Override
  160. public void doInsertSubscriberDataRequestEvent(ClientS6aSession appSession, JInsertSubscriberDataRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  161. logger.info("Diameter S6a Session Factory :: doInsertSubscriberDataRequest :: appSession[" + appSession + "], Request[" + request + "]");
  162. doFireEvent(appSession, request.getMessage());
  163. }
  164. @Override
  165. public void doInsertSubscriberDataAnswerEvent(ServerS6aSession appSession, JInsertSubscriberDataRequest request, JInsertSubscriberDataAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  166. logger.info("Diameter S6a Session Factory :: doInsertSubscriberDataAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  167. doFireEvent(appSession, answer.getMessage());
  168. }
  169. @Override
  170. public void doDeleteSubscriberDataRequestEvent(ClientS6aSession appSession, JDeleteSubscriberDataRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  171. logger.info("Diameter S6a Session Factory :: doDeleteSubscriberDataRequest :: appSession[" + appSession + "], Request[" + request + "]");
  172. doFireEvent(appSession, request.getMessage());
  173. }
  174. @Override
  175. public void doDeleteSubscriberDataAnswerEvent(ServerS6aSession appSession, JDeleteSubscriberDataRequest request, JDeleteSubscriberDataAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  176. logger.info("Diameter S6a Session Factory :: doDeleteSubscriberDataAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  177. doFireEvent(appSession, answer.getMessage());
  178. }
  179. @Override
  180. public void doPurgeUERequestEvent(ServerS6aSession appSession, JPurgeUERequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  181. logger.info("Diameter S6a Session Factory :: doPurgeUERequest :: appSession[" + appSession + "], Request[" + request + "]");
  182. doFireEvent(appSession, request.getMessage());
  183. }
  184. @Override
  185. public void doPurgeUEAnswerEvent(ClientS6aSession appSession, JPurgeUERequest request, JPurgeUEAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  186. logger.info("Diameter S6a Session Factory :: doPurgeUEAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  187. doFireEvent(appSession, answer.getMessage());
  188. }
  189. @Override
  190. public void doResetRequestEvent(ClientS6aSession appSession, JResetRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  191. logger.info("Diameter S6a Session Factory :: doResetRequest :: appSession[" + appSession + "], Request[" + request + "]");
  192. doFireEvent(appSession, request.getMessage());
  193. }
  194. @Override
  195. public void doResetAnswerEvent(ServerS6aSession appSession, JResetRequest request, JResetAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  196. logger.info("Diameter S6a Session Factory :: doResetAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  197. doFireEvent(appSession, answer.getMessage());
  198. }
  199. @Override
  200. public void doNotifyRequestEvent(ServerS6aSession appSession, JNotifyRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  201. logger.info("Diameter S6a Session Factory :: doNotifyRequest :: appSession[" + appSession + "], Request[" + request + "]");
  202. doFireEvent(appSession, request.getMessage());
  203. }
  204. @Override
  205. public void doNotifyAnswerEvent(ClientS6aSession appSession, JNotifyRequest request, JNotifyAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  206. logger.info("Diameter S6a Session Factory :: doNotifyAnswer :: appSession[" + appSession + "], Request[" + request + "], Answer[" + answer + "]");
  207. doFireEvent(appSession, answer.getMessage());
  208. }
  209. }