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