PageRenderTime 36ms CodeModel.GetById 13ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

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