author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 468 | 642c8c0be52e |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
468
642c8c0be52e
6695553: Cleanup GPLv2+SPL legal notices in hat sources
ohair
parents:
2
diff
changeset
|
27 |
/* |
2 | 28 |
* The Original Code is HAT. The Initial Developer of the |
29 |
* Original Code is Bill Foote, with contributions from others |
|
468
642c8c0be52e
6695553: Cleanup GPLv2+SPL legal notices in hat sources
ohair
parents:
2
diff
changeset
|
30 |
* at JavaSoft/Sun. |
2 | 31 |
*/ |
32 |
||
33 |
package com.sun.tools.hat.internal.server; |
|
34 |
||
35 |
/** |
|
36 |
* |
|
37 |
* @author Bill Foote |
|
38 |
*/ |
|
39 |
||
40 |
||
41 |
import java.net.Socket; |
|
42 |
import java.net.ServerSocket; |
|
43 |
import java.net.InetAddress; |
|
44 |
||
45 |
import java.io.InputStream; |
|
46 |
import java.io.BufferedInputStream; |
|
47 |
import java.io.IOException; |
|
48 |
import java.io.Writer; |
|
49 |
import java.io.BufferedWriter; |
|
50 |
import java.io.PrintWriter; |
|
51 |
import java.io.OutputStream; |
|
52 |
import java.io.OutputStreamWriter; |
|
53 |
import java.io.BufferedOutputStream; |
|
54 |
||
55 |
import com.sun.tools.hat.internal.model.Snapshot; |
|
56 |
import com.sun.tools.hat.internal.oql.OQLEngine; |
|
57 |
||
58 |
public class QueryListener implements Runnable { |
|
59 |
||
60 |
||
61 |
private Snapshot snapshot; |
|
62 |
private OQLEngine engine; |
|
63 |
private int port; |
|
64 |
||
65 |
public QueryListener(int port) { |
|
66 |
this.port = port; |
|
67 |
this.snapshot = null; // Client will setModel when it's ready |
|
68 |
this.engine = null; // created when snapshot is set |
|
69 |
} |
|
70 |
||
71 |
public void setModel(Snapshot ss) { |
|
72 |
this.snapshot = ss; |
|
73 |
if (OQLEngine.isOQLSupported()) { |
|
74 |
this.engine = new OQLEngine(ss); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
public void run() { |
|
79 |
try { |
|
80 |
waitForRequests(); |
|
81 |
} catch (IOException ex) { |
|
82 |
ex.printStackTrace(); |
|
83 |
System.exit(1); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
private void waitForRequests() throws IOException { |
|
88 |
ServerSocket ss = new ServerSocket(port); |
|
89 |
Thread last = null; |
|
90 |
for (;;) { |
|
91 |
Socket s = ss.accept(); |
|
92 |
Thread t = new Thread(new HttpReader(s, snapshot, engine)); |
|
93 |
if (snapshot == null) { |
|
94 |
t.setPriority(Thread.NORM_PRIORITY+1); |
|
95 |
} else { |
|
96 |
t.setPriority(Thread.NORM_PRIORITY-1); |
|
97 |
if (last != null) { |
|
98 |
try { |
|
99 |
last.setPriority(Thread.NORM_PRIORITY-2); |
|
100 |
} catch (Throwable ignored) { |
|
101 |
} |
|
102 |
// If the thread is no longer alive, we'll get a |
|
103 |
// NullPointerException |
|
104 |
} |
|
105 |
} |
|
106 |
t.start(); |
|
107 |
last = t; |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
} |