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

http://mobicents.googlecode.com/ · Java · 105 lines · 45 code · 13 blank · 47 comment · 5 complexity · 215fa9acf0daca4b0082648684e6eff3 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.util.FastList;
  24. import org.apache.log4j.Logger;
  25. import org.mobicents.protocols.ss7.m3ua.impl.Asp;
  26. import org.mobicents.protocols.ss7.m3ua.impl.AspState;
  27. import org.mobicents.protocols.ss7.m3ua.impl.TransitionState;
  28. import org.mobicents.protocols.ss7.m3ua.impl.fsm.FSM;
  29. import org.mobicents.protocols.ss7.m3ua.impl.fsm.State;
  30. import org.mobicents.protocols.ss7.m3ua.impl.fsm.StateEventHandler;
  31. import org.mobicents.protocols.ss7.m3ua.impl.fsm.UnknownTransitionException;
  32. /**
  33. * {@link AsStatePenTimeout#onEvent(State)} is called when the pending timer
  34. * T(r) expires.
  35. *
  36. * @author amit bhayani
  37. *
  38. */
  39. public class AsStatePenTimeout implements StateEventHandler {
  40. private AsImpl as;
  41. private FSM fsm;
  42. private static final Logger logger = Logger.getLogger(AsStatePenTimeout.class);
  43. boolean inactive = false;
  44. public AsStatePenTimeout(AsImpl as, FSM fsm) {
  45. this.as = as;
  46. this.fsm = fsm;
  47. }
  48. /**
  49. * <p>
  50. * An active ASP has transitioned to ASP-INACTIVE or ASP DOWN and it was the
  51. * last remaining active ASP in the AS. A recovery timer T(r) SHOULD be
  52. * started, and all incoming signalling messages SHOULD be queued by the
  53. * SGP. If an ASP becomes ASP-ACTIVE before T(r) expires, the AS is moved to
  54. * the AS-ACTIVE state, and all the queued messages will be sent to the ASP.
  55. * </p>
  56. * <p>
  57. * If T(r) expires before an ASP becomes ASP-ACTIVE, and the SGP has no
  58. * alternative, the SGP may stop queuing messages and discard all previously
  59. * queued messages. The AS will move to the AS-INACTIVE state if at least
  60. * one ASP is in ASP-INACTIVE; otherwise, it will move to AS-DOWN state.
  61. * </p>
  62. */
  63. public void onEvent(State state) {
  64. //Clear the Pending Queue for this As
  65. this.as.clearPendingQueue();
  66. this.inactive = false;
  67. // check if there are any ASP's who are INACTIVE, transition to
  68. // INACTIVE else DOWN
  69. for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList().tail(); (n = n
  70. .getNext()) != end;) {
  71. Asp asp = n.getValue();
  72. if (asp.getState() == AspState.INACTIVE) {
  73. try {
  74. this.fsm.signal(TransitionState.AS_INACTIVE);
  75. inactive = true;
  76. break;
  77. } catch (UnknownTransitionException e) {
  78. logger.error(e.getMessage(), e);
  79. }
  80. }// if
  81. }// for
  82. if (!this.inactive) {
  83. // else transition to DOWN
  84. try {
  85. this.fsm.signal(TransitionState.AS_DOWN);
  86. inactive = true;
  87. } catch (UnknownTransitionException e) {
  88. logger.error(e.getMessage(), e);
  89. }
  90. }
  91. }
  92. }