01: package test.load.concurrency;
02:
03: import java.util.Properties;
04: import javax.sip.SipException;
05: import javax.sip.SipFactory;
06: import javax.sip.SipStack;
07: import javax.sip.address.AddressFactory;
08: import javax.sip.header.HeaderFactory;
09: import javax.sip.message.MessageFactory;
10:
11: /**
12: * @author M. Ranganathan
13: *
14: */
15: public class ProtocolObjects {
16: static AddressFactory addressFactory;
17:
18: static MessageFactory messageFactory;
19:
20: static HeaderFactory headerFactory;
21:
22: static SipStack sipStack;
23:
24: static int logLevel = 0;
25:
26: public static String logFileDirectory = "";
27:
28: public static String transport = "udp";
29:
30: static void init(String stackname, boolean autoDialog) {
31: SipFactory sipFactory = null;
32:
33: sipFactory = SipFactory.getInstance();
34: sipFactory.setPathName("gov.nist");
35: Properties properties = new Properties();
36: properties.setProperty("javax.sip.STACK_NAME", stackname);
37:
38: // The following properties are specific to nist-sip
39: // and are not necessarily part of any other jain-sip
40: // implementation.
41: properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
42: logFileDirectory + stackname + "debuglog.txt");
43: properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
44: logFileDirectory + stackname + "log.txt");
45:
46: properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT",
47: (autoDialog ? "on" : "off"));
48:
49: properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE",
50: "8");
51: properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER",
52: "true");
53:
54: // Set to 0 in your production code for max speed.
55: // You need 16 for logging traces. 32 for debug + traces.
56: // Your code will limp at 32 but it is best for debugging.
57: properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL",
58: new Integer(logLevel).toString());
59:
60: try {
61: // Create SipStack object
62: sipStack = sipFactory.createSipStack(properties);
63:
64: System.out.println("createSipStack " + sipStack);
65: } catch (Exception e) {
66: // could not find
67: // gov.nist.jain.protocol.ip.sip.SipStackImpl
68: // in the classpath
69: e.printStackTrace();
70: System.err.println(e.getMessage());
71: throw new RuntimeException("Stack failed to initialize");
72: }
73:
74: try {
75: headerFactory = sipFactory.createHeaderFactory();
76: addressFactory = sipFactory.createAddressFactory();
77: messageFactory = sipFactory.createMessageFactory();
78: } catch (SipException ex) {
79: ex.printStackTrace();
80: throw new RuntimeException(ex);
81: }
82: }
83:
84: public static void destroy() {
85: sipStack.stop();
86: }
87:
88: public static void start() throws Exception {
89: sipStack.start();
90:
91: }
92: }
|