IDEMPIERE-4154 ServerPush Adjustments. Reduce sleep to 300ms, longer wait doesn't help. Log schedule failures count. cleanup editor cache listener if schedule fail.

This commit is contained in:
hengsin 2020-03-02 10:59:29 +08:00
parent 31e63dc04d
commit e0906eb102
4 changed files with 46 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.adempiere.webui.AdempiereWebUI;
import org.atmosphere.cpr.AtmosphereResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -192,11 +193,9 @@ public class AtmosphereServerPush implements ServerPush {
}
if (!ok) {
for(int i = 0; i < 3 && !ok; i++) {
for (int ii = 0; ii < 10 && schedules.size() > 0; ii++) {
try {
Thread.sleep(50);
} catch (InterruptedException e1) {}
}
try {
Thread.sleep(100);
} catch (InterruptedException e1) {}
if (schedules.size() > 0) {
try {
ok = commitResponse();
@ -209,6 +208,15 @@ public class AtmosphereServerPush implements ServerPush {
}
if (!ok) {
log.warn("Failed to resume long polling resource");
Desktop d = desktop.get();
if (d != null) {
Integer count = (Integer) d.getAttribute(AdempiereWebUI.SERVERPUSH_SCHEDULE_FAILURES);
if (count != null)
count = Integer.valueOf(count.intValue()+1);
else
count = Integer.valueOf(1);
d.setAttribute(AdempiereWebUI.SERVERPUSH_SCHEDULE_FAILURES, count);
}
}
}
} else {

View File

@ -118,6 +118,8 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
private ConcurrentMap<String, String[]> m_URLParameters;
public static final String SERVERPUSH_SCHEDULE_FAILURES = "serverpush.schedule.failures";
public AdempiereWebUI()
{
this.setVisible(false);

View File

@ -25,6 +25,7 @@ import java.util.Properties;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.ValuePreference;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.AutoComplete;
@ -768,6 +769,7 @@ ContextMenuListener, IZoomableEditor
private interface ITableDirEditor {
public void setEditor(WTableDirEditor editor);
public void cleanup();
}
private static class EditorCombobox extends Combobox implements ITableDirEditor {
@ -815,7 +817,7 @@ ContextMenuListener, IZoomableEditor
/**
*
*/
protected void cleanup() {
public void cleanup() {
if (editor.tableCacheListener != null) {
CacheMgt.get().unregister(editor.tableCacheListener);
editor.tableCacheListener = null;
@ -873,7 +875,7 @@ ContextMenuListener, IZoomableEditor
/**
*
*/
protected void cleanup() {
public void cleanup() {
if (editor.tableCacheListener != null) {
CacheMgt.get().unregister(editor.tableCacheListener);
editor.tableCacheListener = null;
@ -916,7 +918,12 @@ ContextMenuListener, IZoomableEditor
}
private void refreshLookupList() {
Executions.schedule(editor.getComponent().getDesktop(), new EventListener<Event>() {
int failures = 0;
Desktop desktop = editor.getComponent().getDesktop();
Object attr = desktop.getAttribute(AdempiereWebUI.SERVERPUSH_SCHEDULE_FAILURES);
if (attr != null && attr instanceof Integer)
failures = ((Integer)attr).intValue();
Executions.schedule(desktop, new EventListener<Event>() {
@Override
public void onEvent(Event event) {
try {
@ -925,6 +932,13 @@ ContextMenuListener, IZoomableEditor
} catch (Exception e) {}
}
}, new Event("onResetLookupList"));
attr = desktop.getAttribute(AdempiereWebUI.SERVERPUSH_SCHEDULE_FAILURES);
if (attr != null && attr instanceof Integer) {
int f = ((Integer)attr).intValue();
if (f > failures) {
((ITableDirEditor)editor.getComponent()).cleanup();
}
}
}
@Override

View File

@ -30,6 +30,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import org.adempiere.webui.AdempiereWebUI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.zk.au.out.AuScript;
@ -121,7 +122,7 @@ public class WebSocketServerPush implements ServerPush {
if (endPoint == null) {
if (dt.isServerPushEnabled()) {
try {
Thread.sleep(2000);
Thread.sleep(300);
} catch (InterruptedException e) {
}
endPoint = getEndPoint(dt.getId());
@ -202,7 +203,18 @@ public class WebSocketServerPush implements ServerPush {
synchronized (schedules) {
schedules.add(new Schedule(task, event, scheduler));
}
echo();
boolean ok = echo();
if (!ok) {
Desktop d = desktop.get();
if (d != null) {
Integer count = (Integer) d.getAttribute(AdempiereWebUI.SERVERPUSH_SCHEDULE_FAILURES);
if (count != null)
count = Integer.valueOf(count.intValue()+1);
else
count = Integer.valueOf(1);
d.setAttribute(AdempiereWebUI.SERVERPUSH_SCHEDULE_FAILURES, count);
}
}
} else {
//in event listener thread, can schedule immediately
scheduler.schedule(task, event);