Source Code Cross Referenced for Shootme.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » test » load » leakcheck » busy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » test.load.leakcheck.busy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test.load.leakcheck.busy;
002:
003:        import javax.sip.*;
004:        import javax.sip.address.*;
005:        import javax.sip.header.*;
006:        import javax.sip.message.*;
007:        import java.util.*;
008:
009:        /**
010:         * This class is a UAC template. Shootist is the guy that shoots and shootme is
011:         * the guy that gets shot.
012:         * 
013:         * @author M. Ranganathan
014:         */
015:
016:        public class Shootme implements  SipListener {
017:
018:            private static AddressFactory addressFactory;
019:
020:            private static MessageFactory messageFactory;
021:
022:            private static HeaderFactory headerFactory;
023:
024:            private static SipStack sipStack;
025:
026:            private static final String myAddress = "127.0.0.1";
027:
028:            private static final int myPort = 5070;
029:
030:            protected ServerTransaction inviteTid;
031:
032:            private int counter;
033:
034:            class Ttask extends TimerTask {
035:
036:                public Ttask() {
037:                    new Timer().schedule(this , 0, 20000);
038:                }
039:
040:                /*
041:                 * (non-Javadoc)
042:                 * 
043:                 * @see java.util.TimerTask#run()
044:                 */
045:                public void run() {
046:                    System.gc();
047:                    long freemem = Runtime.getRuntime().totalMemory();
048:                    System.out.println("mem = " + freemem);
049:                }
050:
051:            }
052:
053:            class ApplicationData {
054:                protected int ackCount;
055:            }
056:
057:            protected static final String usageString = "java "
058:                    + "examples.shootist.Shootist \n"
059:                    + ">>>> is your class path set to the root?";
060:
061:            private static void usage() {
062:                System.out.println(usageString);
063:                System.exit(0);
064:
065:            }
066:
067:            public void processRequest(RequestEvent requestEvent) {
068:                Request request = requestEvent.getRequest();
069:                ServerTransaction serverTransactionId = requestEvent
070:                        .getServerTransaction();
071:
072:                /**
073:                 * System.out.println("\n\nRequest " + request.getMethod() + " received
074:                 * at " + sipStack.getStackName() + " with server transaction id " +
075:                 * serverTransactionId);
076:                 */
077:
078:                if (request.getMethod().equals(Request.INVITE)) {
079:                    processInvite(requestEvent, serverTransactionId);
080:                } else if (request.getMethod().equals(Request.ACK)) {
081:                    processAck(requestEvent, serverTransactionId);
082:                } else if (request.getMethod().equals(Request.BYE)) {
083:                    processBye(requestEvent, serverTransactionId);
084:                }
085:
086:            }
087:
088:            /**
089:             * Process the ACK request. Send the bye and complete the call flow.
090:             */
091:            public void processAck(RequestEvent requestEvent,
092:                    ServerTransaction serverTransaction) {
093:                SipProvider sipProvider = (SipProvider) requestEvent
094:                        .getSource();
095:                System.out.println("sip provider: " + sipProvider);
096:                try {
097:                    System.out.println("shootme: got an ACK "
098:                            + requestEvent.getRequest());
099:                } catch (Exception ex) {
100:                    ex.printStackTrace();
101:                    System.exit(0);
102:                }
103:            }
104:
105:            /**
106:             * Process the invite request.
107:             */
108:            public void processInvite(RequestEvent requestEvent,
109:                    ServerTransaction serverTransaction) {
110:                SipProvider sipProvider = (SipProvider) requestEvent
111:                        .getSource();
112:                Request request = requestEvent.getRequest();
113:
114:                if (counter == 99)
115:                    new Ttask();
116:                this .counter++;
117:
118:                try {
119:
120:                    Response response = messageFactory.createResponse(
121:                            Response.BUSY_HERE, request);
122:                    ToHeader toHeader = (ToHeader) response
123:                            .getHeader(ToHeader.NAME);
124:                    toHeader.setTag("4321"); // Application is supposed to set.
125:                    Address address = addressFactory
126:                            .createAddress("Shootme <sip:" + myAddress + ":"
127:                                    + myPort + ">");
128:                    ContactHeader contactHeader = headerFactory
129:                            .createContactHeader(address);
130:                    response.addHeader(contactHeader);
131:                    if (serverTransaction == null) {
132:                        serverTransaction = sipProvider
133:                                .getNewServerTransaction(request);
134:                    }
135:                    serverTransaction.sendResponse(response);
136:
137:                } catch (Exception ex) {
138:                    ex.printStackTrace();
139:                    System.exit(0);
140:                }
141:            }
142:
143:            /**
144:             * Process the bye request.
145:             */
146:            public void processBye(RequestEvent requestEvent,
147:                    ServerTransaction serverTransactionId) {
148:                SipProvider sipProvider = (SipProvider) requestEvent
149:                        .getSource();
150:                System.out.println("sip provider: " + sipProvider);
151:                Request request = requestEvent.getRequest();
152:                try {
153:                    System.out.println("shootme:  got a bye sending OK.");
154:                    Response response = messageFactory.createResponse(200,
155:                            request, null, null);
156:                    serverTransactionId.sendResponse(response);
157:                    System.out.println("Dialog State is "
158:                            + serverTransactionId.getDialog().getState());
159:
160:                } catch (Exception ex) {
161:                    ex.printStackTrace();
162:                    System.exit(0);
163:
164:                }
165:            }
166:
167:            public void processResponse(ResponseEvent responseReceivedEvent) {
168:                System.out.println("Got a response");
169:                Response response = (Response) responseReceivedEvent
170:                        .getResponse();
171:                Transaction tid = responseReceivedEvent.getClientTransaction();
172:
173:                System.out
174:                        .println("Response received with client transaction id "
175:                                + tid + ":\n" + response);
176:                try {
177:                    if (response.getStatusCode() == Response.BUSY_HERE
178:                            && ((CSeqHeader) response
179:                                    .getHeader(CSeqHeader.NAME)).getMethod()
180:                                    .equals(Request.INVITE)) {
181:                        if (tid != this .inviteTid) {
182:                            new Exception().printStackTrace();
183:                            System.exit(0);
184:                        }
185:                        Dialog dialog = tid.getDialog();
186:                        // Save the tags for the dialog here.
187:                        Request request = tid.getRequest();
188:                        dialog.sendAck(request);
189:                    }
190:                    Dialog dialog = tid.getDialog();
191:                    System.out.println("Dalog State = " + dialog.getState());
192:                } catch (Exception ex) {
193:                    ex.printStackTrace();
194:                    System.exit(0);
195:                }
196:
197:            }
198:
199:            public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
200:                Transaction transaction;
201:                if (timeoutEvent.isServerTransaction()) {
202:                    transaction = timeoutEvent.getServerTransaction();
203:                } else {
204:                    transaction = timeoutEvent.getClientTransaction();
205:                }
206:                System.out.println("state = " + transaction.getState());
207:                System.out.println("dialog = " + transaction.getDialog());
208:                System.out.println("dialogState = "
209:                        + transaction.getDialog().getState());
210:                System.out.println("Transaction Time out");
211:            }
212:
213:            public void init() {
214:                SipFactory sipFactory = null;
215:                sipStack = null;
216:                sipFactory = SipFactory.getInstance();
217:                sipFactory.setPathName("gov.nist");
218:                Properties properties = new Properties();
219:                //ifdef SIMULATION
220:                /*
221:                 * properties.setProperty("javax.sip.IP_ADDRESS","129.6.55.62"); //else
222:                 */
223:                properties.setProperty("javax.sip.IP_ADDRESS", myAddress);
224:                //endif
225:                //
226:                properties.setProperty("javax.sip.RETRANSMISSION_FILTER",
227:                        "true");
228:                properties.setProperty("javax.sip.STACK_NAME", "shootme");
229:                // You need 16 for logging traces. 32 for debug + traces.
230:                // Your code will limp at 32 but it is best for debugging.
231:                properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0");
232:                properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
233:                        "shootmedebug.txt");
234:                // Guard against starvation.
235:                properties.setProperty("gov.nist.javax.sip.READ_TIMEOUT",
236:                        "1000");
237:                // properties.setProperty("gov.nist.javax.sip.MAX_MESSAGE_SIZE",
238:                // "4096");
239:                properties.setProperty(
240:                        "gov.nist.javax.sip.CACHE_SERVER_CONNECTIONS", "false");
241:
242:                try {
243:                    // Create SipStack object
244:                    sipStack = sipFactory.createSipStack(properties);
245:                    System.out.println("sipStack = " + sipStack);
246:                } catch (PeerUnavailableException e) {
247:                    // could not find
248:                    // gov.nist.jain.protocol.ip.sip.SipStackImpl
249:                    // in the classpath
250:                    e.printStackTrace();
251:                    System.err.println(e.getMessage());
252:                    if (e.getCause() != null)
253:                        e.getCause().printStackTrace();
254:                    System.exit(0);
255:                }
256:
257:                try {
258:                    headerFactory = sipFactory.createHeaderFactory();
259:                    addressFactory = sipFactory.createAddressFactory();
260:                    messageFactory = sipFactory.createMessageFactory();
261:                    ListeningPoint lp = sipStack.createListeningPoint(sipStack
262:                            .getIPAddress(), 5070, "udp");
263:                    ListeningPoint lp1 = sipStack.createListeningPoint(sipStack
264:                            .getIPAddress(), 5070, "tcp");
265:
266:                    Shootme listener = this ;
267:
268:                    SipProvider sipProvider = sipStack.createSipProvider(lp);
269:                    System.out.println("udp provider " + sipProvider);
270:                    sipProvider.addSipListener(listener);
271:                    sipProvider = sipStack.createSipProvider(lp1);
272:                    System.out.println("tcp provider " + sipProvider);
273:                    sipProvider.addSipListener(listener);
274:
275:                    System.gc();
276:                    long freemem = Runtime.getRuntime().totalMemory();
277:                    System.out.println("Current memory" + freemem);
278:
279:                } catch (Exception ex) {
280:                    System.out.println(ex.getMessage());
281:                    ex.printStackTrace();
282:                    usage();
283:                }
284:
285:            }
286:
287:            public void processIOException(IOExceptionEvent exceptionEvent) {
288:                System.out
289:                        .println("IOException occured while retransmitting requests:"
290:                                + exceptionEvent);
291:            }
292:
293:            public void processTransactionTerminated(
294:                    TransactionTerminatedEvent transactionTerminatedEvent) {
295:                System.out.println("Transaction Terminated event: "
296:                        + transactionTerminatedEvent);
297:            }
298:
299:            public void processDialogTerminated(
300:                    DialogTerminatedEvent dialogTerminatedEvent) {
301:                System.out.println("Dialog Terminated event: "
302:                        + dialogTerminatedEvent);
303:            }
304:
305:            public static void main(String args[]) {
306:                new Shootme().init();
307:            }
308:
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.