/protocols/ss7/m3ua/impl/src/main/java/org/mobicents/protocols/ss7/m3ua/impl/sg/RemAsImpl.java

http://mobicents.googlecode.com/ · Java · 137 lines · 64 code · 25 blank · 48 comment · 0 complexity · 2faf7841215a8a4ac16013488ec8791a 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.sg;
  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.As;
  27. import org.mobicents.protocols.ss7.m3ua.impl.AsState;
  28. import org.mobicents.protocols.ss7.m3ua.impl.TransitionState;
  29. import org.mobicents.protocols.ss7.m3ua.impl.as.AsImpl;
  30. import org.mobicents.protocols.ss7.m3ua.impl.fsm.FSM;
  31. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
  32. import org.mobicents.protocols.ss7.m3ua.parameter.RoutingKey;
  33. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  34. /**
  35. *
  36. * @author amit bhayani
  37. */
  38. public class RemAsImpl extends As {
  39. public RemAsImpl() {
  40. super();
  41. }
  42. public RemAsImpl(String name, RoutingContext rc, RoutingKey rk, TrafficModeType trMode, M3UAProvider provider) {
  43. super(name, rc, rk, trMode, provider);
  44. }
  45. /*
  46. * (non-Javadoc)
  47. *
  48. * @see org.mobicents.protocols.ss7.m3ua.impl.As#init()
  49. */
  50. @Override
  51. public void init() {
  52. fsm = new FSM(this.name);
  53. // Define states
  54. fsm.createState(AsState.DOWN.toString());
  55. fsm.createState(AsState.ACTIVE.toString());
  56. fsm.createState(AsState.INACTIVE.toString());
  57. fsm.createState(AsState.PENDING.toString()).setOnTimeOut(new RemAsStatePenTimeout(this, this.fsm), 2000);
  58. fsm.setStart(AsState.DOWN.toString());
  59. fsm.setEnd(AsState.DOWN.toString());
  60. // Define Transitions
  61. // ******************************************************************/
  62. // STATE DOWN /
  63. // ******************************************************************/
  64. fsm.createTransition(TransitionState.ASP_UP, AsState.DOWN.toString(), AsState.INACTIVE.toString()).setHandler(
  65. new RemAsTransDwnToInact(this, this.fsm));
  66. // ******************************************************************/
  67. // STATE INACTIVE /
  68. // ******************************************************************/
  69. // TODO : Add Pluggable policy for AS?
  70. fsm.createTransition(TransitionState.ASP_ACTIVE, AsState.INACTIVE.toString(), AsState.ACTIVE.toString())
  71. .setHandler(new RemAsTransInactToAct(this, this.fsm));
  72. fsm.createTransition(TransitionState.ASP_DOWN, AsState.INACTIVE.toString(), AsState.DOWN.toString())
  73. .setHandler(new RemAsTransInactToDwn(this, this.fsm));
  74. fsm.createTransition(TransitionState.ASP_UP, AsState.INACTIVE.toString(), AsState.INACTIVE.toString())
  75. .setHandler(new RemAsTransInactToInact(this, this.fsm));
  76. // ******************************************************************/
  77. // STATE ACTIVE /
  78. // ******************************************************************/
  79. fsm.createTransition(TransitionState.ASP_INACTIVE, AsState.ACTIVE.toString(), AsState.PENDING.toString())
  80. .setHandler(new RemAsTransActToPendRemAspInac(this, this.fsm));
  81. fsm.createTransition(TransitionState.ASP_DOWN, AsState.ACTIVE.toString(), AsState.PENDING.toString())
  82. .setHandler(new RemAsTransActToPendRemAspDwn(this, this.fsm));
  83. fsm.createTransition(TransitionState.ASP_ACTIVE, AsState.ACTIVE.toString(), AsState.ACTIVE.toString())
  84. .setHandler(new RemAsTransActToActRemAspAct(this, this.fsm));
  85. fsm.createTransition(TransitionState.ASP_UP, AsState.ACTIVE.toString(), AsState.PENDING.toString()).setHandler(
  86. new RemAsTransActToPendRemAspInac(this, this.fsm));
  87. // ******************************************************************/
  88. // STATE PENDING /
  89. // ******************************************************************/
  90. fsm.createTransition(TransitionState.ASP_DOWN, AsState.PENDING.toString(), AsState.DOWN.toString()).setHandler(
  91. new RemAsNoTrans());
  92. fsm.createTransition(TransitionState.ASP_UP, AsState.PENDING.toString(), AsState.INACTIVE.toString())
  93. .setHandler(new RemAsNoTrans());
  94. fsm.createTransition(TransitionState.ASP_ACTIVE, AsState.PENDING.toString(), AsState.ACTIVE.toString())
  95. .setHandler(new RemAsTransPendToAct(this, this.fsm));
  96. fsm.createTransition(TransitionState.AS_DOWN, AsState.PENDING.toString(), AsState.DOWN.toString());
  97. fsm.createTransition(TransitionState.AS_INACTIVE, AsState.PENDING.toString(), AsState.INACTIVE.toString());
  98. }
  99. /**
  100. * XML Serialization/Deserialization
  101. */
  102. protected static final XMLFormat<RemAsImpl> REMAS_IMPL_XML = new XMLFormat<RemAsImpl>(RemAsImpl.class) {
  103. @Override
  104. public void read(javolution.xml.XMLFormat.InputElement xml, RemAsImpl asImpl) throws XMLStreamException {
  105. AS_XML.read(xml, asImpl);
  106. }
  107. @Override
  108. public void write(RemAsImpl asImpl, javolution.xml.XMLFormat.OutputElement xml) throws XMLStreamException {
  109. AS_XML.write(asImpl, xml);
  110. }
  111. };
  112. }