Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package performance.uas;
  
  
  import java.util.Timer;
  
This is the UAS application for performance testing

Author(s):
Vladimir Ralev
 
 public class Shootme implements SipListener {
 
     private static AddressFactory addressFactory;
 
     private static MessageFactory messageFactory;
 
     private static HeaderFactory headerFactory;
 
     private static SipStack sipStack;
     
     private static SipFactory sipFactory;
     
     private static SipProvider sipProvider
     
     private static Timer timer = new Timer();
 
     private static final String myAddress = "127.0.0.1";
 
     private static final int myPort = 5080;
 
     protected static final String usageString = "java "
             + Shootme.class.getCanonicalName() + " \n"
             + ">>>> is your class path set to the root?";
 
 	private static final long BYE_DELAY = 60000;
 
 	private static final String TIMER_USER = "sipp-timer";
 
     private static void usage() {
         ..println();
         System.exit(0);
     }
 
     class ByeTask extends TimerTask {
         Dialog dialog;
         
         public ByeTask(Dialog dialog)  {
             this. = dialog;
         }
         public void run () {
             try {
                Request byeRequest = this..createRequest(.);
                ClientTransaction ct = .getNewClientTransaction(byeRequest);
                .sendRequest(ct);
                 = null;
             } catch (Exception ex) {
                 ex.printStackTrace();                
             }
 
         }
     }
     
     public void processRequest(RequestEvent requestEvent) {
         final Request request = requestEvent.getRequest();
         final ServerTransaction serverTransactionId = requestEvent.getServerTransaction();
 
         if (request.getMethod().equals(.)) {
             processInvite(requestEventserverTransactionId);
         } else if (request.getMethod().equals(.)) {
             processAck(requestEventserverTransactionId);
         } else if (request.getMethod().equals(.)) {
             processBye(requestEventserverTransactionId);
        } else if (request.getMethod().equals(.)) {
            processCancel(requestEventserverTransactionId);
        }
    }
    public void processResponse(ResponseEvent responseEvent) {
    }

    
Process the ACK request.
    public void processAck(RequestEvent requestEvent,
            ServerTransaction serverTransaction) {
    	final Dialog dialog = requestEvent.getDialog();
    	final RequestExt request = (RequestExtrequestEvent.getRequest();
    		.schedule(new ByeTask(dialog), ) ;
    	}
    }

    
Process the invite request.
    public void processInvite(RequestEvent requestEvent,
            ServerTransaction serverTransaction) {
        final Request request = requestEvent.getRequest();
        final SipProvider sipProvider = (SipProviderrequestEvent.getSource();
        ServerTransaction st = serverTransaction;        
        try {
        	if (st == null) {
        		st = sipProvider.getNewServerTransaction(request);
            }
        	sipProvider.getNewDialog(st);
        	final String toTag = ""+System.nanoTime();
            Response response = .createResponse(.,
                    request);            
            ToHeader toHeader = (ToHeaderresponse.getHeader(.);
            toHeader.setTag(toTag); // Application is supposed to set.            
			// Creates a dialog only for non trying responses				
            st.sendResponse(response);
            response = .createResponse(.,
                    request);
            final Address address = .createAddress("Shootme <sip:"
                    +  + ":" +  + ">");
            final ContactHeader contactHeader = 
                    .createContactHeader(address);
            response.addHeader(contactHeader);
            toHeader = (ToHeaderresponse.getHeader(.);
            toHeader.setTag(toTag); // Application is supposed to set.
            st.sendResponse(response);
        } catch (Exception ex) {
            ex.printStackTrace();
            //System.exit(0);
        }
    }


    
Process the bye request.
    public void processBye(RequestEvent requestEvent,
            ServerTransaction serverTransactionId) {
        final Request request = requestEvent.getRequest();
        final Dialog dialog = requestEvent.getDialog();
        try {
            final Response response = .createResponse(200, request);
            if(serverTransactionId == null) {
            	serverTransactionId = ((SipProvider)requestEvent.getSource()).getNewServerTransaction(request);
            }
            serverTransactionId.sendResponse(response);
        } catch (Exception ex) {
            ex.printStackTrace();
            //System.exit(0);
        }
    }
    public void processCancel(RequestEvent requestEvent,
            ServerTransaction serverTransactionId) {
    }
    public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
    	Request request = null;
    	if(timeoutEvent.getClientTransaction() == null) {
    		request = timeoutEvent.getServerTransaction().getRequest();
    	} else {
    		request = timeoutEvent.getClientTransaction().getRequest();
    	}
    	//System.out.println(request);
    }
    public void init() {        
         = null;
         = SipFactory.getInstance();
        .setPathName("gov.nist");
        Properties properties = new Properties();
        properties.setProperty("javax.sip.STACK_NAME""shootme");
        // You need 16 for logging traces. 32 for debug + traces.
        // Your code will limp at 32 but it is best for debugging.
        properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL""0");
        properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT""false");
        properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT""off");        
        properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
                "shootmedebug.txt");
        properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
        "shootmelog.txt");
        properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER",
        "true");
        properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE""4");
        properties.setProperty("gov.nist.javax.sip.RECEIVE_UDP_BUFFER_SIZE""65536");
        properties.setProperty("gov.nist.javax.sip.SEND_UDP_BUFFER_SIZE""65536");
        properties.setProperty("gov.nist.javax.sip.CONGESTION_CONTROL_ENABLED""false");
//      properties.setProperty("gov.nist.javax.sip.MESSAGE_PARSER_FACTORY", CharsMsgParserFactory.class.getName());
//		properties.setProperty("gov.nist.javax.sip.TIMER_CLASS_NAME", ScheduledExecutorSipTimer.class.getName());
//      properties.setProperty("gov.nist.javax.sip.TIMER_CLASS_NAME", HashWheelSipTimer.class.getName());
        try {
            // Create SipStack object
             = .createSipStack(properties);
        } catch (PeerUnavailableException e) {
            // could not find
            // gov.nist.jain.protocol.ip.sip.SipStackImpl
            // in the classpath
            e.printStackTrace();
            ..println(e.getMessage());
            if (e.getCause() != null)
                e.getCause().printStackTrace();
            System.exit(0);
        }
        try {
             = .createHeaderFactory();
             = .createAddressFactory();
             = .createMessageFactory();
            ListeningPoint lp = .createListeningPoint("127.0.0.1",
                    "udp");
            Shootme listener = this;
             = .createSipProvider(lp);
            .addSipListener(listener);
        } catch (Exception ex) {
            ex.printStackTrace();
            usage();
        }
    }
    public static void main(String args[]) {
        new Shootme().init();
    }
    public void processIOException(IOExceptionEvent exceptionEvent) {
    }
    public void processTransactionTerminated(
            TransactionTerminatedEvent transactionTerminatedEvent) {
    	Request request = null;
    	if(transactionTerminatedEvent.getClientTransaction() == null) {
    		request = transactionTerminatedEvent.getServerTransaction().getRequest();
    	} else {
    		request = transactionTerminatedEvent.getClientTransaction().getRequest();
    	}
    	//System.out.println(request);
    }
    public void processDialogTerminated(
            DialogTerminatedEvent dialogTerminatedEvent) {
    	Dialog dialog = dialogTerminatedEvent.getDialog();
    	//System.out.println(dialog);
    }
New to GrepCode? Check out our FAQ X