UI session in web UI terminated immediately after receiving disconnect notification...
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 27 Sep 2016 10:34:40 +0000 (13:34 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 27 Sep 2016 10:35:05 +0000 (13:35 +0300)
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/console/KeepAliveTimer.java [new file with mode: 0644]
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/jobs/LoginJob.java
src/server/core/events.cpp
webui/webapp/Core/src/org/netxms/ui/eclipse/console/Application.java
webui/webapp/Core/src/org/netxms/ui/eclipse/console/ApplicationWorkbenchAdvisor.java
webui/webapp/Core/src/org/netxms/ui/eclipse/console/ApplicationWorkbenchWindowAdvisor.java
webui/webapp/Core/src/org/netxms/ui/eclipse/console/KeepAliveTimer.java [new file with mode: 0644]
webui/webapp/Core/src/org/netxms/ui/eclipse/jobs/LoginJob.java

index 0016a01..b3b6aa7 100644 (file)
@@ -652,6 +652,11 @@ public class NXCSession
                   resyncEventTemplates();
                }
                break;
+            case SessionNotification.SESSION_KILLED:
+            case SessionNotification.SERVER_SHUTDOWN:
+            case SessionNotification.CONNECTION_BROKEN:
+               backgroundDisconnect();
+               break;
          }
          
          sendNotification(new SessionNotification(code, data));
@@ -1914,12 +1919,31 @@ public class NXCSession
 
       Logger.info("NXCSession.connect", "succesfully logged in, userId=" + userId);
    }
+   
+   /**
+    * Disconect session in background
+    */
+   private void backgroundDisconnect()
+   {
+      Thread t = new Thread(new Runnable() {
+         @Override
+         public void run()
+         {
+            disconnect();
+         }
+      }, "NXCSession disconnect");
+      t.setDaemon(true);
+      t.start();
+   }
 
    /**
     * Disconnect from server.
     */
-   public void disconnect()
+   synchronized public void disconnect()
    {
+      if (isDisconnected)
+         return;
+      
       if (socket != null)
       {
          try
@@ -1938,6 +1962,7 @@ public class NXCSession
          catch(IOException e)
          {
          }
+         socket = null;
       }
       
       // cause notification processing thread to stop
@@ -1975,8 +2000,6 @@ public class NXCSession
          housekeeperThread = null;
       }
 
-      socket = null;
-
       if (msgWaitQueue != null)
       {
          msgWaitQueue.shutdown();
diff --git a/src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/console/KeepAliveTimer.java b/src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/console/KeepAliveTimer.java
new file mode 100644 (file)
index 0000000..18c3c1c
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.ui.eclipse.console;
+
+import org.netxms.client.NXCSession;
+import org.netxms.client.SessionListener;
+import org.netxms.client.SessionNotification;
+
+/**
+ * Console keepalive timer
+ */
+public class KeepAliveTimer extends Thread implements SessionListener
+{
+   private NXCSession session;
+   
+   /**
+    * @param session
+    */
+   public KeepAliveTimer(NXCSession session)
+   {
+      super("Session Keepalive Timer");
+      setDaemon(true);
+      this.session = session;
+      session.addListener(this);
+   }
+   
+   /* (non-Javadoc)
+    * @see java.lang.Thread#run()
+    */
+   @Override
+   public void run()
+   {
+      while(session.isConnected())
+      {
+         try
+         {
+            sleep(1000 * 60); // send keep-alive every 60 seconds
+            if (!session.checkConnection())
+               break;   // session broken, application will exit (handled by workbench advisor)
+         }
+         catch(InterruptedException e)
+         {
+         }
+         catch(Exception e)
+         {
+            Activator.logError("Exception in keep-alive thread", e);
+         }
+      }
+      session = null;
+      Activator.logInfo("Session keepalive timer stopped");
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.client.SessionListener#notificationHandler(org.netxms.client.SessionNotification)
+    */
+   @Override
+   public void notificationHandler(SessionNotification n)
+   {
+      if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || 
+          (n.getCode() == SessionNotification.SESSION_KILLED) ||
+          (n.getCode() == SessionNotification.SERVER_SHUTDOWN))
+      {
+         interrupt();
+      }
+   }
+}
index 5cc56e8..25333a4 100644 (file)
@@ -36,6 +36,7 @@ import org.netxms.client.ProtocolVersion;
 import org.netxms.client.constants.AuthenticationType;
 import org.netxms.client.constants.RCC;
 import org.netxms.ui.eclipse.console.Activator;
+import org.netxms.ui.eclipse.console.KeepAliveTimer;
 import org.netxms.ui.eclipse.console.Messages;
 import org.netxms.ui.eclipse.console.SourceProvider;
 import org.netxms.ui.eclipse.console.TweakletManager;
@@ -157,9 +158,7 @@ public class LoginJob implements IRunnableWithProgress
          callLoginListeners(session);
          monitor.worked(1);
 
-         final Thread thread = new Thread(null, new KeepAliveTimer(), "KeepAliveTimer"); //$NON-NLS-1$
-         thread.setDaemon(true);
-         thread.start();
+         new KeepAliveTimer(session).start();
       }
       catch(Exception e)
       {
@@ -271,28 +270,4 @@ public class LoginJob implements IRunnableWithProgress
       this.signature = signature;
       authMethod = AuthenticationType.CERTIFICATE;
    }
