IDEMPIERE-4154 ServerPush Adjustments

This commit is contained in:
hengsin 2020-01-22 11:48:46 +08:00
parent 4c2537bd1b
commit 96eba5f89a
3 changed files with 55 additions and 14 deletions

View File

@ -20,6 +20,8 @@ the License.
package fi.jawsy.jawwa.zk.atmosphere;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.atmosphere.cpr.AtmosphereResource;
@ -58,6 +60,7 @@ public class AtmosphereServerPush implements ServerPush {
private ThreadInfo _active;
private ExecutionCarryOver _carryOver;
private final Object _mutex = new Object();
private List<Schedule<Event>> schedules = new ArrayList<>();
public AtmosphereServerPush() {
String timeoutString = Library.getProperty("fi.jawsy.jawwa.zk.atmosphere.timeout");
@ -155,19 +158,42 @@ public class AtmosphereServerPush implements ServerPush {
return _active != null && _active.nActive > 0;
}
@Override
@SuppressWarnings("unchecked")
@Override
public void onPiggyback() {
Schedule<Event>[] pendings = null;
synchronized (schedules) {
if (!schedules.isEmpty()) {
pendings = schedules.toArray(new Schedule[0]);
schedules = new ArrayList<>();
}
}
if (pendings != null && pendings.length > 0) {
for(Schedule<Event> p : pendings) {
p.scheduler.schedule(p.task, p.event);
}
}
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T extends Event> void schedule(EventListener<T> task, T event,
Scheduler<T> scheduler) {
scheduler.schedule(task, event);
try {
commitResponse();
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
}
if (Executions.getCurrent() == null) {
//save for schedule at on piggyback event
synchronized (schedules) {
schedules.add(new Schedule(task, event, scheduler));
}
try {
commitResponse();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
} else {
//in event listener thread, can schedule immediately
scheduler.schedule(task, event);
}
}
@Override
@ -238,4 +264,16 @@ public class AtmosphereServerPush implements ServerPush {
@Override
public void resume() {
}
private class Schedule<T extends Event> {
private EventListener<T> task;
private T event;
private Scheduler<T> scheduler;
private Schedule(EventListener<T> task, T event, Scheduler<T> scheduler) {
this.task = task;
this.event = event;
this.scheduler = scheduler;
}
}
}

View File

@ -523,9 +523,12 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
Env.setContext(properties, Env.LANGUAGE, Env.getContext(Env.getCtx(), Env.LANGUAGE));
Env.setContext(properties, AEnv.LOCALE, Env.getContext(Env.getCtx(), AEnv.LOCALE));
Locale locale = (Locale) Executions.getCurrent().getDesktop().getSession().getAttribute(Attributes.PREFERRED_LOCALE);
Desktop desktop = Executions.getCurrent().getDesktop();
Locale locale = (Locale) desktop.getSession().getAttribute(Attributes.PREFERRED_LOCALE);
HttpServletRequest httpRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
if (desktop.isServerPushEnabled())
desktop.enableServerPush(false);
Session session = logout0();
//clear context and invalidate session

View File

@ -57,14 +57,14 @@
polling - org.zkoss.zkex.ui.impl.PollingServerPush
comet - org.zkoss.zkmax.ui.comet.CometServerPush ( enterprise edition only )
-->
<!-- device-config>
<device-type>ajax</device-type>
<server-push-class>fi.jawsy.jawwa.zk.atmosphere.AtmosphereServerPush</server-push-class>
</device-config -->
<device-config>
<device-type>ajax</device-type>
<server-push-class>org.idempiere.ui.zk.websocket.WebSocketServerPush</server-push-class>
<server-push-class>fi.jawsy.jawwa.zk.atmosphere.AtmosphereServerPush</server-push-class>
</device-config>
<!-- device-config>
<device-type>ajax</device-type>
<server-push-class>org.idempiere.ui.zk.websocket.WebSocketServerPush</server-push-class>
</device-config -->
<!-- true for better performance and lower resource usage -->
<system-config>