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

/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/common/impl/app/s6a/S6aSessionFactoryImpl.java

http://mobicents.googlecode.com/
Java | 390 lines | 262 code | 61 blank | 67 comment | 33 complexity | 2abb3fec50bcab222801a9c430823adb 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.jdiameter.common.impl.app.s6a;
  23. import org.jdiameter.api.Answer;
  24. import org.jdiameter.api.ApplicationId;
  25. import org.jdiameter.api.IllegalDiameterStateException;
  26. import org.jdiameter.api.InternalException;
  27. import org.jdiameter.api.OverloadException;
  28. import org.jdiameter.api.Request;
  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.app.StateChangeListener;
  35. import org.jdiameter.api.s6a.ClientS6aSession;
  36. import org.jdiameter.api.s6a.ClientS6aSessionListener;
  37. import org.jdiameter.api.s6a.ServerS6aSession;
  38. import org.jdiameter.api.s6a.ServerS6aSessionListener;
  39. import org.jdiameter.api.s6a.events.JAuthenticationInformationAnswer;
  40. import org.jdiameter.api.s6a.events.JAuthenticationInformationRequest;
  41. import org.jdiameter.api.s6a.events.JCancelLocationAnswer;
  42. import org.jdiameter.api.s6a.events.JCancelLocationRequest;
  43. import org.jdiameter.api.s6a.events.JDeleteSubscriberDataAnswer;
  44. import org.jdiameter.api.s6a.events.JDeleteSubscriberDataRequest;
  45. import org.jdiameter.api.s6a.events.JInsertSubscriberDataAnswer;
  46. import org.jdiameter.api.s6a.events.JInsertSubscriberDataRequest;
  47. import org.jdiameter.api.s6a.events.JNotifyAnswer;
  48. import org.jdiameter.api.s6a.events.JNotifyRequest;
  49. import org.jdiameter.api.s6a.events.JPurgeUEAnswer;
  50. import org.jdiameter.api.s6a.events.JPurgeUERequest;
  51. import org.jdiameter.api.s6a.events.JResetAnswer;
  52. import org.jdiameter.api.s6a.events.JResetRequest;
  53. import org.jdiameter.api.s6a.events.JUpdateLocationAnswer;
  54. import org.jdiameter.api.s6a.events.JUpdateLocationRequest;
  55. import org.jdiameter.client.api.ISessionFactory;
  56. import org.jdiameter.client.impl.app.s6a.IClientS6aSessionData;
  57. import org.jdiameter.client.impl.app.s6a.S6aClientSessionImpl;
  58. import org.jdiameter.common.api.app.IAppSessionDataFactory;
  59. import org.jdiameter.common.api.app.s6a.IS6aMessageFactory;
  60. import org.jdiameter.common.api.app.s6a.IS6aSessionData;
  61. import org.jdiameter.common.api.app.s6a.IS6aSessionFactory;
  62. import org.jdiameter.common.api.data.ISessionDatasource;
  63. import org.jdiameter.server.impl.app.s6a.IServerS6aSessionData;
  64. import org.jdiameter.server.impl.app.s6a.S6aServerSessionImpl;
  65. import org.slf4j.Logger;
  66. import org.slf4j.LoggerFactory;
  67. /**
  68. *
  69. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  70. * @author <a href="mailto:richard.good@smilecoms.com"> Richard Good </a>
  71. * @author <a href="mailto:paul.carter-brown@smilecoms.com"> Paul Carter-Brown </a>
  72. */
  73. public class S6aSessionFactoryImpl implements IS6aSessionFactory, ServerS6aSessionListener, ClientS6aSessionListener, IS6aMessageFactory, StateChangeListener<AppSession> {
  74. private static final Logger logger = LoggerFactory.getLogger(S6aSessionFactoryImpl.class);
  75. protected ISessionFactory sessionFactory;
  76. protected ServerS6aSessionListener serverSessionListener;
  77. protected ClientS6aSessionListener clientSessionListener;
  78. protected IS6aMessageFactory messageFactory;
  79. protected StateChangeListener<AppSession> stateListener;
  80. protected ISessionDatasource iss;
  81. protected IAppSessionDataFactory<IS6aSessionData> sessionDataFactory;
  82. public S6aSessionFactoryImpl(SessionFactory sessionFactory) {
  83. super();
  84. this.sessionFactory = (ISessionFactory) sessionFactory;
  85. this.iss = this.sessionFactory.getContainer().getAssemblerFacility().getComponentInstance(ISessionDatasource.class);
  86. this.sessionDataFactory = (IAppSessionDataFactory<IS6aSessionData>) this.iss.getDataFactory(IS6aSessionData.class);
  87. }
  88. /**
  89. * @return the serverSessionListener
  90. */
  91. public ServerS6aSessionListener getServerSessionListener() {
  92. return serverSessionListener != null ? serverSessionListener : this;
  93. }
  94. /**
  95. * @param serverSessionListener
  96. * the serverSessionListener to set
  97. */
  98. public void setServerSessionListener(ServerS6aSessionListener serverSessionListener) {
  99. this.serverSessionListener = serverSessionListener;
  100. }
  101. /**
  102. * @return the serverSessionListener
  103. */
  104. public ClientS6aSessionListener getClientSessionListener() {
  105. return clientSessionListener != null ? clientSessionListener : this;
  106. }
  107. /**
  108. * @param serverSessionListener
  109. * the serverSessionListener to set
  110. */
  111. public void setClientSessionListener(ClientS6aSessionListener clientSessionListener) {
  112. this.clientSessionListener = clientSessionListener;
  113. }
  114. /**
  115. * @return the messageFactory
  116. */
  117. public IS6aMessageFactory getMessageFactory() {
  118. return messageFactory != null ? messageFactory: this;
  119. }
  120. /**
  121. * @param messageFactory
  122. * the messageFactory to set
  123. */
  124. public void setMessageFactory(IS6aMessageFactory messageFactory) {
  125. this.messageFactory = messageFactory;
  126. }
  127. /**
  128. * @return the stateListener
  129. */
  130. public StateChangeListener<AppSession> getStateListener() {
  131. return stateListener != null ? stateListener : this;
  132. }
  133. /**
  134. * @param stateListener
  135. * the stateListener to set
  136. */
  137. public void setStateListener(StateChangeListener<AppSession> stateListener) {
  138. this.stateListener = stateListener;
  139. }
  140. public AppSession getSession(String sessionId, Class<? extends AppSession> aClass) {
  141. if (sessionId == null) {
  142. throw new IllegalArgumentException("SessionId must not be null");
  143. }
  144. if (!this.iss.exists(sessionId)) {
  145. return null;
  146. }
  147. AppSession appSession = null;
  148. try {
  149. if (aClass == ServerS6aSession.class) {
  150. IServerS6aSessionData sessionData = (IServerS6aSessionData) this.sessionDataFactory.getAppSessionData(ServerS6aSession.class, sessionId);
  151. S6aServerSessionImpl serverSession = new S6aServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getServerSessionListener());
  152. serverSession.getSessions().get(0).setRequestListener(serverSession);
  153. appSession = serverSession;
  154. }
  155. else if (aClass == ClientS6aSession.class) {
  156. IClientS6aSessionData sessionData = (IClientS6aSessionData) this.sessionDataFactory.getAppSessionData(ClientS6aSession.class, sessionId);
  157. S6aClientSessionImpl clientSession = new S6aClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getClientSessionListener());
  158. clientSession.getSessions().get(0).setRequestListener(clientSession);
  159. appSession = clientSession;
  160. }
  161. else {
  162. throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ServerS6aSession.class + "]");
  163. }
  164. }
  165. catch (Exception e) {
  166. logger.error("Failure to obtain new S6a Session.", e);
  167. }
  168. return appSession;
  169. }
  170. /*
  171. * (non-Javadoc)
  172. * @see org.jdiameter.common.api.app.IAppSessionFactory#getNewSession(java.lang.String, java.lang.Class, org.jdiameter.api.ApplicationId, java.lang.Object[])
  173. */
  174. public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) {
  175. AppSession appSession = null;
  176. if (aClass == ServerS6aSession.class) {
  177. if (sessionId == null) {
  178. if (args != null && args.length > 0 && args[0] instanceof Request) {
  179. Request request = (Request) args[0];
  180. sessionId = request.getSessionId();
  181. }
  182. else {
  183. sessionId = this.sessionFactory.getSessionId();
  184. }
  185. }
  186. IServerS6aSessionData sessionData = (IServerS6aSessionData) this.sessionDataFactory.getAppSessionData(ServerS6aSession.class, sessionId);
  187. S6aServerSessionImpl serverSession = new S6aServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getServerSessionListener());
  188. iss.addSession(serverSession);
  189. serverSession.getSessions().get(0).setRequestListener(serverSession);
  190. appSession = serverSession;
  191. }
  192. else if (aClass == ClientS6aSession.class) {
  193. if (sessionId == null) {
  194. if (args != null && args.length > 0 && args[0] instanceof Request) {
  195. Request request = (Request) args[0];
  196. sessionId = request.getSessionId();
  197. }
  198. else {
  199. sessionId = this.sessionFactory.getSessionId();
  200. }
  201. }
  202. IClientS6aSessionData sessionData = (IClientS6aSessionData) this.sessionDataFactory.getAppSessionData(ClientS6aSession.class, sessionId);
  203. S6aClientSessionImpl clientSession = new S6aClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getClientSessionListener());
  204. iss.addSession(clientSession);
  205. clientSession.getSessions().get(0).setRequestListener(clientSession);
  206. appSession = clientSession;
  207. }
  208. else {
  209. throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ServerS6aSession.class + "]");
  210. }
  211. return appSession;
  212. }
  213. /*
  214. * (non-Javadoc)
  215. * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Enum, java.lang.Enum)
  216. */
  217. public void stateChanged(Enum oldState, Enum newState) {
  218. logger.info("Diameter S6a Session Factory :: stateChanged :: oldState[{}], newState[{}]", oldState, newState);
  219. }
  220. public long getApplicationId() {
  221. return 16777251;
  222. }
  223. /*
  224. * (non-Javadoc)
  225. * @see org.jdiameter.api.app.StateChangeListener#stateChanged(java.lang.Object, java.lang.Enum, java.lang.Enum)
  226. */
  227. public void stateChanged(AppSession source, Enum oldState, Enum newState) {
  228. logger.info("Diameter S6a Session Factory :: stateChanged :: Session, [{}], oldState[{}], newState[{}]", new Object[]{source, oldState, newState});
  229. }
  230. public JAuthenticationInformationAnswer createAuthenticationInformationAnswer(Answer answer) {
  231. return new JAuthenticationInformationAnswerImpl(answer);
  232. }
  233. public JAuthenticationInformationRequest createAuthenticationInformationRequest(Request request) {
  234. return new JAuthenticationInformationRequestImpl(request);
  235. }
  236. public JUpdateLocationRequest createUpdateLocationRequest(Request request) {
  237. return new JUpdateLocationRequestImpl(request);
  238. }
  239. public JUpdateLocationAnswer createUpdateLocationAnswer(Answer answer) {
  240. return new JUpdateLocationAnswerImpl(answer);
  241. }
  242. public JPurgeUERequest createPurgeUERequest(Request request) {
  243. return new JPurgeUERequestImpl(request);
  244. }
  245. public JPurgeUEAnswer createPurgeUEAnswer(Answer answer) {
  246. return new JPurgeUEAnswerImpl(answer);
  247. }
  248. public JCancelLocationRequest createCancelLocationRequest(Request request) {
  249. return new JCancelLocationRequestImpl(request);
  250. }
  251. public JCancelLocationAnswer createCancelLocationAnswer(Answer answer) {
  252. return new JCancelLocationAnswerImpl(answer);
  253. }
  254. public JInsertSubscriberDataRequest createInsertSubscriberDataRequest(Request request) {
  255. return new JInsertSubscriberDataRequestImpl(request);
  256. }
  257. public JInsertSubscriberDataAnswer createInsertSubscriberDataAnswer(Answer answer) {
  258. return new JInsertSubscriberDataAnswerImpl(answer);
  259. }
  260. public JDeleteSubscriberDataRequest createDeleteSubscriberDataRequest(Request request) {
  261. return new JDeleteSubscriberDataRequestImpl(request);
  262. }
  263. public JDeleteSubscriberDataAnswer createDeleteSubscriberDataAnswer(Answer answer) {
  264. return new JDeleteSubscriberDataAnswerImpl(answer);
  265. }
  266. public JResetRequest createResetRequest(Request request) {
  267. return new JResetRequestImpl(request);
  268. }
  269. public JResetAnswer createResetAnswer(Answer answer) {
  270. return new JResetAnswerImpl(answer);
  271. }
  272. public JNotifyRequest createNotifyRequest(Request request) {
  273. return new JNotifyRequestImpl(request);
  274. }
  275. public JNotifyAnswer createNotifyAnswer(Answer answer) {
  276. return new JNotifyAnswerImpl(answer);
  277. }
  278. public void doAuthenticationInformationRequestEvent(ServerS6aSession appSession, JAuthenticationInformationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  279. logger.info("Diameter S6a Session Factory :: doAuthenticationInformationRequest :: appSession[{}], Request[{}]", appSession, request);
  280. }
  281. public void doPurgeUERequestEvent(ServerS6aSession appSession, JPurgeUERequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  282. logger.info("Diameter S6a Session Factory :: doPurgeUERequest :: appSession[{}], Request[{}]", appSession, request);
  283. }
  284. public void doUpdateLocationRequestEvent(ServerS6aSession appSession, JUpdateLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  285. logger.info("Diameter S6a Session Factory :: doUpdateLocationRequest :: appSession[{}], Request[{}]", appSession, request);
  286. }
  287. public void doNotifyRequestEvent(ServerS6aSession appSession, JNotifyRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  288. logger.info("Diameter S6a Session Factory :: doNotifyRequest :: appSession[{}], Request[{}]", appSession, request);
  289. }
  290. public void doCancelLocationAnswerEvent(ServerS6aSession appSession, JCancelLocationRequest request, JCancelLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  291. logger.info("Diameter S6a Session Factory :: doCancelLocationAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  292. }
  293. public void doInsertSubscriberDataAnswerEvent(ServerS6aSession appSession, JInsertSubscriberDataRequest request, JInsertSubscriberDataAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  294. logger.info("Diameter S6a Session Factory :: doInsertSubscriberDataAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  295. }
  296. public void doDeleteSubscriberDataAnswerEvent(ServerS6aSession appSession, JDeleteSubscriberDataRequest request, JDeleteSubscriberDataAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  297. logger.info("Diameter S6a Session Factory :: doDeleteSubscriberDataAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  298. }
  299. public void doResetAnswerEvent(ServerS6aSession appSession, JResetRequest request, JResetAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  300. logger.info("Diameter S6a Session Factory :: doResetAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  301. }
  302. public void doOtherEvent(AppSession appSession, AppRequestEvent request, AppAnswerEvent answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  303. logger.info("Diameter S6a Session Factory :: doOtherEvent :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  304. }
  305. public void doCancelLocationRequestEvent(ClientS6aSession appSession, JCancelLocationRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  306. logger.info("Diameter S6a Session Factory :: doCancelLocationRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request});
  307. }
  308. public void doInsertSubscriberDataRequestEvent(ClientS6aSession appSession, JInsertSubscriberDataRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  309. logger.info("Diameter S6a Session Factory :: doInsertSubscriberDataRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request});
  310. }
  311. public void doDeleteSubscriberDataRequestEvent(ClientS6aSession appSession, JDeleteSubscriberDataRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  312. logger.info("Diameter S6a Session Factory :: doDeleteSubscriberDataRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request});
  313. }
  314. public void doResetRequestEvent(ClientS6aSession appSession, JResetRequest request) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  315. logger.info("Diameter S6a Session Factory :: doResetRequest :: appSession[{}], Request[{}]", new Object[]{appSession, request});
  316. }
  317. public void doAuthenticationInformationAnswerEvent(ClientS6aSession appSession, JAuthenticationInformationRequest request, JAuthenticationInformationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  318. logger.info("Diameter S6a Session Factory :: doAuthenticationInformationAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  319. }
  320. public void doPurgeUEAnswerEvent(ClientS6aSession appSession, JPurgeUERequest request, JPurgeUEAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  321. logger.info("Diameter S6a Session Factory :: doPurgeUEAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  322. }
  323. public void doUpdateLocationAnswerEvent(ClientS6aSession appSession, JUpdateLocationRequest request, JUpdateLocationAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  324. logger.info("Diameter S6a Session Factory :: doUpdateLocationAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  325. }
  326. public void doNotifyAnswerEvent(ClientS6aSession appSession, JNotifyRequest request, JNotifyAnswer answer) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
  327. logger.info("Diameter S6a Session Factory :: doNotifyAnswer :: appSession[{}], Request[{}], Answer[{}]", new Object[]{appSession, request, answer});
  328. }
  329. }