/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/as/AspImpl.java

http://mobicents.googlecode.com/ · Java · 166 lines · 67 code · 38 blank · 61 comment · 0 complexity · 95718ba353a81188fee0cb37e9561801 MD5 · raw file

  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.m3ua.impl.as;
  23. import javolution.xml.XMLFormat;
  24. import javolution.xml.stream.XMLStreamException;
  25. import org.mobicents.protocols.ss7.m3ua.M3UAProvider;
  26. import org.mobicents.protocols.ss7.m3ua.impl.Asp;
  27. import org.mobicents.protocols.ss7.m3ua.impl.AspFactory;
  28. import org.mobicents.protocols.ss7.m3ua.impl.AspState;
  29. import org.mobicents.protocols.ss7.m3ua.impl.TransitionState;
  30. /**
  31. * @author amit bhayani
  32. */
  33. public class AspImpl extends Asp {
  34. public AspImpl() {
  35. }
  36. public AspImpl(String name, M3UAProvider m3UAProvider, AspFactory aspFactory) {
  37. super(name, m3UAProvider, aspFactory);
  38. // Define states
  39. fsm.createState(AspState.DOWN_SENT.toString());
  40. fsm.createState(AspState.DOWN.toString());
  41. fsm.createState(AspState.UP_SENT.toString());
  42. fsm.createState(AspState.INACTIVE.toString());
  43. fsm.createState(AspState.ACTIVE_SENT.toString());
  44. fsm.createState(AspState.ACTIVE.toString());
  45. fsm.createState(AspState.INACTIVE_SENT.toString());
  46. fsm.setStart(AspState.DOWN.toString());
  47. fsm.setEnd(AspState.DOWN.toString());
  48. // Define Transitions
  49. // ******************************************************************/
  50. // DOWN /
  51. // ******************************************************************/
  52. fsm.createTransition(TransitionState.COMM_UP, AspState.DOWN.toString(), AspState.UP_SENT.toString());
  53. // .setHandler(new AspTransDwnToAspUpSnt(this, this.fsm));
  54. fsm.createTransition(TransitionState.COMM_DOWN, AspState.DOWN.toString(), AspState.DOWN.toString());
  55. // ******************************************************************/
  56. // UP_SENT/
  57. // ******************************************************************/
  58. // TODO Keep sending ASP_UP. Also wrong logic here, every ASP will send
  59. // ASP_UP ?
  60. fsm.createTimeoutTransition(AspState.UP_SENT.toString(), AspState.UP_SENT.toString(), 2000).setHandler(
  61. new AspTransDwnToAspUpSnt(this, this.fsm));
  62. fsm.createTransition(TransitionState.ASP_INACTIVE, AspState.UP_SENT.toString(), AspState.INACTIVE.toString());
  63. fsm.createTransition(TransitionState.ASP_ACTIVE_SENT, AspState.UP_SENT.toString(),
  64. AspState.ACTIVE_SENT.toString());
  65. fsm.createTransition(TransitionState.ASP_DOWN_SENT, AspState.UP_SENT.toString(), AspState.DOWN_SENT.toString());
  66. fsm.createTransition(TransitionState.COMM_DOWN, AspState.UP_SENT.toString(), AspState.DOWN.toString());
  67. // ******************************************************************/
  68. // ACTIVE_SENT/
  69. // ******************************************************************/
  70. // TODO Keep sending ASP_ACTIVE ?
  71. fsm.createTimeoutTransition(AspState.ACTIVE_SENT.toString(), AspState.ACTIVE_SENT.toString(), 2000);
  72. fsm.createTransition(TransitionState.ASP_ACTIVE_ACK, AspState.ACTIVE_SENT.toString(),
  73. AspState.ACTIVE.toString());
  74. // .setHandler(new AspTransActSntToAct(this, this.fsm));
  75. fsm.createTransition(TransitionState.ASP_DOWN_SENT, AspState.ACTIVE_SENT.toString(),
  76. AspState.DOWN_SENT.toString());
  77. fsm.createTransition(TransitionState.COMM_DOWN, AspState.ACTIVE_SENT.toString(), AspState.DOWN.toString());
  78. // ******************************************************************/
  79. // ACTIVE/
  80. // ******************************************************************/
  81. fsm.createTransition(TransitionState.ASP_INACTIVE_SENT, AspState.ACTIVE.toString(),
  82. AspState.INACTIVE_SENT.toString());
  83. // .setHandler(new AspTransActToInactSnt(this, this.fsm));
  84. fsm.createTransition(TransitionState.OTHER_ALTERNATE_ASP_ACTIVE, AspState.ACTIVE.toString(),
  85. AspState.INACTIVE.toString());
  86. fsm.createTransition(TransitionState.ASP_DOWN_SENT, AspState.ACTIVE.toString(), AspState.DOWN_SENT.toString());
  87. fsm.createTransition(TransitionState.COMM_DOWN, AspState.ACTIVE.toString(), AspState.DOWN.toString());
  88. // .setHandler(new AspTransActToDwn(this, this.fsm));
  89. // ******************************************************************/
  90. // INACTIVE/
  91. // ******************************************************************/
  92. fsm.createTransition(TransitionState.COMM_DOWN, AspState.INACTIVE.toString(), AspState.DOWN.toString());
  93. // .setHandler(new AspTransInactToDwn(this, this.fsm));
  94. fsm.createTransition(TransitionState.ASP_ACTIVE_SENT, AspState.INACTIVE.toString(),
  95. AspState.ACTIVE_SENT.toString());
  96. fsm.createTransition(TransitionState.ASP_DOWN_SENT, AspState.INACTIVE.toString(), AspState.DOWN_SENT.toString());
  97. // ******************************************************************/
  98. // INACTIVE_SENT/
  99. // ******************************************************************/
  100. // TODO keep sending INACTIVE ASP ?
  101. fsm.createTimeoutTransition(AspState.INACTIVE_SENT.toString(), AspState.INACTIVE_SENT.toString(), 2000);
  102. // TODO Take care of this .setHandler(new AspTransActToInactSnt(this,
  103. // this.fsm));
  104. fsm.createTransition(TransitionState.ASP_INACTIVE_ACK, AspState.INACTIVE_SENT.toString(),
  105. AspState.INACTIVE.toString());
  106. fsm.createTransition(TransitionState.ASP_DOWN_SENT, AspState.INACTIVE_SENT.toString(),
  107. AspState.DOWN_SENT.toString());
  108. fsm.createTransition(TransitionState.COMM_DOWN, AspState.INACTIVE_SENT.toString(), AspState.DOWN.toString());
  109. // ******************************************************************/
  110. // DOWN_SENT/
  111. // ******************************************************************/
  112. fsm.createTransition(TransitionState.ASP_DOWN_ACK, AspState.DOWN_SENT.toString(), AspState.DOWN.toString());
  113. fsm.createTransition(TransitionState.COMM_DOWN, AspState.DOWN_SENT.toString(), AspState.DOWN.toString());
  114. }
  115. /**
  116. * XML Serialization/Deserialization
  117. */
  118. protected static final XMLFormat<AspImpl> ASP_IMPL_XML = new XMLFormat<AspImpl>(AspImpl.class) {
  119. @Override
  120. public void read(javolution.xml.XMLFormat.InputElement xml, AspImpl aspImpl) throws XMLStreamException {
  121. ASP_XML.read(xml, aspImpl);
  122. }
  123. @Override
  124. public void write(AspImpl aspImpl, javolution.xml.XMLFormat.OutputElement xml) throws XMLStreamException {
  125. ASP_XML.write(aspImpl, xml);
  126. }
  127. };
  128. }