PageRenderTime 18ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 124 lines | 68 code | 23 blank | 33 comment | 19 complexity | 09434ee28282ef5b76a28339a6b51298 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.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.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.TransitionHandler;
  31. import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
  32. import org.mobicents.protocols.ss7.m3ua.message.MessageType;
  33. import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
  34. import org.mobicents.protocols.ss7.m3ua.parameter.Status;
  35. import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
  36. /**
  37. *
  38. * @author amit bhayani
  39. *
  40. */
  41. public class RemAsTransActToActRemAspAct implements TransitionHandler {
  42. private static final Logger logger = Logger.getLogger(RemAsTransActToActRemAspAct.class);
  43. private RemAsImpl as = null;
  44. private FSM fsm;
  45. public RemAsTransActToActRemAspAct(RemAsImpl as, FSM fsm) {
  46. this.as = as;
  47. this.fsm = fsm;
  48. }
  49. public boolean process(State state) {
  50. try {
  51. if (this.as.getTrafficModeType().getMode() == TrafficModeType.Broadcast) {
  52. // We don't handle this
  53. return false;
  54. }
  55. RemAspImpl remAsp = (RemAspImpl) this.fsm.getAttribute(RemAsImpl.ATTRIBUTE_ASP);
  56. if (this.as.getTrafficModeType().getMode() == TrafficModeType.Loadshare) {
  57. // Iterate through ASP's and send AS_ACTIVE to ASP's who
  58. // are INACTIVE
  59. for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList()
  60. .tail(); (n = n.getNext()) != end;) {
  61. RemAspImpl remAspImpl = (RemAspImpl) n.getValue();
  62. if (remAspImpl.getState() == AspState.INACTIVE) {
  63. Notify msg = createNotify(remAspImpl, Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
  64. remAspImpl.getAspFactory().write(msg);
  65. }
  66. }
  67. } else if (this.as.getTrafficModeType().getMode() == TrafficModeType.Override) {
  68. // Look at 5.2.2. 1+1 Sparing, Backup Override
  69. for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList()
  70. .tail(); (n = n.getNext()) != end;) {
  71. RemAspImpl remAspImpl = (RemAspImpl) n.getValue();
  72. // Transition the other ASP to INACTIVE
  73. if (remAspImpl.getState() == AspState.ACTIVE
  74. && remAspImpl.getName().compareTo(remAsp.getName()) != 0) {
  75. Notify msg = createNotify(remAspImpl, Status.STATUS_Other, Status.INFO_Alternate_ASP_Active);
  76. remAspImpl.getAspFactory().write(msg);
  77. // Transition this ASP to INACTIVE
  78. remAspImpl.getFSM().signal(TransitionState.OTHER_ALTERNATE_ASP_ACTIVE);
  79. break;
  80. }
  81. }
  82. }
  83. return true;
  84. } catch (Exception e) {
  85. logger.error(String.format("Error while translating Rem AS to INACTIVE. %s", this.fsm.toString()), e);
  86. }
  87. // something wrong
  88. return false;
  89. }
  90. private Notify createNotify(RemAspImpl remAsp, int type, int info) {
  91. Notify msg = (Notify) this.as.getM3UAProvider().getMessageFactory().createMessage(MessageClass.MANAGEMENT,
  92. MessageType.NOTIFY);
  93. Status status = this.as.getM3UAProvider().getParameterFactory().createStatus(type, info);
  94. msg.setStatus(status);
  95. if (remAsp.getASPIdentifier() != null) {
  96. msg.setASPIdentifier(remAsp.getASPIdentifier());
  97. }
  98. msg.setRoutingContext(this.as.getRoutingContext());
  99. return msg;
  100. }
  101. }