-
-   /**
-    * Keep-alive timer
-    */
-   private final class KeepAliveTimer implements Runnable
-   {
-      @Override
-      public void run()
-      {
-         while(true)
-         {
-            final NXCSession session = ConsoleSharedData.getSession();
-            try
-            {
-               Thread.sleep(1000 * 60); // send keep-alive every 60 seconds
-               if (!session.checkConnection())
-                  break;   // session broken, application will exit (handled by workbench advisor)
-            }
-            catch(Exception e)
-            {
-            }
-         }
-      }
-   }
 }
index cb9963e..6be13ac 100644 (file)
@@ -215,10 +215,10 @@ Event::Event(const EventTemplate *eventTemplate, UINT32 sourceId, UINT32 dciId,
  */
 Event::~Event()
 {
-   safe_free(m_messageText);
-   safe_free(m_messageTemplate);
-       safe_free(m_userTag);
-       safe_free(m_customMessage);
+   free(m_messageText);
+   free(m_messageTemplate);
+       free(m_userTag);
+       free(m_customMessage);
 }
 
 /**
index 49c00c7..9d5ccd9 100644 (file)
@@ -79,7 +79,6 @@ public class Application implements IApplication
                      RWT.getUISession().setAttribute(ConsoleSharedData.ATTRIBUTE_TIMEZONE, TimeZone.getTimeZone(tzList[0]));
                   }
                }
-               
                SharedIcons.init(display);
                WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
                return PlatformUI.createAndRunWorkbench(display, advisor);
index c3d1601..60cf612 100644 (file)
@@ -27,6 +27,8 @@ import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.window.Window;
 import org.eclipse.rap.rwt.RWT;
+import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
+import org.eclipse.rap.rwt.internal.service.UISessionImpl;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.application.IWorkbenchConfigurer;
@@ -46,6 +48,7 @@ import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 /**
  * Workbench advisor for NetXMS console application
  */
+@SuppressWarnings("restriction")
 public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
 {
    private static final String PERSPECTIVE_ID = "org.netxms.ui.eclipse.console.ManagementPerspective"; //$NON-NLS-1$
@@ -193,23 +196,33 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
                                    (n.getCode() == SessionNotification.SERVER_SHUTDOWN) ||
                                    (n.getCode() == SessionNotification.SESSION_KILLED))
                {
-                  display.asyncExec(new Runnable() {
+                  display.syncExec(new Runnable() {
                      @Override
                      public void run()
                      {
-                       String productName = BrandingManager.getInstance().getProductName();
-                        MessageDialog.openError(
-                              PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
-                              Messages.get().ApplicationWorkbenchAdvisor_CommunicationError,
-                              ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ? 
+                        RWT.getUISession().setAttribute("NoPageReload", Boolean.TRUE);
+                        PlatformUI.getWorkbench().close();
+                        
+                        String productName = BrandingManager.getInstance().getProductName();
+                        String msg =
+                              (n.getCode() == SessionNotification.CONNECTION_BROKEN) ? 
                                          String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName)
-                                      : ((n.getCode() == SessionNotification.CONNECTION_BROKEN) ?
+                                      : ((n.getCode() == SessionNotification.SESSION_KILLED) ?
                                         "Communication session was terminated by system administrator"
-                                       : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName)))
-                                    + Messages.get().ApplicationWorkbenchAdvisor_OKToCloseMessage);
-                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().close();
+                                       : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName));
+                        
+                        JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
+                        if (executor != null)
+                           executor.execute("document.body.innerHTML='" +
+                                 "<div style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: none; background-color: white;\">" + 
+                                 "<p style=\"margin-top: 30px; margin-left: 30px; color: #800000; font-family: \"Segoe UI\", Verdana, Arial, sans-serif; font-weight: bold; font-size: 2em;\">" + 
+                                 msg + 
+                                 "</p><br/>" + 
+                                 "<button style=\"margin-left: 30px\" onclick=\"location.reload(true)\">RELOAD</button>" + 
+                                 "</div>';");
                      }
                   });
