PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 137 lines | 64 code | 25 blank | 48 comment | 0 complexity | 2faf7841215a8a4ac16013488ec8791a 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.xml.XMLFormat;
 26import javolution.xml.stream.XMLStreamException;
 27
 28import org.mobicents.protocols.ss7.m3ua.M3UAProvider;
 29import org.mobicents.protocols.ss7.m3ua.impl.As;
 30import org.mobicents.protocols.ss7.m3ua.impl.AsState;
 31import org.mobicents.protocols.ss7.m3ua.impl.TransitionState;
 32import org.mobicents.protocols.ss7.m3ua.impl.as.AsImpl;
 33import org.mobicents.protocols.ss7.m3ua.impl.fsm.FSM;
 34import org.mobicents.protocols.ss7.m3ua.parameter.RoutingContext;
 35import org.mobicents.protocols.ss7.m3ua.parameter.RoutingKey;
 36import org.mobicents.protocols.ss7.m3ua.parameter.TrafficModeType;
 37
 38/**
 39 * 
 40 * @author amit bhayani
 41 */
 42public class RemAsImpl extends As {
 43
 44	public RemAsImpl() {
 45		super();
 46	}
 47
 48	public RemAsImpl(String name, RoutingContext rc, RoutingKey rk, TrafficModeType trMode, M3UAProvider provider) {
 49		super(name, rc, rk, trMode, provider);
 50	}
 51
 52	/*
 53	 * (non-Javadoc)
 54	 * 
 55	 * @see org.mobicents.protocols.ss7.m3ua.impl.As#init()
 56	 */
 57	@Override
 58	public void init() {
 59		fsm = new FSM(this.name);
 60
 61		// Define states
 62		fsm.createState(AsState.DOWN.toString());
 63		fsm.createState(AsState.ACTIVE.toString());
 64		fsm.createState(AsState.INACTIVE.toString());
 65		fsm.createState(AsState.PENDING.toString()).setOnTimeOut(new RemAsStatePenTimeout(this, this.fsm), 2000);
 66
 67		fsm.setStart(AsState.DOWN.toString());
 68		fsm.setEnd(AsState.DOWN.toString());
 69		// Define Transitions
 70
 71		// ******************************************************************/
 72		// STATE DOWN /
 73		// ******************************************************************/
 74		fsm.createTransition(TransitionState.ASP_UP, AsState.DOWN.toString(), AsState.INACTIVE.toString()).setHandler(
 75				new RemAsTransDwnToInact(this, this.fsm));
 76
 77		// ******************************************************************/
 78		// STATE INACTIVE /
 79		// ******************************************************************/
 80		// TODO : Add Pluggable policy for AS?
 81		fsm.createTransition(TransitionState.ASP_ACTIVE, AsState.INACTIVE.toString(), AsState.ACTIVE.toString())
 82				.setHandler(new RemAsTransInactToAct(this, this.fsm));
 83
 84		fsm.createTransition(TransitionState.ASP_DOWN, AsState.INACTIVE.toString(), AsState.DOWN.toString())
 85				.setHandler(new RemAsTransInactToDwn(this, this.fsm));
 86
 87		fsm.createTransition(TransitionState.ASP_UP, AsState.INACTIVE.toString(), AsState.INACTIVE.toString())
 88				.setHandler(new RemAsTransInactToInact(this, this.fsm));
 89
 90		// ******************************************************************/
 91		// STATE ACTIVE /
 92		// ******************************************************************/
 93		fsm.createTransition(TransitionState.ASP_INACTIVE, AsState.ACTIVE.toString(), AsState.PENDING.toString())
 94				.setHandler(new RemAsTransActToPendRemAspInac(this, this.fsm));
 95
 96		fsm.createTransition(TransitionState.ASP_DOWN, AsState.ACTIVE.toString(), AsState.PENDING.toString())
 97				.setHandler(new RemAsTransActToPendRemAspDwn(this, this.fsm));
 98
 99		fsm.createTransition(TransitionState.ASP_ACTIVE, AsState.ACTIVE.toString(), AsState.ACTIVE.toString())
100				.setHandler(new RemAsTransActToActRemAspAct(this, this.fsm));
101
102		fsm.createTransition(TransitionState.ASP_UP, AsState.ACTIVE.toString(), AsState.PENDING.toString()).setHandler(
103				new RemAsTransActToPendRemAspInac(this, this.fsm));
104
105		// ******************************************************************/
106		// STATE PENDING /
107		// ******************************************************************/
108		fsm.createTransition(TransitionState.ASP_DOWN, AsState.PENDING.toString(), AsState.DOWN.toString()).setHandler(
109				new RemAsNoTrans());
110
111		fsm.createTransition(TransitionState.ASP_UP, AsState.PENDING.toString(), AsState.INACTIVE.toString())
112				.setHandler(new RemAsNoTrans());
113
114		fsm.createTransition(TransitionState.ASP_ACTIVE, AsState.PENDING.toString(), AsState.ACTIVE.toString())
115				.setHandler(new RemAsTransPendToAct(this, this.fsm));
116
117		fsm.createTransition(TransitionState.AS_DOWN, AsState.PENDING.toString(), AsState.DOWN.toString());
118		fsm.createTransition(TransitionState.AS_INACTIVE, AsState.PENDING.toString(), AsState.INACTIVE.toString());
119	}
120
121	/**
122	 * XML Serialization/Deserialization
123	 */
124	protected static final XMLFormat<RemAsImpl> REMAS_IMPL_XML = new XMLFormat<RemAsImpl>(RemAsImpl.class) {
125
126		@Override
127		public void read(javolution.xml.XMLFormat.InputElement xml, RemAsImpl asImpl) throws XMLStreamException {
128			AS_XML.read(xml, asImpl);
129		}
130
131		@Override
132		public void write(RemAsImpl asImpl, javolution.xml.XMLFormat.OutputElement xml) throws XMLStreamException {
133			AS_XML.write(asImpl, xml);
134		}
135	};
136
137}