/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. package org.mobicents.protocols.mgcp.stack.test.notify;
  23. import jain.protocol.ip.mgcp.JainMgcpCommandEvent;
  24. import jain.protocol.ip.mgcp.JainMgcpEvent;
  25. import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
  26. import jain.protocol.ip.mgcp.message.Constants;
  27. import jain.protocol.ip.mgcp.message.NotifyResponse;
  28. import jain.protocol.ip.mgcp.message.parms.ReturnCode;
  29. import java.util.TooManyListenersException;
  30. import org.apache.log4j.Logger;
  31. import org.mobicents.protocols.mgcp.stack.JainMgcpExtendedListener;
  32. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  33. public class MGW implements JainMgcpExtendedListener {
  34. private static Logger logger = Logger.getLogger(MGW.class);
  35. private boolean responseSent = false;
  36. JainMgcpStackProviderImpl mgwProvider;
  37. public MGW(JainMgcpStackProviderImpl mgwProvider) {
  38. this.mgwProvider = mgwProvider;
  39. try {
  40. this.mgwProvider.addJainMgcpListener(this);
  41. } catch (TooManyListenersException e) {
  42. e.printStackTrace();
  43. NotifyTest.fail("Unexpected Exception");
  44. }
  45. }
  46. public void checkState() {
  47. NotifyTest.assertTrue("Expect to sent NTFY Response", responseSent);
  48. }
  49. public void transactionEnded(int handle) {
  50. logger.info("transactionEnded " + handle);
  51. }
  52. public void transactionRxTimedOut(JainMgcpCommandEvent command) {
  53. logger.info("transactionRxTimedOut " + command);
  54. }
  55. public void transactionTxTimedOut(JainMgcpCommandEvent command) {
  56. logger.info("transactionTxTimedOut " + command);
  57. }
  58. public void processMgcpCommandEvent(JainMgcpCommandEvent jainmgcpcommandevent) {
  59. logger.info("processMgcpCommandEvent " + jainmgcpcommandevent);
  60. switch (jainmgcpcommandevent.getObjectIdentifier()) {
  61. case Constants.CMD_NOTIFY:
  62. NotifyResponse response = new NotifyResponse(jainmgcpcommandevent.getSource(),
  63. ReturnCode.Transaction_Executed_Normally);
  64. response.setTransactionHandle(jainmgcpcommandevent.getTransactionHandle());
  65. mgwProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
  66. responseSent = true;
  67. break;
  68. default:
  69. logger.warn("This REQUEST is unexpected " + jainmgcpcommandevent);
  70. break;
  71. }
  72. }
  73. public void processMgcpResponseEvent(JainMgcpResponseEvent jainmgcpresponseevent) {
  74. logger.info("processMgcpResponseEvent " + jainmgcpresponseevent);
  75. }
  76. }