PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 84 lines | 46 code | 16 blank | 22 comment | 4 complexity | 5081422934425d3efde4468b03633962 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 org.apache.log4j.Logger;
26import org.mobicents.protocols.ss7.m3ua.impl.fsm.FSM;
27import org.mobicents.protocols.ss7.m3ua.impl.fsm.State;
28import org.mobicents.protocols.ss7.m3ua.impl.fsm.TransitionHandler;
29import org.mobicents.protocols.ss7.m3ua.message.MessageClass;
30import org.mobicents.protocols.ss7.m3ua.message.MessageType;
31import org.mobicents.protocols.ss7.m3ua.message.mgmt.Notify;
32import org.mobicents.protocols.ss7.m3ua.parameter.Status;
33
34public class RemAsTransActToActRemAspUp implements TransitionHandler {
35
36    private static final Logger logger = Logger.getLogger(RemAsTransActToActRemAspUp.class);
37
38    private RemAsImpl as = null;
39    private FSM fsm;
40
41    public RemAsTransActToActRemAspUp(RemAsImpl as, FSM fsm) {
42        this.as = as;
43        this.fsm = fsm;
44    }
45
46    public boolean process(State state) {
47        try {
48
49            RemAspImpl remAsp = (RemAspImpl) this.fsm.getAttribute(RemAsImpl.ATTRIBUTE_ASP);
50
51            if (remAsp == null) {
52                logger.error(String.format("No ASP found. %s", this.fsm.toString()));
53                return false;
54            }
55
56            // Send AS is ACTIVE notify
57            Notify msg = createNotify(remAsp);
58            remAsp.getAspFactory().write(msg);
59            return true;
60        } catch (Exception e) {
61            logger.error(String.format("Error while translating Rem AS to INACTIVE message. %s", this.fsm.toString()),
62                    e);
63        }
64        return false;
65    }
66
67    private Notify createNotify(RemAspImpl remAsp) {
68        Notify msg = (Notify) this.as.getM3UAProvider().getMessageFactory().createMessage(MessageClass.MANAGEMENT,
69                MessageType.NOTIFY);
70
71        Status status = this.as.getM3UAProvider().getParameterFactory().createStatus(Status.STATUS_AS_State_Change,
72                Status.INFO_AS_ACTIVE);
73        msg.setStatus(status);
74
75        if (remAsp.getASPIdentifier() != null) {
76            msg.setASPIdentifier(remAsp.getASPIdentifier());
77        }
78
79        msg.setRoutingContext(this.as.getRoutingContext());
80
81        return msg;
82    }
83
84}