Skip to content

Commit b4c78bd

Browse files
author
zhourenjian
committed
Refactoring codes and fixing bug
1 parent 5545a49 commit b4c78bd

File tree

9 files changed

+172
-127
lines changed

9 files changed

+172
-127
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ static CompoundPipeRunnable unregisterPipe(String id) {
152152
synchronized (allPipes) {
153153
for (int i = 0; i < allPipes.length; i++) {
154154
if (allPipes[i] != null && allPipes[i].id.equals(id)) {
155+
CompoundPipeRunnable pipe = allPipes[i];
155156
allPipes[i] = null;
156-
return allPipes[i];
157+
return pipe;
157158
}
158159
}
159160
return null;

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public boolean pipeDestroy() {
5858
pipes[i].pipeDestroy();
5959
}
6060
}
61-
pipeKey = null;
61+
//pipeKey = null;
6262
status = 0; // starting
6363
return super.pipeDestroy();
6464
}
@@ -136,6 +136,9 @@ public boolean weave(CompoundPipeSession pipe) {
136136
synchronized (pipes) {
137137
for (int i = 0; i < pipes.length; i++) {
138138
if (pipe == pipes[i]) {
139+
pipe.pipeKey = this.pipeKey;
140+
pipe.parent = this;
141+
initPipeSession(pipe);
139142
return false;
140143
}
141144
}
@@ -147,6 +150,8 @@ public boolean weave(CompoundPipeSession pipe) {
147150
}
148151
pipes[i] = pipe; // replace it!!!
149152
lastSetup = System.currentTimeMillis();
153+
pipe.pipeKey = this.pipeKey;
154+
pipe.parent = this;
150155
return true;
151156
}
152157
}
@@ -165,7 +170,13 @@ public boolean weave(CompoundPipeSession pipe) {
165170
lastSetup = System.currentTimeMillis();
166171
}
167172
}
173+
pipe.pipeKey = this.pipeKey;
168174
pipe.parent = this;
175+
initPipeSession(pipe);
176+
return true;
177+
}
178+
179+
private void initPipeSession(CompoundPipeSession pipe) {
169180
while (pipe.session == null) {
170181
String key = nextSessionKey();
171182
boolean isKeyOK = true;
@@ -180,18 +191,20 @@ public boolean weave(CompoundPipeSession pipe) {
180191
break;
181192
}
182193
}
183-
return true;
184194
}
185195

186196
public boolean unweave(CompoundPipeSession pipe) {
197+
/*
187198
if (pipeKey == null || !pipeKey.equals(pipe.pipeKey)) {
188199
return false;
189200
}
201+
//*/
190202
for (int i = 0; i < pipes.length; i++) {
191203
if (pipe == pipes[i] || (pipe.session != null && pipes[i] != null
192204
&& pipe.session.equals(pipes[i].session))) {
193205
pipes[i] = null;
194206
lastSetup = System.currentTimeMillis();
207+
pipe.pipeKey = null;
195208
return true;
196209
}
197210
}

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static final class PipeSessionClosedEvent extends CompoundSerializable {
1212

1313
@Override
1414
public void ajaxRun() {
15+
lastLiveDetected = System.currentTimeMillis();
1516
SimplePipeRunnable pipe = SimplePipeHelper.getPipe(pipeKey);
1617
if (pipe != null) {
1718
pipeAlive = pipeSetup();
@@ -42,7 +43,11 @@ public void pipeCreated() {
4243

4344
@Override
4445
public boolean pipeDestroy() {
45-
if (!super.pipeDestroy()) return false;
46+
if (destroyed) {
47+
return false; // already destroyed, no further destroy actions
48+
}
49+
pipeAlive = false;
50+
destroyed = true;
4651

4752
/**
4853
* @j2sNative
@@ -54,6 +59,9 @@ public boolean pipeDestroy() {
5459
}
5560

5661
SimplePipeRunnable pipe = SimplePipeHelper.getPipe(pipeKey);
62+
if (pipe == null) {
63+
pipe = parent;
64+
}
5765
if (pipe instanceof CompoundPipeRunnable) {
5866
CompoundPipeRunnable cp = (CompoundPipeRunnable) pipe;
5967
if (cp.status < 3) {
@@ -62,6 +70,7 @@ public boolean pipeDestroy() {
6270
cp.unweave(this);
6371
}
6472
session = null;
73+
pipeKey = null;
6574
return true;
6675
}
6776

@@ -82,6 +91,8 @@ final public SimpleSerializable[] through(Object... args) {
8291

8392
@Override
8493
public void pipeThrough(Object... args) {
94+
if (args == null || args.length == 0) return;
95+
8596
SimplePipeRunnable pipe = SimplePipeHelper.getPipe(pipeKey);
8697
if (!(pipe instanceof CompoundPipeRunnable)) return;
8798
CompoundPipeRunnable cp = (CompoundPipeRunnable) pipe;
@@ -123,6 +134,9 @@ public boolean deal(PipeSessionClosedEvent evt) {
123134
}
124135
this.updateStatus(false);
125136
SimplePipeRunnable pipe = SimplePipeHelper.getPipe(this.pipeKey);
137+
if (pipe == null) {
138+
pipe = this.parent;
139+
}
126140
if (pipe instanceof CompoundPipeRunnable) {
127141
CompoundPipeRunnable p = (CompoundPipeRunnable) pipe;
128142
if (p.pipes != null) {
@@ -134,12 +148,12 @@ public boolean deal(PipeSessionClosedEvent evt) {
134148
}
135149
}
136150
}
137-
138-
if (!p.isPipeLive()) {
139-
String pipeKey = this.pipeKey;
140-
p.pipeDestroy();
141-
SimplePipeHelper.removePipe(pipeKey);
142-
}
151+
}
152+
153+
if (pipe != null && !pipe.isPipeLive()) {
154+
String pipeKey = this.pipeKey;
155+
pipe.pipeDestroy();
156+
SimplePipeHelper.removePipe(pipeKey);
143157
}
144158
return true;
145159
}

0 commit comments

Comments
 (0)