IDEMPIERE-4451 Executions.schedule should be executed asynchronously (#266)

onpiggyback should check whether's there's pending serverpush echo
This commit is contained in:
hengsin 2020-09-22 02:21:03 +08:00 committed by GitHub
parent 4c1ba12a3f
commit 98ab98b28c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -48,7 +48,9 @@ import org.zkoss.zk.ui.util.Clients;
*/ */
public class AtmosphereServerPush implements ServerPush { public class AtmosphereServerPush implements ServerPush {
private static final String ON_ACTIVATE_DESKTOP = "onActivateDesktop"; private static final String ATMOSPHERE_SERVER_PUSH_ECHO = "AtmosphereServerPush.Echo";
private static final String ON_ACTIVATE_DESKTOP = "onActivateDesktop";
public static final int DEFAULT_TIMEOUT = 1000 * 60 * 2; public static final int DEFAULT_TIMEOUT = 1000 * 60 * 2;
@ -161,7 +163,12 @@ public class AtmosphereServerPush implements ServerPush {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void onPiggyback() { public void onPiggyback() {
if (Executions.getCurrent() != null && Executions.getCurrent().getAttribute(ATMOSPHERE_SERVER_PUSH_ECHO) != null) {
//has pending serverpush echo, wait for next execution piggyback trigger by the pending serverpush echo
return;
}
Schedule<Event>[] pendings = null; Schedule<Event>[] pendings = null;
synchronized (schedules) { synchronized (schedules) {
if (!schedules.isEmpty()) { if (!schedules.isEmpty()) {
@ -195,8 +202,8 @@ public class AtmosphereServerPush implements ServerPush {
synchronized (schedules) { synchronized (schedules) {
schedules.add(new Schedule(task, event, scheduler)); schedules.add(new Schedule(task, event, scheduler));
} }
if (Executions.getCurrent().getAttribute("AtmosphereServerPush.Echo") == null) { if (Executions.getCurrent().getAttribute(ATMOSPHERE_SERVER_PUSH_ECHO) == null) {
Executions.getCurrent().setAttribute("AtmosphereServerPush.Echo", Boolean.TRUE); Executions.getCurrent().setAttribute(ATMOSPHERE_SERVER_PUSH_ECHO, Boolean.TRUE);
Clients.response(new AuEcho()); Clients.response(new AuEcho());
} }
} }

View File

@ -52,7 +52,9 @@ import org.zkoss.zk.ui.util.Clients;
*/ */
public class WebSocketServerPush implements ServerPush { public class WebSocketServerPush implements ServerPush {
private static final String ON_ACTIVATE_DESKTOP = "onActivateDesktop"; private static final String ATMOSPHERE_SERVER_PUSH_ECHO = "AtmosphereServerPush.Echo";
private static final String ON_ACTIVATE_DESKTOP = "onActivateDesktop";
private final AtomicReference<Desktop> desktop = new AtomicReference<Desktop>(); private final AtomicReference<Desktop> desktop = new AtomicReference<Desktop>();
@ -168,6 +170,11 @@ public class WebSocketServerPush implements ServerPush {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void onPiggyback() { public void onPiggyback() {
if (Executions.getCurrent() != null && Executions.getCurrent().getAttribute(ATMOSPHERE_SERVER_PUSH_ECHO) != null) {
//has pending serverpush echo, wait for next execution piggyback trigger by the pending serverpush echo
return;
}
Schedule<Event>[] pendings = null; Schedule<Event>[] pendings = null;
synchronized (schedules) { synchronized (schedules) {
if (!schedules.isEmpty()) { if (!schedules.isEmpty()) {
@ -208,8 +215,8 @@ public class WebSocketServerPush implements ServerPush {
synchronized (schedules) { synchronized (schedules) {
schedules.add(new Schedule(task, event, scheduler)); schedules.add(new Schedule(task, event, scheduler));
} }
if (Executions.getCurrent().getAttribute("AtmosphereServerPush.Echo") == null) { if (Executions.getCurrent().getAttribute(ATMOSPHERE_SERVER_PUSH_ECHO) == null) {
Executions.getCurrent().setAttribute("AtmosphereServerPush.Echo", Boolean.TRUE); Executions.getCurrent().setAttribute(ATMOSPHERE_SERVER_PUSH_ECHO, Boolean.TRUE);
Clients.response(new AuEcho()); Clients.response(new AuEcho());
} }
} }