Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package performance.uas_uac;
  
  
  import java.io.FileReader;
 
 
 
 public class One implements SipListener{
 	private static SipStack sipStack;
 	private static ListeningPoint listeningPoint;
 	private static SipProvider sipProvider;
 	private static AddressFactory addressFactory;
 	private static MessageFactory messageFactory;
 	private static HeaderFactory headerFactory;
 	private static ContactHeader contactHeader = null;
 	private static String transport="udp";
 	
 	public static void main(String[] args) {
 		//Factorys
 		SipFactory sipFactory = SipFactory.getInstance();
 		sipFactory.setPathName("gov.nist");
 		
 		try {
 		} catch (PeerUnavailableException e) {
 		}
 		//Stack
 		try{
 			Properties properties = new Properties();
 			properties.setProperty("javax.sip.STACK_NAME""send");
 //			properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER", "true");
 //			properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", "2");
 //			properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "debug.txt");
 ////			properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "log.txt");
 			properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL""0");
 //			properties.setProperty("gov.nist.javax.sip.AGGRESSIVE_CLEANUP", "true");
 			 = sipFactory.createSipStack(properties);
 		}
 		catch (PeerUnavailableException e) {
 		}
 		
 		//Listening Point
 		try{
 		}
 		}
		}
		//SIP Provider
		try{
		}
		}
		try
		{
		}
		{
		}
		//File
		String lines=null;
		try {
//			reader = new BufferedReader(new FileReader("Info.txt"));
//			lines = reader.readLine();		
		    lines ="send1 | empf1";
			Vector<StringcallInformation = new Vector<String>();
			//Read the file
//			while (lines != null) {				
				callInformation.add(lines);
//				lines = reader.readLine();
//			}
			String[] currentLine = null;
			SIPClientTransaction sct = null;
			//Search the CalledNumber
			for(int u = 0; u < 100000; u++){
    			for (int i = 0; i < callInformation.size(); i++) {
    					//Get the Line
    					currentLine = callInformation.get(i).replaceAll(" ","").split("\\|");
    					//Get the Numbers
    					Request request = createMessage(currentLine[0],currentLine[1],i);
    	
    					//Send
    					ClientTransaction clientTransaction = .getNewClientTransaction(request);
    					
    					sct = (SIPClientTransactionclientTransaction;
    //					System.out.println(sct.getMessageChannel().getSIPStack().getActiveClientTransactionCount());
    					
    					//clientTransaction.setRetransmitTimer(10000);
    					clientTransaction.sendRequest();
    					//System.out.println("INVITE sent");
    					Thread.sleep(50);
    			}
    			if(u != 0 && u % 1500 == 0){
    				..println("I'll sleep..with ActiveClientTransactions: " +sct.getMessageChannel().getSIPStack().getActiveClientTransactionCount());
    				Thread.sleep(180000);
    				..println("ActiveClientTransactions: " +sct.getMessageChannel().getSIPStack().getActiveClientTransactionCount());
//    				System.out.println("DialogSize: "+sct.getMessageChannel().getSIPStack().dialogTable.size());
//    				System.out.println("EarlyDialogSize: "+sct.getMessageChannel().getSIPStack().earlyDialogTable.size());
//    				System.out.println("ForkedClientSize: "+sct.getMessageChannel().getSIPStack().forkedClientTransactionTable.size());
//    				System.out.println("MergeSize: "+sct.getMessageChannel().getSIPStack().mergeTable.size());
//    				System.out.println("TerminatedServerTxPendingAckSize: "+sct.getMessageChannel().getSIPStack().terminatedServerTransactionsPendingAck.size());
//    				System.out.println("ServerDialogMergeTestTableSize: "+sct.getMessageChannel().getSIPStack().serverDialogMergeTestTable.size());
//    				if(sct.getMessageChannel().getSIPStack().getActiveClientTransactionCount() > 0) {
//    				    for (Entry<String, SIPClientTransaction> entry : sct.getMessageChannel().getSIPStack().clientTransactionTable.entrySet()) {
//    				        System.out.println("Ctw: "+entry.getKey() + " , ctx " + entry.getValue().getMethod());
//                        }				    
//    				}
    			}
			}
//			System.out.println("last: "+System.currentTimeMillis());
catch (SipException e) {	
//		} catch (IOException e) {
//			e.printStackTrace();
//			System.err.println(e.getMessage());
catch (InterruptedException e){
		}
	}
	private static Request createMessage(String fromString tolong id){
		Request request = null;
		id += 1;//0 not allowed
		//Invite
		try {	
			// create From Header
			SipURI fromAddress = .createSipURI(from"send.com");
			Address fromNameAddress = .createAddress(fromAddress);
			fromNameAddress.setDisplayName(from);
			FromHeader fromHeader = .createFromHeader(fromNameAddress,"12345");
			// create To Header
			SipURI toAddress = .createSipURI(to"empf.com");
			Address toNameAddress = .createAddress(toAddress);
			toNameAddress.setDisplayName(to);
			ToHeader toHeader = .createToHeader(toNameAddressnull);
			// create Request URI
			SipURI requestURI = .createSipURI(from"127.0.0.1:5080");
			// Create ViaHeaders
			ArrayList viaHeaders = new ArrayList();
			ViaHeader viaHeader = .createViaHeader("127.0.0.1",
			viaHeaders.add(viaHeader);
			// Create a new CallId header
			//callIdHeader.setCallId("1");
			// Create a new Cseq header
			// Create a new MaxForwardsHeader
			// Create the request.
					callIdHeadercSeqHeaderfromHeadertoHeaderviaHeadersmaxForwards);
			// Create contact headers
			String host = "127.0.0.1";
			SipURI contactUrl = .createSipURI(fromhost);
			// Create the contact name address.
			SipURI contactURI = .createSipURI(fromhost);
			Address contactAddress = .createAddress(contactURI);
			// Add the contact address.
			contactAddress.setDisplayName(from);
catch (ParseException e) {
		}
		return request;
	}
	}
	public void processIOException(IOExceptionEvent arg0) {	
	    ..println("processIOException----------------------------------");
	}
	public void processRequest(RequestEvent requestEvent) {
		//Invite received
		if(requestEvent.getRequest().getMethod().equals(.)){
			//System.out.println("INVITE bekommen");
			try {	
				ServerTransaction serverTransaction = requestEvent.getServerTransaction();
				if(serverTransaction==null){
					serverTransaction = .getNewServerTransaction(requestEvent.getRequest());
				}
				Response responseRing = .createResponse(.requestEvent.getRequest());
				responseRing.addHeader();
				serverTransaction.sendResponse(responseRing);
				//System.out.println("Ringing sent");
				//System.out.println("Ringing sent");
				Response responseOk = .createResponse(.requestEvent.getRequest());
				serverTransaction.sendResponse(responseOk);
				//System.out.println("OK sent");
				//System.out.println("Ok sent");
catch (SipException e) {
				// TODO Auto-generated catch block
catch (InvalidArgumentException e) {
				// TODO Auto-generated catch block
catch (ParseException e) {
				// TODO Auto-generated catch block
			}
		}
		if(requestEvent.getRequest().getMethod().equals(.))
		{
			//System.out.println("ACK bekommen");
			//System.out.println("ACK bekommen");
			//System.out.println(requestEvent.getDialog());
		}
		if(requestEvent.getRequest().getMethod().equals(.))
		{
			//System.out.println("BYE bekommen");
			//System.out.println("Bye bekommen");
			//System.out.println(requestEvent.getDialog());
			Response responseOk;
			try {
				responseOk = .createResponse(.requestEvent.getRequest());
				ServerTransaction serverTransaction = requestEvent.getServerTransaction();
				serverTransaction.sendResponse(responseOk);
catch (ParseException e) {
				// TODO Auto-generated catch block
catch (SipException e) {
				// TODO Auto-generated catch block
catch (InvalidArgumentException e) {
				// TODO Auto-generated catch block
			}	
			//System.out.println("Ok (bye) sent");
			//System.out.println("OK (bye) sent");
		}
	}
	public void processResponse(ResponseEvent responseEvent) {
		if(responseEvent.getResponse().getStatusCode() == 180){
			//System.out.println("Ringing bekommen");
			//System.out.println("RINGING bekommen");
		}
		CSeqHeader cseq2 = (CSeqHeaderresponseEvent.getResponse().getHeader(.);
		if(responseEvent.getResponse().getStatusCode() == 200 && cseq2.getMethod().equals("INVITE")){
			//System.out.println("confirmed OK bekommen");
			//System.out.println("confirmed OK bekommen");
			try{
				Dialog dialog = responseEvent.getClientTransaction().getDialog();
				Request ack = dialog.createAck(cseq.getSeqNumber());
				//System.out.println("Ack sent");
				//System.out.println("ACK sent");
				dialog.sendAck(ack);
				//A sends a BYE
				Request byeRequest = dialog.createRequest(.);
				//System.out.println("BYE sent");
				//System.out.println("Bye sent");
			}catch (SipException e) {
			}
		}
		else if(responseEvent.getResponse().getStatusCode() == 200 && cseq2.getMethod().equals("BYE")){
			//System.out.println("terminated OK bekommen");
			//System.out.println("terminated OK bekommen");
		}
	}
	public void processTimeout(TimeoutEvent arg0) {
		//System.out.println("Timeout----------------------------------");
	    ..println("Timeout---------------------------------- CTX : " + arg0.getClientTransaction() + " STX : " + arg0.getServerTransaction());
	    new Exception().printStackTrace();
	}
	}
New to GrepCode? Check out our FAQ X