PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 112 lines | 66 code | 25 blank | 21 comment | 3 complexity | 9088b1a60aad53c2d0abd27fd7de3e75 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.modifyconnection;
 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.ModifyConnectionResponse;
 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			ModifyConnectionTest.fail("Unexpected Exception");
 58		}
 59	}
 60
 61	public void checkState() {
 62		ModifyConnectionTest.assertTrue("Expect to sent MDCX 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 \n" + jainmgcpcommandevent);
 82
 83		switch (jainmgcpcommandevent.getObjectIdentifier()) {
 84		case Constants.CMD_MODIFY_CONNECTION:
 85			ModifyConnectionResponse response = null;
 86			if (this.sendFailedResponse) {
 87				response = new ModifyConnectionResponse(jainmgcpcommandevent.getSource(),
 88						ReturnCode.Endpoint_Insufficient_Resources);
 89			} else {
 90				response = new ModifyConnectionResponse(jainmgcpcommandevent.getSource(),
 91						ReturnCode.Transaction_Executed_Normally);
 92			}
 93			response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
 94			mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
 95
 96			responseSent = true;
 97
 98			break;
 99		default:
100			logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
101			break;
102
103		}
104
105	}
106
107	public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
108		logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
109
110	}
111
112}