From 1fa0591f4b76626fde42a84ac586e1f9c6c8b324 Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 6 Oct 2018 15:46:47 +0530 Subject: [PATCH 1/3] Fixing issue with notification sending logic --- .../device/mgt/core/operation/mgt/OperationManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 0e5306f6c2..2ac5150a59 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -251,7 +251,7 @@ public class OperationManagerImpl implements OperationManager { } OperationManagementDAOFactory.commitTransaction(); - if (isScheduled) { + if (!isScheduled) { for (Device device : authorizedDevices) { this.sendNotification(operation, device); } From 9381362a0a363f1c0d774c94f1a08ded9b70e396 Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 8 Oct 2018 22:52:55 +0530 Subject: [PATCH 2/3] Provide workaround to address WS issue https://bz.apache.org/bugzilla/show_bug.cgi?id=56026 --- .../wsproxy/inbound/SubscriptionEndpoint.java | 7 ++- .../wsproxy/outbound/AnalyticsClient.java | 43 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java index 14db789fa9..b556949ae1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/inbound/SubscriptionEndpoint.java @@ -49,7 +49,7 @@ public class SubscriptionEndpoint { * * @param session - Users registered session. */ - public void onOpen(Session session) { + void onOpen(Session session) { if (log.isDebugEnabled()) { log.debug("WebSocket opened, for Session id: " + session.getId()); } @@ -68,8 +68,7 @@ public class SubscriptionEndpoint { endpoint += "/"; } endpoint += session.getRequestURI().getSchemeSpecificPart().replace("secured-websocket-proxy",""); - AnalyticsClient analyticsClient = new AnalyticsClient(session); - analyticsClient.connectClient(new URI(endpoint)); + AnalyticsClient analyticsClient = new AnalyticsClient(session, new URI(endpoint)); analyticsClients.add(analyticsClient); } catch (URISyntaxException e) { log.error("Unable to create URL from: " + endpoint, e); @@ -121,7 +120,7 @@ public class SubscriptionEndpoint { * @param session - Users registered session. * @param message - Status code for web-socket close. */ - public void onMessage(Session session, String message) { + void onMessage(Session session, String message) { for (AnalyticsClient analyticsClient : analyticsClientsMap.get(session.getId())) { if (analyticsClient != null) { analyticsClient.sendMessage(message); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java index 7bfd480288..96e6d6974a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.wsproxy/src/main/java/org/wso2/carbon/device/mgt/analytics/wsproxy/outbound/AnalyticsClient.java @@ -42,24 +42,18 @@ public class AnalyticsClient { private static final Log log = LogFactory.getLog(AnalyticsClient.class); - private WebSocketContainer container; - private Session analyticsSession = null; - private Session clientSession; + private final Session analyticsSession; + private final Session clientSession; /** * Create {@link AnalyticsClient} instance. */ - public AnalyticsClient(Session clientSession) { - container = ContainerProvider.getWebSocketContainer(); + public AnalyticsClient(Session clientSession, URI endpointURI) throws WSProxyException { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); this.clientSession = clientSession; - } - /** - * Create web socket client connection using {@link WebSocketContainer}. - */ - public void connectClient(URI endpointURI) throws WSProxyException { try { - analyticsSession = container.connectToServer(this, endpointURI); + this.analyticsSession = container.connectToServer(this, endpointURI); } catch (DeploymentException | IOException e) { String msg = "Error occurred while connecting to remote endpoint " + endpointURI.toString(); log.error(msg, e); @@ -79,7 +73,6 @@ public class AnalyticsClient { log.debug("Closing web socket session: '" + userSession.getId() + "'. Code: " + reason.getCloseCode().toString() + " Reason: " + reason.getReasonPhrase()); } - this.analyticsSession = null; } /** @@ -91,7 +84,16 @@ public class AnalyticsClient { */ @OnMessage public void onMessage(String message) { - this.clientSession.getAsyncRemote().sendText(message); + synchronized (this.clientSession) { + try { + this.clientSession.getBasicRemote().sendText(message); + } catch (IOException e) { + log.warn("Sending message to client failed due to " + e.getMessage()); + if (log.isDebugEnabled()) { + log.debug("Full stack trace:", e); + } + } + } } /** @@ -100,14 +102,23 @@ public class AnalyticsClient { * @param message the message which is going to send. */ public void sendMessage(String message) { - this.analyticsSession.getAsyncRemote().sendText(message); + synchronized (this.analyticsSession) { + try { + this.analyticsSession.getBasicRemote().sendText(message); + } catch (IOException e) { + log.warn("Sending message to analytics failed due to " + e.getMessage()); + if (log.isDebugEnabled()) { + log.debug("Full stack trace:", e); + } + } + } } /** * Close current connection. */ public void closeConnection(CloseReason closeReason) throws WSProxyException { - if (this.analyticsSession != null) { + if (this.analyticsSession.isOpen()) { try { this.analyticsSession.close(closeReason); } catch (IOException e) { @@ -115,6 +126,8 @@ public class AnalyticsClient { log.error(msg, e); throw new WSProxyException(msg, e); } + } else { + log.warn("Analytics session '" + this.analyticsSession.getId() + "' is already closed"); } } } From 5d13979629e24dc30b594f85f88de30f52cd36bb Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 8 Oct 2018 23:07:36 +0530 Subject: [PATCH 3/3] Increased notification popup time --- .../cdmf.unit.geo-dashboard/public/js/websocket.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js index 5bc0c3d8a1..def7287471 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js @@ -91,7 +91,7 @@ function initializeGeoLocation(geoFencingEnabled) { InitSpatialObject(geoFencingEnabled); } else { - noty({text: 'Invalid Access! No device information provided to track!', type: 'error'}); + noty({text: 'Invalid Access! No device information provided to track!', type: 'error', timeout: 10000}); } } @@ -493,7 +493,7 @@ GeoAreaObject.prototype.update = function (geoJSON) { }; function notifyAlert(message) { - noty({text: "Alert: " + message, type: 'warning'}); + noty({text: "Alert: " + message, type: 'warning', timeout: 10000}); } function Alert(type, message, level) { @@ -505,7 +505,7 @@ function Alert(type, message, level) { this.level = 'information'; this.notify = function () { - noty({text: this.type + ' ' + this.message, type: level}); + noty({text: this.type + ' ' + this.message, type: level, timeout: 10000}); } } @@ -575,7 +575,7 @@ var webSocketOnAlertError = function (e) { wsURL = wsURL.replace("wss://","https://"); var uriParts = wsURL.split("/"); wsURL = uriParts[0] + "//" + uriParts[2]; - noty({text: 'Something went wrong when trying to connect to ' + wsURL + '', type: 'error'}); + noty({text: 'Something went wrong when trying to connect to ' + wsURL + '', type: 'error', timeout: 10000}); }; var webSocketSpatialOnOpen = function () { @@ -606,7 +606,7 @@ var webSocketSpatialOnError = function (err) { wsURL = wsURL.replace("wss://","https://"); var uriParts = wsURL.split("/"); wsURL = uriParts[0] + "//" + uriParts[2]; - noty({text: 'Something went wrong when trying to connect to ' + wsURL + '', type: 'error'}); + noty({text: 'Something went wrong when trying to connect to ' + wsURL + '', type: 'error', timeout: 10000}); };