+                  ((UISessionImpl)RWT.getUISession(display)).shutdown();
                }
             }
          });
index 2243891..3132b84 100644 (file)
@@ -204,8 +204,11 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor
        public void postWindowClose()
        {
                super.postWindowClose();
-      JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
-      if (executor != null)
-         executor.execute("location.reload(true);");
+      if (RWT.getUISession().getAttribute("NoPageReload") == null)
+      {
+         JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
+         if (executor != null)
+            executor.execute("location.reload(true);");
+      }
        }
 }
diff --git a/webui/webapp/Core/src/org/netxms/ui/eclipse/console/KeepAliveTimer.java b/webui/webapp/Core/src/org/netxms/ui/eclipse/console/KeepAliveTimer.java
new file mode 100644 (file)
index 0000000..18c3c1c
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2016 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.ui.eclipse.console;
+
+import org.netxms.client.NXCSession;
+import org.netxms.client.SessionListener;
+import org.netxms.client.SessionNotification;
+
+/**
+ * Console keepalive timer
+ */
+public class KeepAliveTimer extends Thread implements SessionListener
+{
+   private NXCSession session;
+   
+   /**
+    * @param session
+    */
+   public KeepAliveTimer(NXCSession session)
+   {
+      super("Session Keepalive Timer");
+      setDaemon(true);
+      this.session = session;
+      session.addListener(this);
+   }
+   
+   /* (non-Javadoc)
+    * @see java.lang.Thread#run()
+    */
+   @Override
+   public void run()
+   {
+      while(session.isConnected())
+      {
+         try
+         {
+            sleep(1000 * 60); // send keep-alive every 60 seconds
+            if (!session.checkConnection())
+               break;   // session broken, application will exit (handled by workbench advisor)
+         }
+         catch(InterruptedException e)
+         {
+         }
+         catch(Exception e)
+         {
+            Activator.logError("Exception in keep-alive thread", e);
+         }
+      }
+      session = null;
+      Activator.logInfo("Session keepalive timer stopped");
+   }
+
+   /* (non-Javadoc)
+    * @see org.netxms.client.SessionListener#notificationHandler(org.netxms.client.SessionNotification)
+    */
+   @Override
+   public void notificationHandler(SessionNotification n)
+   {
+      if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || 
+          (n.getCode() == SessionNotification.SESSION_KILLED) ||
+          (n.getCode() == SessionNotification.SERVER_SHUTDOWN))
+      {
+         interrupt();
+      }
+   }
+}
index f877858..b42b70a 100644 (file)
@@ -36,6 +36,7 @@ import org.netxms.client.ProtocolVersion;
 import org.netxms.client.constants.AuthenticationType;
 import org.netxms.client.constants.RCC;
 import org.netxms.ui.eclipse.console.Activator;
+import org.netxms.ui.eclipse.console.KeepAliveTimer;
 import org.netxms.ui.eclipse.console.Messages;
 import org.netxms.ui.eclipse.console.SourceProvider;
 import org.netxms.ui.eclipse.console.api.ConsoleLoginListener;
@@ -159,10 +160,7 @@ public class LoginJob implements IRunnableWithProgress
          callLoginListeners(session);
          monitor.worked(5);
 
-         Runnable keepAliveTimer = new KeepAliveTimer();
-         final Thread thread = new Thread(null, keepAliveTimer, "KeepAliveTimer");
-         thread.setDaemon(true);
-         thread.start();
+         new KeepAliveTimer(session).start();
       }
       catch(Exception e)
       {
@@ -274,31 +272,4 @@ public class LoginJob implements IRunnableWithProgress
       this.signature = signature;
       authMethod = AuthenticationType.CERTIFICATE;
    }
-
-   /**
-    * Keep-alive timer
-    */
-   private final class KeepAliveTimer implements Runnable
-   {
-      @Override
-      public void run()
-      {
-         while(true)
-         {
-            final NXCSession session = (NXCSession)RWT.getUISession(display).getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
-            if (session == null)
-               break;
-            try
-            {
-               Thread.sleep(1000 * 60); // send keep-alive every 60 seconds
-               if (!session.checkConnection())
-                  break;   // session broken, application will exit (handled by workbench advisor)
-            }
-            catch(Exception e)
-            {
-               Activator.logError("Exception in keep-alive thread", e);
-            }
-         }
-      }
-   }
 }