PageRenderTime 42ms CodeModel.GetById 35ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/deleteconnection/MGW.java

http://mobicents.googlecode.com/
Java | 114 lines | 66 code | 27 blank | 21 comment | 3 complexity | d2a0ddf787d77064ef2dc3b420f6749c 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.mgcp.stack.test.deleteconnection;
 24
 25import jain.protocol.ip.mgcp.JainMgcpCommandEvent;
 26import jain.protocol.ip.mgcp.JainMgcpEvent;
 27import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
 28import jain.protocol.ip.mgcp.message.Constants;
 29import jain.protocol.ip.mgcp.message.DeleteConnectionResponse;
 30import jain.protocol.ip.mgcp.message.parms.ReturnCode;
 31
 32import java.util.TooManyListenersException;
 33
 34import org.apache.log4j.Logger;
 35import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
 36import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
 37
 38public class MGW implements JainMgcpExtendedListener {
 39
 40	private static Logger logger = Logger.getLogger(MGW.class);
 41	private boolean responseSent = false;
 42
 43	JainMgcpStackProviderImpl mgwProvider;
 44	private boolean sendFailedResponse = false;
 45
 46	public MGW(JainMgcpStackProviderImpl mgwProvider, boolean sendFailedResponse) {
 47		this(mgwProvider);
 48		this.sendFailedResponse = sendFailedResponse;
 49	}
 50
 51	public MGW(JainMgcpStackProviderImpl mgwProvider) {
 52		this.mgwProvider = mgwProvider;
 53		try {
 54			this.mgwProvider.addJainMgcpListener(this);
 55		} catch (TooManyListenersException e) {
 56			e.printStackTrace();
 57			DeleteConnectionTest.fail("Unexpected Exception");
 58		}
 59	}
 60
 61	public void checkState() {
 62		DeleteConnectionTest.assertTrue("Expect to sent DLCX Response", responseSent);
 63	}
 64
 65	public void transactionEnded(int handle) {
 66		logger.info("transactionEnded " + handle);
 67
 68	}
 69
 70	public void transactionRxTimedOut(JainMgcpCommandEvent command) {
 71		logger.info("transactionRxTimedOut " + command);
 72
 73	}
 74
 75	public void transactionTxTimedOut(JainMgcpCommandEvent command) {
 76		logger.info("transactionTxTimedOut " + command);
 77
 78	}
 79
 80	public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
 81		logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
 82
 83		switch (jainmgcpcommandevent.getObjectIdentifier()) {
 84		case Constants.CMD_DELETE_CONNECTION:
 85
 86			DeleteConnectionResponse response = null;
 87			if (this.sendFailedResponse) {
 88				response = new DeleteConnectionResponse(jainmgcpcommandevent.getSource(), ReturnCode.Unknown_Call_ID);
 89				response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
 90			} else {
 91				response = new DeleteConnectionResponse(jainmgcpcommandevent.getSource(),
 92						ReturnCode.Transaction_Executed_Normally);
 93
 94				response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
 95			}
 96			mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
 97
 98			responseSent = true;
 99
100			break;
101		default:
102			logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
103			break;
104
105		}
106
107	}
108
109	public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
110		logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
111
112	}
113
114}