Source Code Cross Referenced for Probe.java in  » Web-Server » Jigsaw » org » w3c » www » protocol » http » micp » 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 » Web Server » Jigsaw » org.w3c.www.protocol.http.micp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Probe.java
002:        // $Id: Probe.java,v 1.4 2000/08/16 21:38:05 ylafon Exp $  
003:        // (c) COPYRIGHT MIT and INRIA, 1997.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.www.protocol.http.micp;
007:
008:        import java.awt.Button;
009:        import java.awt.Color;
010:        import java.awt.Component;
011:        import java.awt.Container;
012:        import java.awt.Dimension;
013:        import java.awt.Frame;
014:        import java.awt.GridBagConstraints;
015:        import java.awt.GridBagLayout;
016:        import java.awt.Label;
017:        import java.awt.Panel;
018:        import java.awt.Window;
019:
020:        import java.awt.event.ActionEvent;
021:        import java.awt.event.ActionListener;
022:
023:        import java.net.DatagramPacket;
024:        import java.net.DatagramSocket;
025:        import java.net.InetAddress;
026:        import java.net.MulticastSocket;
027:        import java.net.UnknownHostException;
028:
029:        import java.io.IOException;
030:        import java.io.PrintStream;
031:
032:        import java.util.EventObject;
033:
034:        /**
035:         * A real piece of fun, try it !
036:         */
037:
038:        class Stats implements  MICP {
039:            int queries = 0;
040:            int hits = 0;
041:            String lasturl = null;
042:
043:            final synchronized void handle(int op, String url) {
044:                if (op == MICP_OP_QUERY)
045:                    queries++;
046:                else
047:                    hits++;
048:                lasturl = url;
049:            }
050:
051:            final synchronized int getQueries() {
052:                return queries;
053:            }
054:
055:            final synchronized int getHits() {
056:                return hits;
057:            }
058:
059:            final synchronized String getLastURL() {
060:                return lasturl;
061:            }
062:
063:        }
064:
065:        class MICPReader extends Thread {
066:            InetAddress addr = null;
067:            int port = -1;
068:            Stats stats = null;
069:            MulticastSocket socket = null;
070:            MICPReadWrite micprw = null;
071:
072:            public void run() {
073:                byte buffer[] = new byte[4096];
074:                MICPMessage msg = new MICPMessage();
075:                while (true) {
076:                    try {
077:                        DatagramPacket p = new DatagramPacket(buffer,
078:                                buffer.length);
079:                        socket.receive(p);
080:                        micprw.decode(p.getData(), p.getLength(), msg);
081:                        // Stat that message:
082:                        stats.handle(msg.op, msg.url);
083:                    } catch (Exception ex) {
084:                        ex.printStackTrace();
085:                    }
086:                }
087:            }
088:
089:            MICPReader(InetAddress a, int port, Stats stats)
090:                    throws UnknownHostException, IOException {
091:                // Init:
092:                this .micprw = new MICPReadWrite();
093:                this .addr = a;
094:                this .port = port;
095:                this .stats = stats;
096:                // Create and join:
097:                this .socket = new MulticastSocket(port);
098:                this .socket.joinGroup(a);
099:                // Run !
100:                setName("mICP listener");
101:                start();
102:            }
103:        }
104:
105:        public class Probe extends Panel implements  Runnable, ActionListener {
106:            MICPReader reader = null;
107:            Stats stats = null;
108:            long refresh = 500;
109:
110:            Label hits = null;
111:            Label queries = null;
112:            Label url = null;
113:            Button exit = null;
114:
115:            /**
116:             * ActionListener implementation - exit on exit button.
117:             * @param e The event.
118:             */
119:
120:            public void actionPerformed(ActionEvent e) {
121:                if (e.getSource() == exit) {
122:                    System.out.println("Bye !");
123:                    System.exit(0);
124:                }
125:            }
126:
127:            protected synchronized void tick() {
128:                try {
129:                    wait(refresh);
130:                } catch (InterruptedException ex) {
131:                }
132:            }
133:
134:            public void run() {
135:                while (true) {
136:                    // Display stats:
137:                    hits.setText(Integer.toString(stats.getHits()));
138:                    queries.setText(Integer.toString(stats.getQueries()));
139:                    url.setText(stats.getLastURL());
140:                    // Wait for interval:
141:                    tick();
142:                }
143:            }
144:
145:            public Probe(InetAddress addr, int port, long refresh)
146:                    throws UnknownHostException, IOException {
147:                // Create objects:
148:                this .refresh = refresh;
149:                this .stats = new Stats();
150:                this .reader = new MICPReader(addr, port, stats);
151:                // Create widgets:
152:                GridBagLayout gb = new GridBagLayout();
153:                setLayout(gb);
154:                GridBagConstraints ct = new GridBagConstraints();
155:                GridBagConstraints cv = new GridBagConstraints();
156:                // Create the title constraints:
157:                ct = new GridBagConstraints();
158:                ct.gridx = GridBagConstraints.RELATIVE;
159:                ct.anchor = GridBagConstraints.EAST;
160:                ct.weighty = 1.0;
161:                // Create the value constraints:
162:                cv = new GridBagConstraints();
163:                cv.gridx = GridBagConstraints.RELATIVE;
164:                cv.gridwidth = GridBagConstraints.REMAINDER;
165:                cv.fill = GridBagConstraints.HORIZONTAL;
166:                cv.anchor = GridBagConstraints.WEST;
167:                cv.weightx = 1.0;
168:                cv.weighty = 1.0;
169:                // Add the number of queries label:
170:                Label title = new Label("queries");
171:                gb.setConstraints(title, ct);
172:                add(title);
173:                queries = new Label("0");
174:                queries.setBackground(Color.white);
175:                gb.setConstraints(queries, cv);
176:                add(queries);
177:                // Add the number of hits label:
178:                title = new Label("hits");
179:                gb.setConstraints(title, ct);
180:                add(title);
181:                hits = new Label("0");
182:                hits.setBackground(Color.white);
183:                gb.setConstraints(hits, cv);
184:                add(hits);
185:                // Add the last url label:
186:                title = new Label("url");
187:                gb.setConstraints(title, ct);
188:                add(title);
189:                url = new Label("0");
190:                url.setBackground(Color.white);
191:                gb.setConstraints(url, cv);
192:                add(url);
193:                // Add the exit button:
194:                exit = new Button("Exit");
195:                exit.addActionListener(this );
196:                gb.setConstraints(exit, ct);
197:                add(exit);
198:            }
199:
200:            public static void usage() {
201:                PrintStream p = System.out;
202:                p.println("Probe -a <addr> -p <port> -r <refresh>"
203:                        + " -w <width> -h <height>");
204:                p.println("\taddr: multicast group address");
205:                p.println("\tport: multicast port");
206:                p.println("\trefresh: refresh interval in ms");
207:                p.println("\twidth: width at startup (pixels)");
208:                p.println("\theight: height at startup (pixels)");
209:                System.exit(1);
210:            }
211:
212:            public static void main(String args[]) {
213:                InetAddress addr = null;
214:                int port = -1;
215:                long refresh = 500;
216:                int width = 330;
217:                int height = 130;
218:                try {
219:                    for (int i = 0; i < args.length; i++) {
220:                        if (args[i].equals("-a") && (i + 1 < args.length)) {
221:                            addr = InetAddress.getByName(args[++i]);
222:                        } else if (args[i].equals("-p")
223:                                && (i + 1 < args.length)) {
224:                            port = Integer.parseInt(args[++i]);
225:                        } else if (args[i].equals("-r")
226:                                && (i + 1 < args.length)) {
227:                            refresh = Long.parseLong(args[++i]);
228:                        } else if (args[i].equals("-w")
229:                                && (i + 1 < args.length)) {
230:                            width = Integer.parseInt(args[++i]);
231:                        } else if (args[i].equals("-h")
232:                                && (i + 1 < args.length)) {
233:                            height = Integer.parseInt(args[++i]);
234:                        } else {
235:                            usage();
236:                        }
237:                    }
238:                } catch (Exception ex) {
239:                    usage();
240:                }
241:                // Check args:
242:                if ((addr == null) || (port == -1))
243:                    usage();
244:                // Run it:
245:                Probe probe = null;
246:                try {
247:                    probe = new Probe(addr, port, refresh);
248:                } catch (Exception ex) {
249:                    ex.printStackTrace();
250:                    System.exit(1);
251:                }
252:                Frame toplevel = new Frame("mICP-Probe");
253:                toplevel.add("Center", probe);
254:                toplevel.setSize(new Dimension(width, height));
255:                toplevel.show();
256:                new Thread(probe).start();
257:            }
258:
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.