PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 100 lines | 55 code | 24 blank | 21 comment | 1 complexity | 02c511f314e0f892d2a215044d146670 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.notify;
 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.NotifyResponse;
 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
 45	public MGW(JainMgcpStackProviderImpl mgwProvider) {
 46		this.mgwProvider = mgwProvider;
 47		try {
 48			this.mgwProvider.addJainMgcpListener(this);
 49		} catch (TooManyListenersException e) {
 50			e.printStackTrace();
 51			NotifyTest.fail("Unexpected Exception");
 52		}
 53	}
 54
 55	public void checkState() {
 56		NotifyTest.assertTrue("Expect to sent NTFY Response", responseSent);
 57	}
 58
 59	public void transactionEnded(int handle) {
 60		logger.info("transactionEnded " + handle);
 61
 62	}
 63
 64	public void transactionRxTimedOut(JainMgcpCommandEvent command) {
 65		logger.info("transactionRxTimedOut " + command);
 66
 67	}
 68
 69	public void transactionTxTimedOut(JainMgcpCommandEvent command) {
 70		logger.info("transactionTxTimedOut " + command);
 71
 72	}
 73
 74	public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
 75		logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
 76
 77		switch (jainmgcpcommandevent.getObjectIdentifier()) {
 78		case Constants.CMD_NOTIFY:			
 79
 80			NotifyResponse response = new NotifyResponse(jainmgcpcommandevent.getSource(),
 81					ReturnCode.Transaction_Executed_Normally);
 82			response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
 83			mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
 84			responseSent = true;
 85
 86			break;
 87		default:
 88			logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
 89			break;
 90
 91		}
 92
 93	}
 94
 95	public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
 96		logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
 97
 98	}
 99
100}