PageRenderTime 29ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 119 lines | 67 code | 22 blank | 30 comment | 17 complexity | 2ef41f4a0d992252ba01894220928400 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.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. public class RemAsTransInactToAct implements TransitionHandler {
  36. private static final Logger logger = Logger.getLogger(RemAsTransInactToAct.class);
  37. private RemAsImpl as = null;
  38. private FSM fsm;
  39. private int lbCount = 0;
  40. public RemAsTransInactToAct(RemAsImpl as, FSM fsm) {
  41. this.as = as;
  42. this.fsm = fsm;
  43. }
  44. public boolean process(State state) {
  45. try {
  46. if (this.as.getTrafficModeType().getMode() == TrafficModeType.Broadcast) {
  47. // We don't handle this
  48. return false;
  49. }
  50. // For Traffic Mode Type = load-balancing, need to check policy to
  51. // have 'minAspActiveForLb' ASP's ACTIVE before AS_ACTIVE NOTIFY is
  52. // sent.
  53. if (this.as.getTrafficModeType().getMode() == TrafficModeType.Loadshare) {
  54. lbCount = this.as.getMinAspActiveForLb();
  55. // Find out how many ASP's are ACTIVE now
  56. for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList()
  57. .tail(); (n = n.getNext()) != end;) {
  58. RemAspImpl remAspImpl = (RemAspImpl) n.getValue();
  59. if (remAspImpl.getState() == AspState.ACTIVE) {
  60. lbCount--;
  61. }
  62. }
  63. if (lbCount > 0) {
  64. // We still need more ASP ACTIVE before AS is ACTIVE
  65. return false;
  66. }
  67. }
  68. // Iterate through ASP's and send AS_ACTIVE to ASP's who
  69. // are INACTIVE or ACTIVE
  70. for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList()
  71. .tail(); (n = n.getNext()) != end;) {
  72. RemAspImpl remAspImpl = (RemAspImpl) n.getValue();
  73. if (remAspImpl.getState() == AspState.INACTIVE || remAspImpl.getState() == AspState.ACTIVE) {
  74. Notify msg = createNotify(remAspImpl);
  75. remAspImpl.getAspFactory().write(msg);
  76. }
  77. }
  78. return true;
  79. } catch (Exception e) {
  80. logger.error(String.format("Error while translating Rem AS to INACTIVE. %s", this.fsm.toString()), e);
  81. }
  82. // something wrong
  83. return false;
  84. }
  85. private Notify createNotify(RemAspImpl remAsp) {
  86. Notify msg = (Notify) this.as.getM3UAProvider().getMessageFactory().createMessage(MessageClass.MANAGEMENT,
  87. MessageType.NOTIFY);
  88. Status status = this.as.getM3UAProvider().getParameterFactory().createStatus(Status.STATUS_AS_State_Change,
  89. 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. }