Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit682dbf5

Browse files
author
zhourenjian@gmail.com
committed
Use char instead of String for PIPE_TYPE_* constants, so we can make optimization for heavy servers
1 parent85377f9 commit682dbf5

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ synchronized static String registerPipe(SimplePipeRunnable pipe) {
118118
*/
119119
@J2SIgnore
120120
staticStringnextPipeKey() {
121-
StringBufferbuf =newStringBuffer();
121+
StringBufferbuf =newStringBuffer(SimplePipeRequest.PIPE_KEY_LENGTH);
122122
for (inti =0;i <SimplePipeRequest.PIPE_KEY_LENGTH;i++) {
123123
intr = (int)Math.round((float)Math.random() *61);// 0..61, total 62 numbers
124124
if (r <10) {

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
112112
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
113113
return;
114114
}
115-
Stringtype =req.getParameter(SimplePipeRequest.FORM_PIPE_TYPE);
116-
if (type ==null) {
117-
type =SimplePipeRequest.PIPE_TYPE_CONTINUUM;
115+
chartype =SimplePipeRequest.PIPE_TYPE_CONTINUUM;
116+
StringtypeStr =req.getParameter(SimplePipeRequest.FORM_PIPE_TYPE);
117+
if (typeStr !=null &&typeStr.length() >0) {
118+
type =typeStr.charAt(0);
118119
}
119120
Stringdomain =req.getParameter(SimplePipeRequest.FORM_PIPE_DOMAIN);
120121
doPipe(resp,key,type,domain);
@@ -139,14 +140,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
139140
* type = notify
140141
* Notify that client (browser) still keeps the pipe connection.
141142
*/
142-
protectedvoiddoPipe(finalHttpServletResponseresp,Stringkey,Stringtype,Stringdomain)
143+
protectedvoiddoPipe(finalHttpServletResponseresp,Stringkey,chartype,Stringdomain)
143144
throwsIOException {
144145
PrintWriterwriter =null;
145146
resp.setHeader("Pragma","no-cache");
146147
resp.setHeader("Cache-Control","no-cache");
147148
resp.setDateHeader("Expires",0);
148149

149-
if (SimplePipeRequest.PIPE_TYPE_NOTIFY.equals(type)) {
150+
if (SimplePipeRequest.PIPE_TYPE_NOTIFY ==type) {
150151
/*
151152
* Client send in "notify" request to execute #notifyPipeStatus, see below comments
152153
*/
@@ -160,7 +161,7 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
160161
writer.write("\");");
161162
return;
162163
}
163-
if (SimplePipeRequest.PIPE_TYPE_SUBDOMAIN_QUERY.equals(type)) {// subdomain query
164+
if (SimplePipeRequest.PIPE_TYPE_SUBDOMAIN_QUERY ==type) {// subdomain query
164165
resp.setContentType("text/html; charset=utf-8");
165166
writer =resp.getWriter();
166167
StringBufferbuffer =newStringBuffer();
@@ -189,11 +190,11 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
189190
writer.write(buffer.toString());
190191
return;
191192
}
192-
booleanisContinuum =SimplePipeRequest.PIPE_TYPE_CONTINUUM.equals(type);
193+
booleanisContinuum =SimplePipeRequest.PIPE_TYPE_CONTINUUM ==type;
193194
if (isContinuum) {
194195
resp.setHeader("Transfer-Encoding","chunked");
195196
}
196-
booleanisScripting =SimplePipeRequest.PIPE_TYPE_SCRIPT.equals(type);
197+
booleanisScripting =SimplePipeRequest.PIPE_TYPE_SCRIPT ==type;
197198
if (isScripting) {// iframe
198199
resp.setContentType("text/html; charset=utf-8");
199200
writer =resp.getWriter();
@@ -211,8 +212,7 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
211212
writer.write(buffer.toString());
212213
writer.flush();
213214
}else {
214-
if (SimplePipeRequest.PIPE_TYPE_QUERY.equals(type)
215-
||isContinuum) {
215+
if (SimplePipeRequest.PIPE_TYPE_QUERY ==type ||isContinuum) {
216216
resp.setContentType("text/plain; charset=utf-8");
217217
}else {
218218
resp.setContentType("text/javascript; charset=utf-8");
@@ -345,28 +345,27 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
345345
}
346346
}
347347

348-
protectedstaticStringoutput(Stringtype,Stringkey,
349-
Stringstr) {
348+
protectedstaticStringoutput(chartype,Stringkey,Stringstr) {
350349
StringBufferbuffer =newStringBuffer();
351-
if (SimplePipeRequest.PIPE_TYPE_SCRIPT.equals(type)) {
350+
if (SimplePipeRequest.PIPE_TYPE_SCRIPT ==type) {
352351
// iframe, so $ is a safe method identifier
353352
buffer.append("<script type=\"text/javascript\">$ (\"");
354-
}elseif (SimplePipeRequest.PIPE_TYPE_XSS.equals(type)) {
353+
}elseif (SimplePipeRequest.PIPE_TYPE_XSS ==type) {
355354
buffer.append("$p1p3p$ (\"");// $p1p3p$
356355
}
357356
buffer.append(key);
358-
if (SimplePipeRequest.PIPE_TYPE_SCRIPT.equals(type)
359-
||SimplePipeRequest.PIPE_TYPE_XSS.equals(type)) {
357+
if (SimplePipeRequest.PIPE_TYPE_SCRIPT ==type
358+
||SimplePipeRequest.PIPE_TYPE_XSS ==type) {
360359
str =str.replaceAll("\\\\","\\\\\\\\").replaceAll("\r","\\\\r")
361360
.replaceAll("\n","\\\\n").replaceAll("\"","\\\\\"");
362-
if (SimplePipeRequest.PIPE_TYPE_SCRIPT.equals(type)) {
361+
if (SimplePipeRequest.PIPE_TYPE_SCRIPT ==type) {
363362
str =str.replaceAll("<\\/script>","<\\/scr\" +\"ipt>");
364363
}
365364
}
366365
buffer.append(str);
367-
if (SimplePipeRequest.PIPE_TYPE_SCRIPT.equals(type)) {// iframe
366+
if (SimplePipeRequest.PIPE_TYPE_SCRIPT ==type) {// iframe
368367
buffer.append("\");</script>\r\n");
369-
}elseif (SimplePipeRequest.PIPE_TYPE_XSS.equals(type)) {
368+
}elseif (SimplePipeRequest.PIPE_TYPE_XSS ==type) {
370369
buffer.append("\");\r\n");
371370
}
372371
returnbuffer.toString();

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeRequest.java‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,32 @@ public static interface IHttpPipeRequestFactory extends IHttpRequestFactory {
7979
/**
8080
* Type of pipe request: query
8181
*/
82-
publicstaticfinalStringPIPE_TYPE_QUERY ="q";// "query";
82+
publicstaticfinalcharPIPE_TYPE_QUERY ='q';
8383

8484
/**
8585
* Type of pipe request: subdomain-query
8686
*/
87-
publicstaticfinalStringPIPE_TYPE_SUBDOMAIN_QUERY ="u";// "subdomain-query";
87+
publicstaticfinalcharPIPE_TYPE_SUBDOMAIN_QUERY ='u';
8888

8989
/**
9090
* Type of pipe request: notify
9191
*/
92-
publicstaticfinalStringPIPE_TYPE_NOTIFY ="n";// "notify";
92+
publicstaticfinalcharPIPE_TYPE_NOTIFY ='n';
9393

9494
/**
9595
* Type of pipe request: script
9696
*/
97-
publicstaticfinalStringPIPE_TYPE_SCRIPT ="s";// "script";
97+
publicstaticfinalcharPIPE_TYPE_SCRIPT ='s';
9898

9999
/**
100100
* Type of pipe request: xss
101101
*/
102-
publicstaticfinalStringPIPE_TYPE_XSS ="x";// "xss";
102+
publicstaticfinalcharPIPE_TYPE_XSS ='x';
103103

104104
/**
105105
* Type of pipe request: continuum
106106
*/
107-
publicstaticfinalStringPIPE_TYPE_CONTINUUM ="c";// "continuum";
107+
publicstaticfinalcharPIPE_TYPE_CONTINUUM ='c';
108108

109109

110110
/**
@@ -191,12 +191,17 @@ public static void switchToContinuumMode(boolean queue) {
191191
* @param pipeRequestType
192192
* @return request data for both GET and POST request.
193193
*/
194-
protectedstaticStringconstructRequest(StringpipeKey,StringpipeRequestType,longpipeSequence) {
194+
protectedstaticStringconstructRequest(StringpipeKey,charpipeRequestType,longpipeSequence) {
195195
reqCount++;
196-
returnFORM_PIPE_KEY +"=" +pipeKey +"&"
196+
/**
197+
* @j2sNative
198+
* return"k="+pipeKey+"&t="+pipeRequestType+"&s="+pipeSequence+"&r="+net.sf.j2s.ajax.SimplePipeRequest.reqCount;
199+
*/ {
200+
returnFORM_PIPE_KEY +"=" +pipeKey +"&"
197201
+FORM_PIPE_TYPE +"=" +pipeRequestType +"&"
198202
+FORM_PIPE_SEQUENCE +"=" +pipeSequence +"&"
199203
+FORM_PIPE_RANDOM +"=" +reqCount;
204+
}
200205
}
201206

202207
protectedstaticvoidsendRequest(HttpRequestrequest,Stringmethod,Stringurl,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp