PageRenderTime 34ms CodeModel.GetById 22ms app.highlight 8ms RepoModel.GetById 1ms 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
  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
 23package org.mobicents.protocols.ss7.m3ua.impl.sg;
 24
 25import javolution.util.FastList;
 26
 27import org.apache.log4j.Logger;
 28import org.mobicents.protocols.ss7.m3ua.impl.Asp;
 29import org.mobicents.protocols.ss7.m3ua.impl.AspState;
 30import org.mobicents.protocols.ss7.m3ua.impl.TransitionState;
 31import org.mobicents.protocols.ss7.m3ua.impl.fsm.FSM;
 32import org.mobicents.protocols.ss7.m3ua.impl.fsm.State;
 33import org.mobicents.protocols.ss7.m3ua.impl.fsm.TransitionHandler;
 34import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
 35import org.mobicents.protocols.ss7.m3ua.message.MessageType;
 36import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
 37import org.mobicents.protocols.ss7.m3ua.parameter.Status;
 38import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
 39
 40/**
 41 * 
 42 * @author amit bhayani
 43 *
 44 */
 45public class RemAsTransActToActRemAspAct implements TransitionHandler {
 46
 47    private static final Logger logger = Logger.getLogger(RemAsTransActToActRemAspAct.class);
 48
 49    private RemAsImpl as = null;
 50    private FSM fsm;
 51
 52    public RemAsTransActToActRemAspAct(RemAsImpl as, FSM fsm) {
 53        this.as = as;
 54        this.fsm = fsm;
 55    }
 56
 57    public boolean process(State state) {
 58        try {
 59
 60            if (this.as.getTrafficModeType().getMode() == TrafficModeType.Broadcast) {
 61                // We don't handle this
 62                return false;
 63            }
 64
 65            RemAspImpl remAsp = (RemAspImpl) this.fsm.getAttribute(RemAsImpl.ATTRIBUTE_ASP);
 66
 67            if (this.as.getTrafficModeType().getMode() == TrafficModeType.Loadshare) {
 68                // Iterate through ASP's and send AS_ACTIVE to ASP's who
 69                // are INACTIVE
 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
 74                    if (remAspImpl.getState() == AspState.INACTIVE) {
 75                        Notify msg = createNotify(remAspImpl, Status.STATUS_AS_State_Change, Status.INFO_AS_ACTIVE);
 76                        remAspImpl.getAspFactory().write(msg);
 77                    }
 78                }
 79            } else if (this.as.getTrafficModeType().getMode() == TrafficModeType.Override) {
 80                // Look at 5.2.2. 1+1 Sparing, Backup Override
 81
 82                for (FastList.Node<Asp> n = this.as.getAspList().head(), end = this.as.getAspList()
 83                        .tail(); (n = n.getNext()) != end;) {
 84                    RemAspImpl remAspImpl = (RemAspImpl) n.getValue();
 85
 86                    // Transition the other ASP to INACTIVE
 87                    if (remAspImpl.getState() == AspState.ACTIVE
 88                            && remAspImpl.getName().compareTo(remAsp.getName()) != 0) {
 89                        Notify msg = createNotify(remAspImpl, Status.STATUS_Other, Status.INFO_Alternate_ASP_Active);
 90                        remAspImpl.getAspFactory().write(msg);
 91
 92                        // Transition this ASP to INACTIVE
 93                        remAspImpl.getFSM().signal(TransitionState.OTHER_ALTERNATE_ASP_ACTIVE);
 94
 95                        break;
 96                    }
 97                }
 98            }
 99
100            return true;
101        } catch (Exception e) {
102            logger.error(String.format("Error while translating Rem AS to INACTIVE. %s", this.fsm.toString()), e);
103        }
104        // something wrong
105        return false;
106    }
107
108    private Notify createNotify(RemAspImpl remAsp, int type, int info) {
109        Notify msg = (Notify) this.as.getM3UAProvider().getMessageFactory().createMessage(MessageClass.MANAGEMENT,
110                MessageType.NOTIFY);
111
112        Status status = this.as.getM3UAProvider().getParameterFactory().createStatus(type, info);
113        msg.setStatus(status);
114
115        if (remAsp.getASPIdentifier() != null) {
116            msg.setASPIdentifier(remAsp.getASPIdentifier());
117        }
118
119        msg.setRoutingContext(this.as.getRoutingContext());
120
121        return msg;
122    }
123
124}