Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10eca7b

Browse files
Avoid generating too many exceptions
Support monitoring whether events has been received or not
1 parent b3449b9 commit 10eca7b

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

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

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
package net.sf.j2s.ajax;
1212

1313
import java.lang.reflect.Method;
14+
import java.util.HashSet;
1415
import java.util.Iterator;
1516
import java.util.List;
17+
import java.util.Set;
1618
import java.util.Vector;
1719

1820
import net.sf.j2s.ajax.SimpleRPCRunnable;
@@ -75,6 +77,12 @@ public abstract class SimplePipeRunnable extends SimpleRPCRunnable {
7577
@J2SIgnore
7678
int pipeMode;
7779

80+
@J2SIgnore
81+
Object dealMutex;
82+
83+
@J2SIgnore
84+
Set<String> nonExistedDeals;
85+
7886
@J2SIgnore
7987
public int getPipeMode() {
8088
return pipeMode;
@@ -131,6 +139,16 @@ public void setSequence(long sequence) {
131139
pipeSequence = sequence;
132140
}
133141

142+
@J2SIgnore
143+
public boolean isMonitoringEvents() {
144+
return false;
145+
}
146+
147+
@J2SIgnore
148+
public void pipeDataOK(SimpleSerializable ... evts) {
149+
150+
}
151+
134152
@J2SIgnore
135153
public void setPipeHelper(SimplePipeHelper.IPipeThrough helper) {
136154
pipeManaged = true;
@@ -444,16 +462,31 @@ public boolean deal(SimpleSerializable ss) {
444462
Class<?> clzz = getClass();
445463
if (clzz != null) {
446464
do {
447-
try {
448-
method = clzz.getMethod("deal", clazz);
449-
} catch (Exception e) {
450-
}
451-
if (method != null) {
452-
Class<?> returnType = method.getReturnType();
453-
if (returnType == boolean.class) {
454-
method.setAccessible(true);
455-
Object result = method.invoke(this, ss);
456-
return ((Boolean) result).booleanValue();
465+
if (nonExistedDeals == null || !nonExistedDeals.contains(clazz.getName())) {
466+
try {
467+
method = clzz.getMethod("deal", clazz);
468+
} catch (Exception e) {
469+
if (dealMutex == null) {
470+
synchronized (this) {
471+
if (dealMutex == null) {
472+
dealMutex = new Object();
473+
}
474+
}
475+
}
476+
synchronized (dealMutex) {
477+
if (nonExistedDeals == null) {
478+
nonExistedDeals = new HashSet<String>();
479+
}
480+
nonExistedDeals.add(clazz.getName());
481+
}
482+
}
483+
if (method != null) {
484+
Class<?> returnType = method.getReturnType();
485+
if (returnType == boolean.class) {
486+
method.setAccessible(true);
487+
Object result = method.invoke(this, ss);
488+
return ((Boolean) result).booleanValue();
489+
}
457490
}
458491
}
459492
clazz = clazz.getSuperclass();

0 commit comments

Comments
 (0)