Skip to content

Commit 7712231

Browse files
author
zhourenjian
committed
Support IE subdomain query mode
Detect multiple queries are being sent to server, and avoid sending more queries before earlier requests get responses. Add thread name to Java threads Fixing Pipe swt requesting bug on OK response Other bug fixing
1 parent 081b840 commit 7712231

File tree

10 files changed

+288
-145
lines changed

10 files changed

+288
-145
lines changed

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/HttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public void send() {
374374
public void send(String str) {
375375
content = str;
376376
if (asynchronous) {
377-
(new Thread() {
377+
(new Thread("Java2Script HTTP Request") {
378378
public void run() {
379379
if (!toAbort) {
380380
request();

sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/CompoundPipeRunnable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ protected long pipeMonitoringInterval() {
312312
}
313313

314314
@Override
315-
protected long pipeWaitClosingInterval() {
315+
public long pipeWaitClosingInterval() {
316316
long closingInterval = super.pipeWaitClosingInterval();
317317
for (int i = 0; i < pipes.length; i++) {
318318
if (pipes[i] != null) {

sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeHelper.java

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
*/
2828
public class SimplePipeHelper {
2929

30-
static interface IPipeThrough {
30+
public static interface IPipeThrough {
3131
public void helpThrough(SimplePipeRunnable pipe, SimpleSerializable[] objs);
3232
}
3333

34-
static interface IPipeClosing {
34+
public static interface IPipeClosing {
3535
public void helpClosing(SimplePipeRunnable pipe);
3636
}
3737

@@ -123,7 +123,7 @@ static String nextPipeKey() {
123123
@J2SNative({
124124
"delete net.sf.j2s.ajax.SimplePipeHelper.pipes[key];"
125125
})
126-
static void removePipe(String key) {
126+
public static void removePipe(String key) {
127127
if (key == null) {
128128
System.out.println("Removing pipe for null key???");
129129
return;
@@ -155,15 +155,15 @@ public static SimplePipeRunnable getPipe(String key) {
155155
}
156156

157157
@J2SIgnore
158-
static List<SimpleSerializable> getPipeDataList(String key) {
158+
public static List<SimpleSerializable> getPipeDataList(String key) {
159159
if (pipeMap == null) {
160160
return null;
161161
}
162162
return pipeMap.get(key);
163163
}
164164

165165
@J2SIgnore
166-
static void pipeIn(String key, SimpleSerializable[] ss) {
166+
public static void pipeIn(String key, SimpleSerializable[] ss) {
167167
SimplePipeRunnable pipe = getPipe(key);
168168
List<SimpleSerializable> list = getPipeDataList(key);
169169
if (pipe == null || list == null) {
@@ -180,7 +180,7 @@ static void pipeIn(String key, SimpleSerializable[] ss) {
180180
}
181181

182182
@J2SIgnore
183-
static boolean isPipeLive(String key) {
183+
public static boolean isPipeLive(String key) {
184184
SimplePipeRunnable pipe = getPipe(key);
185185
if (pipe != null) {
186186
return pipe.isPipeLive();
@@ -189,7 +189,7 @@ static boolean isPipeLive(String key) {
189189
}
190190

191191
@J2SIgnore
192-
static boolean notifyPipeStatus(String key, boolean live) {
192+
public static boolean notifyPipeStatus(String key, boolean live) {
193193
SimplePipeRunnable pipe = getPipe(key);
194194
if (pipe != null && pipe.isPipeLive()) {
195195
pipe.updateStatus(live);
@@ -199,7 +199,7 @@ static boolean notifyPipeStatus(String key, boolean live) {
199199
}
200200

201201
@J2SIgnore
202-
public static void helpClosing(SimplePipeRunnable pipe) {
202+
static void helpClosing(SimplePipeRunnable pipe) {
203203
if (pipe.closer != null) {
204204
pipe.closer.helpClosing(pipe);
205205
} else {
@@ -208,37 +208,79 @@ public static void helpClosing(SimplePipeRunnable pipe) {
208208
}
209209

210210
@J2SIgnore
211-
public static void printStatistics() {
211+
public static String printStatistics2() {
212+
StringBuffer buffer = new StringBuffer();
213+
buffer.append("Pipe monitor<br />\r\n");
212214
if (pipes != null) {
213-
System.out.println("Totoal pipe count: " + pipes.size());
214-
System.out.println("Totoal pipe map count: " + pipeMap.size());
215+
buffer.append("Totoal pipe count: " + pipes.size() + "<br />\r\n");
216+
buffer.append("Totoal pipe map count: " + pipeMap.size() + "<br />\r\n");
215217
Object[] keys = pipeMap.keySet().toArray();
216218
for (int i = 0; i < keys.length; i++) {
217219
String key = (String) keys[i];
218220
List<SimpleSerializable> list = pipeMap.get(key);
219221
SimplePipeRunnable p = pipes.get(key);
220222
if (p instanceof CompoundPipeRunnable) {
221223
CompoundPipeRunnable cp = (CompoundPipeRunnable) p;
222-
System.out.println(i + "Pipe " + cp.pipeKey + " status=" + cp.status + " pipeAlive=" + cp.isPipeLive() + " created=" + new Date(cp.lastSetup));
224+
int activeCount = 0;
225+
for (int j = 0; j < cp.pipes.length; j++) {
226+
if (cp.pipes[j] != null) {
227+
activeCount++;
228+
}
229+
}
230+
if (activeCount > 2) {
231+
buffer.append(i + " Pipe (active=" + activeCount + ") " + cp.pipeKey + " status=" + cp.status + " pipeAlive=" + cp.isPipeLive() + " created=" + new Date(cp.lastSetup) + "<br />\r\n");
232+
}
233+
}
234+
if (list != null) {
235+
int size = list.size();
236+
if (size > 20) {
237+
if (p != null) {
238+
buffer.append(i + "::: pipe " + p.pipeKey + " size : " + size + " / " + p.pipeAlive + "<br />\r\n");
239+
} else {
240+
buffer.append("Error pipe " + key + " with size : " + size + "<br />\r\n");
241+
}
242+
}
243+
}
244+
}
245+
}
246+
return buffer.toString();
247+
}
248+
249+
@J2SIgnore
250+
public static String printStatistics() {
251+
StringBuffer buffer = new StringBuffer();
252+
buffer.append("Pipe monitor<br />\r\n");
253+
if (pipes != null) {
254+
buffer.append("Totoal pipe count: " + pipes.size() + "<br />\r\n");
255+
buffer.append("Totoal pipe map count: " + pipeMap.size() + "<br />\r\n");
256+
Object[] keys = pipeMap.keySet().toArray();
257+
for (int i = 0; i < keys.length; i++) {
258+
String key = (String) keys[i];
259+
List<SimpleSerializable> list = pipeMap.get(key);
260+
SimplePipeRunnable p = pipes.get(key);
261+
if (p instanceof CompoundPipeRunnable) {
262+
CompoundPipeRunnable cp = (CompoundPipeRunnable) p;
263+
buffer.append(i + "Pipe " + cp.pipeKey + " status=" + cp.status + " pipeAlive=" + cp.isPipeLive() + " created=" + new Date(cp.lastSetup) + "<br />\r\n");
223264
for (int j = 0; j < cp.pipes.length; j++) {
224265
CompoundPipeSession ps = cp.pipes[j];
225266
if (ps != null) {
226-
System.out.println(j + " : " + ps.session + " / " + ps.isPipeLive() + " pipeAlive=" + ps.pipeAlive);
267+
buffer.append(j + " : " + ps.session + " / " + ps.isPipeLive() + " pipeAlive=" + ps.pipeAlive + "<br />\r\n");
227268
}
228269
}
229270
}
230271
if (list != null) {
231272
int size = list.size();
232273
//if (size > 5) {
233274
if (p != null) {
234-
System.out.println("::: pipe " + p.pipeKey + " size : " + size + " / " + p.pipeAlive);
275+
buffer.append("::: pipe " + p.pipeKey + " size : " + size + " / " + p.pipeAlive + "<br />\r\n");
235276
} else {
236-
System.out.println("Error pipe " + key + " with size : " + size);
277+
buffer.append("Error pipe " + key + " with size : " + size + "<br />\r\n");
237278
}
238279
//}
239280
}
240281
}
241282
}
283+
return buffer.toString();
242284
}
243285

244286
@J2SIgnore
@@ -255,7 +297,7 @@ public static void setMonitoringInterval(long monitoringInterval) {
255297
private static void monitoringAllPipes() {
256298
while (true) {
257299
try {
258-
Thread.sleep(getMonitoringInterval());
300+
Thread.sleep(monitoringInterval);
259301
} catch (InterruptedException e) {
260302
}
261303
if (pipes == null) {
@@ -289,7 +331,7 @@ private static void monitoringAllPipes() {
289331
}
290332
if (ps.isPipeLive()) {
291333
ps.lastLiveDetected = now;
292-
} else if (now - ps.lastLiveDetected > 30000 + ps.pipeWaitClosingInterval()) {
334+
} else if (now - ps.lastLiveDetected > SimplePipeRequest.pipeLiveNotifyInterval * 3 + monitoringInterval + ps.pipeWaitClosingInterval()) {
293335
asyncDestroyPipe(ps);
294336
}
295337
}

sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeHttpServlet.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,23 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
167167
buffer.append("<html><head><title></title></head><body>\r\n");
168168
buffer.append("<script type=\"text/javascript\">");
169169
buffer.append("p = new Object ();\r\n");
170-
buffer.append("window.onload = function () {\r\n");
170+
buffer.append("p.key = \"" + key + "\";\r\n");
171171
buffer.append("p.originalDomain = document.domain;\r\n");
172172
buffer.append("document.domain = \"" + domain + "\";\r\n");
173-
buffer.append("p.key = \"" + key + "\";\r\n");
173+
buffer.append("var securityErrors = 0\r\n");
174+
buffer.append("var lazyOnload = function () {\r\n");
175+
buffer.append("try {\r\n");
174176
buffer.append("var spr = window.parent.net.sf.j2s.ajax.SimplePipeRequest;\r\n");
175177
buffer.append("eval (\"(\" + spr.subdomainInit + \") (p);\");\r\n");
176178
buffer.append("eval (\"((\" + spr.subdomainLoopQuery + \") (p)) ();\");\r\n");
177-
buffer.append("};\r\n");
179+
buffer.append("} catch (e) {\r\n");
180+
buffer.append("securityErrors++;\r\n");
181+
buffer.append("if (securityErrors < 100) {\r\n"); // 10s
182+
buffer.append("window.setTimeout (lazyOnload, 100);\r\n");
183+
buffer.append("};\r\n"); // end of if
184+
buffer.append("};\r\n"); // end of catch
185+
buffer.append("};\r\n"); // end of function
186+
buffer.append("window.onload = lazyOnload;\r\n");
178187
buffer.append("</script>\r\n");
179188
buffer.append("</body></html>\r\n");
180189
writer.write(buffer.toString());
@@ -191,6 +200,8 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
191200
buffer.append("<script type=\"text/javascript\">");
192201
if (domain != null) {
193202
buffer.append("document.domain = \"" + domain + "\";\r\n");
203+
} else {
204+
buffer.append("document.domain = document.domain;\r\n");
194205
}
195206
buffer.append("function $ (s) { if (window.parent) window.parent.net.sf.j2s.ajax.SimplePipeRequest.parseReceived (s); }");
196207
buffer.append("if (window.parent) eval (\"(\" + window.parent.net.sf.j2s.ajax.SimplePipeRequest.checkIFrameSrc + \") ();\");\r\n");

0 commit comments

Comments
 (0)