PageRenderTime 58ms CodeModel.GetById 48ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 121 lines | 70 code | 27 blank | 24 comment | 1 complexity | b358dadc86ea718817c567c6fdd54f94 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.Notify;
 30import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier;
 31import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
 32import jain.protocol.ip.mgcp.message.parms.EventName;
 33import jain.protocol.ip.mgcp.message.parms.NotifiedEntity;
 34import jain.protocol.ip.mgcp.pkg.MgcpEvent;
 35import jain.protocol.ip.mgcp.pkg.PackageName;
 36
 37import org.apache.log4j.Logger;
 38import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
 39import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
 40
 41public class CA implements JainMgcpExtendedListener {
 42
 43	private static Logger logger = Logger.getLogger(CA.class);
 44
 45	private JainMgcpStackProviderImpl caProvider;
 46	private int mgStack = 0;
 47	private boolean responseReceived = false;
 48
 49	public CA(JainMgcpStackProviderImpl caProvider, JainMgcpStackProviderImpl mgwProvider) {
 50		this.caProvider = caProvider;
 51		mgStack = mgwProvider.getJainMgcpStack().getPort();
 52	}
 53
 54	public void sendNotify() {
 55
 56		try {
 57			caProvider.addJainMgcpListener(this);
 58
 59			EndpointIdentifier endpointID = new EndpointIdentifier("media/trunk/Announcement/enp-1", "127.0.0.1:"
 60					+ mgStack);
 61
 62			Notify notify = new Notify(this, endpointID, caProvider.getUniqueRequestIdentifier(),
 63					new EventName[] { new EventName(PackageName.Announcement, MgcpEvent.oc, new ConnectionIdentifier(
 64							"1")) });
 65			notify.setTransactionHandle(caProvider.getUniqueTransactionHandler());
 66
 67			// TODO We are forced to set the NotifiedEntity, but this should
 68			// happen automatically. Fix this in MGCP Stack
 69			NotifiedEntity notifiedEntity = new NotifiedEntity("127.0.0.1", "127.0.0.1", mgStack);
 70			notify.setNotifiedEntity(notifiedEntity);
 71
 72			caProvider.sendMgcpEvents(new JainMgcpEvent[] { notify });
 73
 74			logger.debug(" Notify command sent for TxId " + notify.getTransactionHandle());
 75		} catch (Exception e) {
 76			// TODO Auto-generated catch block
 77			e.printStackTrace();
 78			NotifyTest.fail("Unexpected Exception");
 79		}
 80	}
 81
 82	public void checkState() {
 83		NotifyTest.assertTrue("Expect to receive NTFY Response", responseReceived);
 84
 85	}
 86
 87	public void transactionEnded(int handle) {
 88		logger.info("transactionEnded " + handle);
 89
 90	}
 91
 92	public void transactionRxTimedOut(JainMgcpCommandEvent command) {
 93		logger.info("transactionRxTimedOut " + command);
 94
 95	}
 96
 97	public void transactionTxTimedOut(JainMgcpCommandEvent command) {
 98		logger.info("transactionTxTimedOut " + command);
 99
100	}
101
102	public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
103		logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
104	}
105
106	public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
107		logger.debug("processMgcpResponseEvent = " + jainmgcpresponseevent);
108		switch (jainmgcpresponseevent.getObjectIdentifier()) {
109		case Constants.RESP_NOTIFY:
110			responseReceived = true;
111			break;
112		default:
113			logger.warn("This RESPONSE is unexpected " + jainmgcpresponseevent);
114			responseReceived = false;
115			break;
116
117		}
118
119	}
120
121}