PageRenderTime 35ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/map/map-impl/src/main/java/org/mobicents/protocols/ss7/map/MAPServiceBaseImpl.java

http://mobicents.googlecode.com/
Java | 178 lines | 85 code | 20 blank | 73 comment | 4 complexity | cd383b79948584f160f5e413abc52a4f 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.protocols.ss7.map;
  23. import java.util.List;
  24. import java.util.concurrent.CopyOnWriteArrayList;
  25. import org.mobicents.protocols.ss7.map.api.MAPApplicationContext;
  26. import org.mobicents.protocols.ss7.map.api.MAPException;
  27. import org.mobicents.protocols.ss7.map.api.MAPParsingComponentException;
  28. import org.mobicents.protocols.ss7.map.api.MAPProvider;
  29. import org.mobicents.protocols.ss7.map.api.MAPDialog;
  30. import org.mobicents.protocols.ss7.map.api.MAPServiceBase;
  31. import org.mobicents.protocols.ss7.map.api.MAPServiceListener;
  32. import org.mobicents.protocols.ss7.map.api.dialog.MAPProviderError;
  33. import org.mobicents.protocols.ss7.map.api.errors.MAPErrorMessage;
  34. import org.mobicents.protocols.ss7.sccp.parameter.SccpAddress;
  35. import org.mobicents.protocols.ss7.tcap.api.TCAPException;
  36. import org.mobicents.protocols.ss7.tcap.api.tc.dialog.Dialog;
  37. import org.mobicents.protocols.ss7.tcap.asn.comp.ComponentType;
  38. import org.mobicents.protocols.ss7.tcap.asn.comp.Invoke;
  39. import org.mobicents.protocols.ss7.tcap.asn.comp.OperationCode;
  40. import org.mobicents.protocols.ss7.tcap.asn.comp.Parameter;
  41. import org.mobicents.protocols.ss7.tcap.asn.comp.Problem;
  42. /**
  43. * This class must be the super class of all MAP services
  44. *
  45. * @author sergey vetyutnev
  46. *
  47. */
  48. public abstract class MAPServiceBaseImpl implements MAPServiceBase {
  49. protected Boolean _isActivated = false;
  50. //protected Set<MAPServiceListener> serviceListeners = new HashSet<MAPServiceListener>();
  51. protected List<MAPServiceListener> serviceListeners = new CopyOnWriteArrayList<MAPServiceListener>();
  52. protected MAPProviderImpl mapProviderImpl = null;
  53. protected MAPServiceBaseImpl(MAPProviderImpl mapProviderImpl) {
  54. this.mapProviderImpl = mapProviderImpl;
  55. }
  56. public MAPProvider getMAPProvider() {
  57. return this.mapProviderImpl;
  58. }
  59. /**
  60. * Creation a MAP Dialog implementation for the specific service
  61. *
  62. * @param appCntx
  63. * @param tcapDialog
  64. * @return
  65. */
  66. protected abstract MAPDialogImpl createNewDialogIncoming(MAPApplicationContext appCntx, Dialog tcapDialog);
  67. /**
  68. * Creating new outgoing TCAP Dialog. Used when creating a new outgoing MAP
  69. * Dialog
  70. *
  71. * @param origAddress
  72. * @param destAddress
  73. * @return
  74. * @throws MAPException
  75. */
  76. protected Dialog createNewTCAPDialog(SccpAddress origAddress, SccpAddress destAddress) throws MAPException {
  77. try {
  78. return this.mapProviderImpl.getTCAPProvider().getNewDialog(origAddress, destAddress);
  79. } catch (TCAPException e) {
  80. throw new MAPException(e.getMessage(), e);
  81. }
  82. }
  83. public abstract void processComponent(ComponentType compType, OperationCode oc, Parameter parameter, MAPDialog mapDialog, Long invokeId, Long linkedId)
  84. throws MAPParsingComponentException;
  85. /**
  86. * Adding MAP Dialog into MAPProviderImpl.dialogs Used when creating a new
  87. * outgoing MAP Dialog
  88. *
  89. * @param dialog
  90. */
  91. protected void putMAPDialogIntoCollection(MAPDialogImpl dialog) {
  92. this.mapProviderImpl.addDialog((MAPDialogImpl) dialog);
  93. }
  94. protected void addMAPServiceListener(MAPServiceListener mapServiceListener) {
  95. this.serviceListeners.add(mapServiceListener);
  96. }
  97. protected void removeMAPServiceListener(MAPServiceListener mapServiceListener) {
  98. this.serviceListeners.remove(mapServiceListener);
  99. }
  100. /**
  101. * {@inheritDoc}
  102. */
  103. public MAPApplicationContext getMAPv1ApplicationContext(int operationCode, Invoke invoke) {
  104. return null;
  105. }
  106. /**
  107. * This method is invoked when MAPProviderImpl.onInvokeTimeOut() is invoked.
  108. * An InvokeTimeOut may be a normal situation for the component class 2, 3,
  109. * or 4. In this case checkInvokeTimeOut() should return true and deliver to
  110. * the MAP-user correct indication
  111. *
  112. * @param dialog
  113. * @param invoke
  114. * @return
  115. */
  116. public boolean checkInvokeTimeOut(MAPDialog dialog, Invoke invoke) {
  117. return false;
  118. }
  119. /**
  120. * {@inheritDoc}
  121. */
  122. public boolean isActivated() {
  123. return this._isActivated;
  124. }
  125. /**
  126. * {@inheritDoc}
  127. */
  128. public void acivate() {
  129. this._isActivated = true;
  130. }
  131. /**
  132. * {@inheritDoc}
  133. */
  134. public void deactivate() {
  135. this._isActivated = false;
  136. // TODO: abort all active dialogs ?
  137. }
  138. protected void deliverErrorComponent(MAPDialog mapDialog, Long invokeId, MAPErrorMessage mapErrorMessage) {
  139. for (MAPServiceListener serLis : this.serviceListeners) {
  140. serLis.onErrorComponent(mapDialog, invokeId, mapErrorMessage);
  141. }
  142. }
  143. protected void deliverRejectComponent(MAPDialog mapDialog, Long invokeId, Problem problem) {
  144. for (MAPServiceListener serLis : this.serviceListeners) {
  145. serLis.onRejectComponent(mapDialog, invokeId, problem);
  146. }
  147. }
  148. protected void deliverProviderErrorComponent(MAPDialog mapDialog, Long invokeId, MAPProviderError providerError) {
  149. for (MAPServiceListener serLis : this.serviceListeners) {
  150. serLis.onProviderErrorComponent(mapDialog, invokeId, providerError);
  151. }
  152. }
  153. protected void deliverInvokeTimeout(MAPDialog mapDialog, Invoke invoke) {
  154. for (MAPServiceListener serLis : this.serviceListeners) {
  155. serLis.onInvokeTimeout(mapDialog, invoke.getInvokeId());
  156. }
  157. }
  158. }