IDEMPIERE-4154 ServerPush Adjustments
This commit is contained in:
parent
4c2537bd1b
commit
96eba5f89a
|
@ -20,6 +20,8 @@ the License.
|
||||||
package fi.jawsy.jawwa.zk.atmosphere;
|
package fi.jawsy.jawwa.zk.atmosphere;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.atmosphere.cpr.AtmosphereResource;
|
import org.atmosphere.cpr.AtmosphereResource;
|
||||||
|
@ -58,6 +60,7 @@ public class AtmosphereServerPush implements ServerPush {
|
||||||
private ThreadInfo _active;
|
private ThreadInfo _active;
|
||||||
private ExecutionCarryOver _carryOver;
|
private ExecutionCarryOver _carryOver;
|
||||||
private final Object _mutex = new Object();
|
private final Object _mutex = new Object();
|
||||||
|
private List<Schedule<Event>> schedules = new ArrayList<>();
|
||||||
|
|
||||||
public AtmosphereServerPush() {
|
public AtmosphereServerPush() {
|
||||||
String timeoutString = Library.getProperty("fi.jawsy.jawwa.zk.atmosphere.timeout");
|
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;
|
return _active != null && _active.nActive > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public void onPiggyback() {
|
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,
|
public <T extends Event> void schedule(EventListener<T> task, T event,
|
||||||
Scheduler<T> scheduler) {
|
Scheduler<T> scheduler) {
|
||||||
scheduler.schedule(task, event);
|
if (Executions.getCurrent() == null) {
|
||||||
try {
|
//save for schedule at on piggyback event
|
||||||
commitResponse();
|
synchronized (schedules) {
|
||||||
} catch (IOException e) {
|
schedules.add(new Schedule(task, event, scheduler));
|
||||||
log.error(e.getLocalizedMessage(), e);
|
}
|
||||||
}
|
try {
|
||||||
|
commitResponse();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//in event listener thread, can schedule immediately
|
||||||
|
scheduler.schedule(task, event);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -238,4 +264,16 @@ public class AtmosphereServerPush implements ServerPush {
|
||||||
@Override
|
@Override
|
||||||
public void resume() {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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, Env.LANGUAGE, Env.getContext(Env.getCtx(), Env.LANGUAGE));
|
||||||
Env.setContext(properties, AEnv.LOCALE, Env.getContext(Env.getCtx(), AEnv.LOCALE));
|
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();
|
HttpServletRequest httpRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest();
|
||||||
|
|
||||||
|
if (desktop.isServerPushEnabled())
|
||||||
|
desktop.enableServerPush(false);
|
||||||
Session session = logout0();
|
Session session = logout0();
|
||||||
|
|
||||||
//clear context and invalidate session
|
//clear context and invalidate session
|
||||||
|
|
|
@ -57,14 +57,14 @@
|
||||||
polling - org.zkoss.zkex.ui.impl.PollingServerPush
|
polling - org.zkoss.zkex.ui.impl.PollingServerPush
|
||||||
comet - org.zkoss.zkmax.ui.comet.CometServerPush ( enterprise edition only )
|
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-config>
|
||||||
<device-type>ajax</device-type>
|
<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-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 -->
|
<!-- true for better performance and lower resource usage -->
|
||||||
<system-config>
|
<system-config>
|
||||||
|
|
Loading…
Reference in New Issue