PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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