/protocols/ss7/hardware/dialogic/java/src/main/java/org/mobicents/ss7/hardware/dialogic/DialogicTest.java

http://mobicents.googlecode.com/ · Java · 117 lines · 81 code · 26 blank · 10 comment · 3 complexity · 459cf5ddb6f96061049b230a293147cd MD5 · raw file

  1. package org.mobicents.ss7.hardware.dialogic;
  2. import java.io.IOException;
  3. import org.apache.log4j.Logger;
  4. import org.mobicents.protocols.ss7.mtp.Mtp3TransferPrimitive;
  5. public class DialogicTest {
  6. private static final Logger logger = Logger.getLogger(DialogicMtp3UserPart.class);
  7. // TODO: set the correct values of sourceModuleId & destinationModuleId
  8. private int sourceModuleId = 0;
  9. private int destinationModuleId = 0;
  10. private InterProcessCommunicator ipc = new InterProcessCommunicator(sourceModuleId, destinationModuleId);
  11. public void BoardTest() throws Exception {
  12. // starting two threads for listening
  13. MtpProcessReading p1 = new MtpProcessReading(1);
  14. MtpProcessReading p2 = new MtpProcessReading(2);
  15. Thread t1 = new Thread(p1);
  16. Thread t2 = new Thread(p2);
  17. t1.start();
  18. t2.start();
  19. Thread.sleep(5000);
  20. MtpProcessWriting p3 = new MtpProcessWriting(1);
  21. MtpProcessWriting p4 = new MtpProcessWriting(2);
  22. Thread t3 = new Thread(p3);
  23. Thread t4 = new Thread(p4);
  24. t3.start();
  25. t4.start();
  26. // working for 600 sec (10 min)
  27. Thread.sleep(600000);
  28. }
  29. private class MtpProcessReading implements Runnable {
  30. int num;
  31. public MtpProcessReading(int num) {
  32. this.num = num;
  33. }
  34. @Override
  35. public void run() {
  36. while( true ) {
  37. // reading the message
  38. byte[] buf = ipc.read();
  39. // logging the result
  40. StringBuilder sb = new StringBuilder();
  41. sb.append("Data read: Num=");
  42. sb.append(num);
  43. sb.append(": ");
  44. if (buf == null)
  45. sb.append("null");
  46. else {
  47. sb.append("length=");
  48. sb.append(buf.length);
  49. }
  50. logger.error(sb.toString());
  51. }
  52. }
  53. }
  54. private class MtpProcessWriting implements Runnable {
  55. int num;
  56. public MtpProcessWriting(int num) {
  57. this.num = num;
  58. }
  59. @Override
  60. public void run() {
  61. while( true ) {
  62. // writing the message
  63. // TODO: fill fields with correct values !!!
  64. int si = 3;
  65. int ni = 2;
  66. int mp = 0;
  67. int opc = 1;
  68. int dpc = 2;
  69. int sls = 0;
  70. byte[] data = new byte[10];
  71. Mtp3TransferPrimitive msg = new Mtp3TransferPrimitive(si, ni, mp, opc, dpc, sls, data);
  72. byte[] buf = msg.encodeMtp3();
  73. try {
  74. ipc.write(buf);
  75. logger.error("Data written: Num=" + num);
  76. } catch (IOException e) {
  77. // TODO Auto-generated catch block
  78. logger.error("Error data writing: Num=" + num);
  79. e.printStackTrace();
  80. }
  81. try {
  82. // we are sending a message per a second
  83. Thread.sleep(1000);
  84. } catch (InterruptedException e) {
  85. // TODO Auto-generated catch block
  86. e.printStackTrace();
  87. }
  88. }
  89. }
  90. }
  91. }