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

Commite6ff04e

Browse files
author
zhourenjian
committed
Remove Java 5.0 Syntax warnings
Remove unnecessary "new Date().getTime()" (replaced with System.currentMillisconds()"Fixing bug of SimplePipe/CompoundPipe, improve its stabilitiesCode refactor
1 parentab2e0f7 commite6ff04e

18 files changed

+460
-413
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ protected SimpleRPCRunnable getRunnableByRequest(String request) {
1313
if (pipeinstanceofCompoundPipeRunnable) {
1414
CompoundPipeRunnablep = (CompoundPipeRunnable)pipe;
1515
p.weave(session);
16-
//p.status = 3;
1716
}
1817
}
1918
returnrunnable;

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
packagenet.sf.j2s.ajax;
22

3-
importjava.util.Date;
4-
53
publicclassCompoundPipeRequestextendsSimplePipeRequest {
64

75
staticCompoundPipeRunnable[]pipes =newCompoundPipeRunnable[3];
86

97
publicstaticvoidweave(Stringid,CompoundPipeSessionp) {
108
finalCompoundPipeRunnablepipe =retrievePipe(id,true);
119
if (pipe.status ==0 || !pipe.isPipeLive()) {
12-
pipe.weave(p);
10+
pipe.weave(p);// no matter woven or not, continue to start the pipe
1311
pipe.updateStatus(true);
14-
SimplePipeRequest.pipe(pipe);
15-
pipe.status =1;// pipe
12+
if (pipe.status ==0) {// pipe is not started yet
13+
pipe.status =1;// pipe request is sent
14+
pipe.pipeKey =null;
15+
SimplePipeRequest.pipe(pipe);
16+
}
1617
}else {
17-
pipe.weave(p);
18-
if (pipe.pipeKey !=null) {
19-
p.pipeKey =pipe.pipeKey;
20-
SimpleRPCRequest.request(p);
21-
if (pipe.status <2) {
22-
pipe.status=2;// requested
23-
}
18+
if (!pipe.weave(p) &&p.isPipeLive()) {// already woven!
19+
return;
20+
}
21+
p.pipeKey =pipe.pipeKey;
22+
SimpleRPCRequest.request(p);
23+
if (pipe.status<2) {
24+
pipe.status =2;// requested
2425
}
2526
}
2627
}
2728

2829
staticvoidpipeFailed(CompoundPipeRunnablepipe) {
29-
longnow =newDate().getTime();
30+
longnow =System.currentTimeMillis();
3031
if (now -pipe.lastSetupRetried >5 *60 *1000) {// five minutes
3132
pipe.setupFailedRetries =0;
3233
}
@@ -92,6 +93,7 @@ private static CompoundPipeRunnable createPipe(String id) {
9293
publicvoidajaxOut() {
9394
super.ajaxOut();
9495
if (!pipeAlive) {
96+
CompoundPipeRequest.pipeFailed(this);
9597
return;// Not setup yet!
9698
}
9799
for (inti =0;i <pipes.length;i++) {

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

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ private static String nextSessionKey() {
2525
intsetupFailedRetries;
2626
longlastSetupRetried;
2727

28+
longlastSetup;
29+
2830
publicCompoundPipeRunnable() {
2931
pipes =newCompoundPipeSession[4];
3032
status =0;// starting
@@ -34,6 +36,7 @@ public CompoundPipeRunnable() {
3436
rpcMethod ="POST";
3537
pipeURL ="simplepipe";
3638
rpcURL ="piperpc";
39+
lastSetup =System.currentTimeMillis();
3740
}
3841

3942
protectedCompoundPipeSessiongetSession(Stringsession) {
@@ -55,6 +58,8 @@ public boolean pipeDestroy() {
5558
pipes[i].pipeDestroy();
5659
}
5760
}
61+
pipeKey =null;
62+
status =0;// starting
5863
returnsuper.pipeDestroy();
5964
}
6065

@@ -78,6 +83,9 @@ public boolean isPipeLive() {
7883
if (pipeAlive &&status <3) {// connected
7984
returntrue;// still in starting status
8085
}
86+
if (status ==3 &&System.currentTimeMillis() -lastSetup <30000) {
87+
returntrue;
88+
}
8189
if (super.isPipeLive()) {
8290
for (inti =0;i <pipes.length;i++) {
8391
if (pipes[i] !=null &&pipes[i].isPipeLive()) {
@@ -117,17 +125,29 @@ public void pipeLost() {
117125
@Override
118126
publicvoidkeepPipeLive() {
119127
for (inti =0;i <pipes.length;i++) {
120-
if (pipes[i] !=null) {
128+
if (pipes[i] !=null &&pipes[i].isPipeLive()) {
121129
pipes[i].keepPipeLive();
122130
}
123131
}
124132
}
125133

126-
publicvoidweave(CompoundPipeSessionpipe) {
134+
publicbooleanweave(CompoundPipeSessionpipe) {
135+
pipe.pipeReset();
127136
synchronized (pipes) {
128137
for (inti =0;i <pipes.length;i++) {
129138
if (pipe ==pipes[i]) {
130-
return;
139+
returnfalse;
140+
}
141+
}
142+
for (inti =0;i <pipes.length;i++) {
143+
if (pipe.session !=null &&pipes[i] !=null
144+
&&pipe.session.equals(pipes[i].session)) {
145+
if (pipes[i].isPipeLive()) {
146+
System.out.println("pipe session " +pipes[i].session +" is still live!!");
147+
}
148+
pipes[i] =pipe;// replace it!!!
149+
lastSetup =System.currentTimeMillis();
150+
returntrue;
131151
}
132152
}
133153
booleanadded =false;
@@ -142,6 +162,7 @@ public void weave(CompoundPipeSession pipe) {
142162
CompoundPipeSession[]newPipes =newCompoundPipeSession[pipes.length +4];
143163
System.arraycopy(pipes,0,newPipes,0,pipes.length);
144164
newPipes[pipes.length] =pipe;
165+
lastSetup =System.currentTimeMillis();
145166
}
146167
}
147168
pipe.parent =this;
@@ -159,15 +180,41 @@ public void weave(CompoundPipeSession pipe) {
159180
break;
160181
}
161182
}
183+
returntrue;
162184
}
163185

164-
publicvoidunweave(CompoundPipeSessionpipe) {
186+
publicbooleanunweave(CompoundPipeSessionpipe) {
187+
if (pipeKey ==null || !pipeKey.equals(pipe.pipeKey)) {
188+
returnfalse;
189+
}
165190
for (inti =0;i <pipes.length;i++) {
166-
if (pipe ==pipes[i]) {
191+
if (pipe ==pipes[i] || (pipe.session !=null &&pipes[i] !=null
192+
&&pipe.session.equals(pipes[i].session))) {
167193
pipes[i] =null;
168-
break;
194+
lastSetup =System.currentTimeMillis();
195+
returntrue;
196+
}
197+
}
198+
returnfalse;
199+
}
200+
201+
publicintgetActivePipeSessionCount() {
202+
intcount =0;
203+
for (inti =0;i <pipes.length;i++) {
204+
if (pipes[i] !=null) {
205+
count++;
206+
}
207+
}
208+
returncount;
209+
}
210+
211+
publicbooleanisEmpty() {
212+
for (inti =0;i <pipes.length;i++) {
213+
if (pipes[i] !=null) {
214+
returnfalse;
169215
}
170216
}
217+
returntrue;
171218
}
172219

173220
@Override
@@ -230,4 +277,26 @@ public String getPipeMethod() {
230277
returnpipeMethod;
231278
}
232279

280+
@Override
281+
protectedlongpipeMonitoringInterval() {
282+
longmonitorInterval =super.pipeMonitoringInterval();
283+
for (inti =0;i <pipes.length;i++) {
284+
if (pipes[i] !=null) {
285+
monitorInterval =Math.min(monitorInterval,pipes[i].pipeWaitClosingInterval());
286+
}
287+
}
288+
returnmonitorInterval;
289+
}
290+
291+
@Override
292+
protectedlongpipeWaitClosingInterval() {
293+
longclosingInterval =super.pipeWaitClosingInterval();
294+
for (inti =0;i <pipes.length;i++) {
295+
if (pipes[i] !=null) {
296+
closingInterval =Math.max(closingInterval,pipes[i].pipeWaitClosingInterval());
297+
}
298+
}
299+
returnclosingInterval;
300+
}
301+
233302
}

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
publicabstractclassCompoundPipeSessionextendsSimplePipeRunnable {
44

5-
privatestaticclassPipeSessionClosedEventextendsCompoundSerializable {
5+
publicstaticfinalclassPipeSessionClosedEventextendsCompoundSerializable {
66

77
}
88

@@ -21,6 +21,11 @@ public void ajaxRun() {
2121
}
2222
}
2323

24+
@Override
25+
publicbooleanisPipeLive() {
26+
returnsuper.isPipeLive() &&session !=null;
27+
}
28+
2429
@Override
2530
publicvoidpipeCreated() {
2631
super.pipeCreated();
@@ -51,24 +56,15 @@ public boolean pipeDestroy() {
5156
SimplePipeRunnablepipe =SimplePipeHelper.getPipe(pipeKey);
5257
if (pipeinstanceofCompoundPipeRunnable) {
5358
CompoundPipeRunnablecp = (CompoundPipeRunnable)pipe;
59+
if (cp.status <3) {
60+
cp.status =3;// no matter what happens, mark status as completed
61+
}
5462
cp.unweave(this);
5563
}
64+
session =null;
5665
returntrue;
5766
}
5867

59-
@Override
60-
publicvoidpipeFailed() {
61-
super.pipeFailed();
62-
SimplePipeRunnablepipe =SimplePipeHelper.getPipe(pipeKey);
63-
if (pipeinstanceofCompoundPipeRunnable) {
64-
CompoundPipeRunnablecp = (CompoundPipeRunnable)pipe;
65-
if (cp.status <3) {
66-
cp.status =3;// connected but failed to create child pipe
67-
}
68-
updateStatus(false);
69-
}
70-
}
71-
7268
@Override
7369
finalpublicSimpleSerializable[]through(Object...args) {
7470
CompoundSerializable[]cs =convert(args);
@@ -85,7 +81,7 @@ final public SimpleSerializable[] through(Object... args) {
8581
publicabstractCompoundSerializable[]convert(Object...args);
8682

8783
@Override
88-
protectedvoidpipeThrough(Object...args) {
84+
publicvoidpipeThrough(Object...args) {
8985
SimplePipeRunnablepipe =SimplePipeHelper.getPipe(pipeKey);
9086
if (!(pipeinstanceofCompoundPipeRunnable))return;
9187
CompoundPipeRunnablecp = (CompoundPipeRunnable)pipe;
@@ -140,8 +136,9 @@ public boolean deal(PipeSessionClosedEvent evt) {
140136
}
141137

142138
if (!p.isPipeLive()) {
139+
StringpipeKey =this.pipeKey;
143140
p.pipeDestroy();
144-
SimplePipeHelper.removePipe(this.pipeKey);
141+
SimplePipeHelper.removePipe(pipeKey);
145142
}
146143
}
147144
returntrue;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp