IDEMPIERE-3840 Use web socket for server push. Fix construction of websocket path to server. Remove testing timeout code that have been accidentally leftover. Some minor cleanup.
This commit is contained in:
parent
eaba8b92f2
commit
47d876ddad
|
@ -66,9 +66,8 @@ public class ServerPushEndPoint {
|
|||
|
||||
@OnOpen
|
||||
public void onOpen(Session sess, @PathParam("dtid") String dtid) throws IOException {
|
||||
if (!Util.isEmpty(dtid, true)) {
|
||||
if (!Util.isEmpty(dtid, true) && WebSocketServerPush.isValidDesktopId(dtid)) {
|
||||
session = sess;
|
||||
session.setMaxIdleTimeout(30000);
|
||||
this.dtid = dtid;
|
||||
WebSocketServerPush.registerEndPoint(dtid, this);
|
||||
}
|
||||
|
@ -93,7 +92,7 @@ public class ServerPushEndPoint {
|
|||
try {
|
||||
session.getBasicRemote().sendText("echo");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
CLogger.getCLogger(getClass()).log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class WebSocketServerPush implements ServerPush {
|
|||
private final Object _mutex = new Object();
|
||||
|
||||
private final static Map<String, ServerPushEndPoint> endPointMap = new ConcurrentHashMap<>();
|
||||
private final static ServerPushEndPoint STUB = new ServerPushEndPoint();
|
||||
private List<Schedule<Event>> schedules = new ArrayList<>();
|
||||
|
||||
public WebSocketServerPush() {
|
||||
|
@ -226,7 +227,9 @@ public class WebSocketServerPush implements ServerPush {
|
|||
return;
|
||||
}
|
||||
|
||||
log.debug("Starting server push for " + desktop);
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Starting server push for " + desktop);
|
||||
registerEndPoint(desktop.getId(), STUB);
|
||||
startServerPushAtClient(desktop);
|
||||
}
|
||||
|
||||
|
@ -242,7 +245,8 @@ public class WebSocketServerPush implements ServerPush {
|
|||
return;
|
||||
}
|
||||
|
||||
log.debug("Stopping server push for " + desktop);
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Stopping server push for " + desktop);
|
||||
Clients.response("org.idempiere.websocket.serverpush.stop", new AuScript(null, "org.idempiere.websocket.stopServerPush('" + desktop.getId() + "');"));
|
||||
}
|
||||
|
||||
|
@ -292,6 +296,18 @@ public class WebSocketServerPush implements ServerPush {
|
|||
*/
|
||||
public static ServerPushEndPoint getEndPoint(String dtid) {
|
||||
ServerPushEndPoint endpoint = endPointMap.get(dtid);
|
||||
return endpoint;
|
||||
if (endpoint == STUB)
|
||||
return null;
|
||||
else
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dtid desktop id
|
||||
* @return true if serverpush started for dtid, false otherwise
|
||||
*/
|
||||
public static boolean isValidDesktopId(String dtid) {
|
||||
return endPointMap.containsKey(dtid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
path = path.substring(location.host.length+1);
|
||||
var last=path.lastIndexOf("/");
|
||||
if (last > 0) {
|
||||
path = path.substring(0, last);
|
||||
path = "/" + path.substring(0, last) + "/serverpush/";
|
||||
} else {
|
||||
path = "";
|
||||
path = "/serverpush/";
|
||||
}
|
||||
url = url + window.location.host + "/" + path + "/serverpush/" + this.desktop.id;
|
||||
url = url + window.location.host + path + this.desktop.id;
|
||||
var me = this;
|
||||
this.socket = new WebSocket(url);
|
||||
this.socket.onopen = function (event) {
|
||||
|
|
Loading…
Reference in New Issue