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

http://mobicents.googlecode.com/ · Java · 116 lines · 56 code · 19 blank · 41 comment · 10 complexity · da89dac2a3ce44e20a903c0b9a992869 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.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.fsm.FSM;
  28. import org.mobicents.protocols.ss7.m3ua.impl.fsm.State;
  29. import org.mobicents.protocols.ss7.m3ua.impl.fsm.TransitionHandler;
  30. import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
  31. import org.mobicents.protocols.ss7.m3ua.message.MessageType;
  32. import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
  33. import org.mobicents.protocols.ss7.m3ua.parameter.Status;
  34. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  35. /**
  36. * <p>
  37. * Transition's the {@link RemAsImpl} from
  38. * {@link org.mobicents.protocols.ss7.m3ua.impl.AsState#PENDING} to
  39. * {@link org.mobicents.protocols.ss7.m3ua.impl.AsState#ACTIVE}. Send's
  40. * AS_ACTIVE notification to all {@link Asp} within this As that are
  41. * {@link AspState#ACTIVE}
  42. * </p>
  43. *
  44. * <p>
  45. * Also initiates sending of PayloadData from the pending queue of this As.
  46. * </p>
  47. *
  48. * @author amit bhayani
  49. *
  50. */
  51. public class RemAsTransPendToAct implements TransitionHandler {
  52. private static final Logger logger = Logger.getLogger(RemAsTransPendToAct.class);
  53. private RemAsImpl as = null;
  54. private FSM fsm;
  55. public RemAsTransPendToAct(RemAsImpl as, FSM fsm) {
  56. this.as = as;
  57. this.fsm = fsm;
  58. }
  59. public boolean process(State state) {
  60. if (this.as.getTrafficModeType().getMode() == TrafficModeType.Broadcast) {
  61. // We don't handle this
  62. return false;
  63. }
  64. try {
  65. // Iterate through ASP's and send AS_ACTIVE to ASP's who
  66. // are INACTIVE or ACTIVE
  67. for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList().tail(); (n = n
  68. .getNext()) != end;) {
  69. RemAspImpl remAspImpl = (RemAspImpl) n.getValue();
  70. if (remAspImpl.getState() == AspState.INACTIVE || remAspImpl.getState() == AspState.ACTIVE) {
  71. Notify msg = createNotify(remAspImpl);
  72. remAspImpl.getAspFactory().write(msg);
  73. }
  74. }// end of for
  75. // Send the PayloadData (if any) from pending queue to other side
  76. Asp causeAsp = (Asp) this.fsm.getAttribute(RemAsImpl.ATTRIBUTE_ASP);
  77. this.as.sendPendingPayloadData(causeAsp);
  78. return true;
  79. } catch (Exception e) {
  80. logger.error(String.format("Error while translating Rem AS to INACTIVE message. %s", this.fsm.toString()),
  81. e);
  82. }
  83. return false;
  84. }
  85. private Notify createNotify(RemAspImpl remAsp) {
  86. Notify msg = (Notify) this.as.getM3UAProvider().getMessageFactory()
  87. .createMessage(MessageClass.MANAGEMENT, MessageType.NOTIFY);
  88. Status status = this.as.getM3UAProvider().getParameterFactory()
  89. .createStatus(Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  90. msg.setStatus(status);
  91. if (remAsp.getASPIdentifier() != null) {
  92. msg.setASPIdentifier(remAsp.getASPIdentifier());
  93. }
  94. msg.setRoutingContext(this.as.getRoutingContext());
  95. return msg;
  96. }
  97. }