PageRenderTime 33ms CodeModel.GetById 22ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 117 lines | 68 code | 28 blank | 21 comment | 1 complexity | 9d72e413f81b7c9dce77ed96202b8414 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.restartinprogress;
 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.RestartInProgress;
 30import jain.protocol.ip.mgcp.message.RestartInProgressResponse;
 31import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
 32import jain.protocol.ip.mgcp.message.parms.NotifiedEntity;
 33import jain.protocol.ip.mgcp.message.parms.RestartMethod;
 34
 35import org.apache.log4j.Logger;
 36import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
 37import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
 38import org.mobicents.protocols.mgcp.stack.test.auditendpoint.AuditEndpointTest;
 39
 40public class MGW implements JainMgcpExtendedListener {
 41
 42	private static Logger logger = Logger.getLogger(MGW.class);
 43	private boolean responseReceived = false;
 44	int caPort = 0;
 45
 46	JainMgcpStackProviderImpl mgwProvider;
 47
 48	public MGW(JainMgcpStackProviderImpl mgwProvider, int caPort) {
 49		this.mgwProvider = mgwProvider;
 50		this.caPort = caPort;
 51	}
 52
 53	public void sendRestartInProgress() {
 54
 55		try {
 56			this.mgwProvider.addJainMgcpListener(this);
 57
 58			EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/enp-1", "127.0.0.1:"
 59					+ caPort);
 60
 61			RestartInProgress restartInProgress = new RestartInProgress(this, endpointID, RestartMethod.Graceful);
 62
 63			restartInProgress.setTransactionHandle(mgwProvider.getUniqueTransactionHandler());
 64
 65			mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { restartInProgress });
 66
 67			logger.debug(" RestartInProgress command sent for TxId " + restartInProgress.getTransactionHandle());
 68		} catch (Exception e) {
 69			e.printStackTrace();
 70			AuditEndpointTest.fail("Unexpected Exception");
 71		}
 72	}
 73
 74	public void checkState() {
 75		RestartInProgressTest.assertTrue("Expect to Receive RSIP Response", responseReceived);
 76	}
 77
 78	public void transactionEnded(int handle) {
 79		logger.info("transactionEnded " + handle);
 80
 81	}
 82
 83	public void transactionRxTimedOut(JainMgcpCommandEvent command) {
 84		logger.info("transactionRxTimedOut " + command);
 85
 86	}
 87
 88	public void transactionTxTimedOut(JainMgcpCommandEvent command) {
 89		logger.info("transactionTxTimedOut " + command);
 90
 91	}
 92
 93	public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
 94		logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
 95
 96	}
 97
 98	public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
 99		logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
100
101		switch (jainmgcpresponseevent.getObjectIdentifier()) {
102		case Constants.RESP_RESTART_IN_PROGRESS:
103			RestartInProgressResponse response = (RestartInProgressResponse) jainmgcpresponseevent;
104
105			NotifiedEntity notifiedEntity = response.getNotifiedEntity();
106			RestartInProgressTest.assertNotNull(notifiedEntity);
107			RestartInProgressTest.assertEquals("127.0.0.1", notifiedEntity.getDomainName());
108			responseReceived = true;
109			break;
110		default:
111			logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
112			break;
113		}
114
115	}
116
117}