subscription mechanism in client API changed to named channels
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 15 Jan 2016 16:39:48 +0000 (18:39 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 15 Jan 2016 16:39:48 +0000 (18:39 +0200)
19 files changed:
include/netxms-version.h
include/nxcldefs.h
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/client/netxms-client/src/main/java/org/netxms/client/ProtocolVersion.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/jobs/LoginJob.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/views/AbstractTraceView.java
src/java/netxms-eclipse/EventManager/src/org/netxms/ui/eclipse/eventmanager/actions/OpenSyslogMonitor.java
src/java/netxms-eclipse/EventManager/src/org/netxms/ui/eclipse/eventmanager/views/EventMonitor.java
src/java/netxms-eclipse/EventManager/src/org/netxms/ui/eclipse/eventmanager/views/SyslogMonitor.java
src/java/netxms-eclipse/SNMP/src/org/netxms/ui/eclipse/snmp/views/SnmpTrapMonitor.java
src/server/core/audit.cpp
src/server/core/session.cpp
src/server/include/nms_core.h
webui/webapp/Core/src/org/netxms/ui/eclipse/jobs/LoginJob.java
webui/webapp/Core/src/org/netxms/ui/eclipse/views/AbstractTraceView.java
webui/webapp/EventManager/src/org/netxms/ui/eclipse/eventmanager/actions/OpenSyslogMonitor.java
webui/webapp/EventManager/src/org/netxms/ui/eclipse/eventmanager/views/EventMonitor.java
webui/webapp/EventManager/src/org/netxms/ui/eclipse/eventmanager/views/SyslogMonitor.java
webui/webapp/SNMP/src/org/netxms/ui/eclipse/snmp/views/SnmpTrapMonitor.java

index 95066af..9262686 100644 (file)
@@ -48,7 +48,7 @@
 #define CLIENT_PROTOCOL_VERSION_PUSH      1     /* Data push API */
 #define CLIENT_PROTOCOL_VERSION_TRAP      1     /* Event (trap) sending API */
 #define CLIENT_PROTOCOL_VERSION_MOBILE    1     /* All functionality relevant for mobile client */
-#define CLIENT_PROTOCOL_VERSION_FULL      3     /* All functionality */
+#define CLIENT_PROTOCOL_VERSION_FULL      4     /* All functionality */
 
 /**
  * Protocol version positions
index 3a87474..85b2db8 100644 (file)
@@ -924,15 +924,15 @@ enum AggregationFunction
 #define DEPLOYMENT_STATUS_FINISHED     255
 
 /**
- * Session subscription codes (data channels)
- */
-#define NXC_CHANNEL_EVENTS       0x00000001
-#define NXC_CHANNEL_SYSLOG       0x00000002
-#define NXC_CHANNEL_ALARMS       0x00000004
-#define NXC_CHANNEL_OBJECTS      0x00000008
-#define NXC_CHANNEL_SNMP_TRAPS   0x00000010
-#define NXC_CHANNEL_AUDIT_LOG    0x00000020
-#define NXC_CHANNEL_SITUATIONS   0x00000040
+ * Core subscription channels
+ */
+#define NXC_CHANNEL_EVENTS       _T("Core.Events")
+#define NXC_CHANNEL_SYSLOG       _T("Core.Syslog")
+#define NXC_CHANNEL_ALARMS       _T("Core.Alarms")
+#define NXC_CHANNEL_OBJECTS      _T("Core.Objects")
+#define NXC_CHANNEL_SNMP_TRAPS   _T("Core.SNMP.Traps")
+#define NXC_CHANNEL_AUDIT_LOG    _T("Core.Audit")
+#define NXC_CHANNEL_SITUATIONS   _T("Core.Situations")
 
 /**
  * Node creation flags
index df31038..4af614e 100644 (file)
@@ -181,14 +181,14 @@ public class NXCSession
    // Various public constants
    public static final int DEFAULT_CONN_PORT = 4701;
 
-   // Notification channels
-   public static final int CHANNEL_EVENTS = 0x0001;
-   public static final int CHANNEL_SYSLOG = 0x0002;
-   public static final int CHANNEL_ALARMS = 0x0004;
-   public static final int CHANNEL_OBJECTS = 0x0008;
-   public static final int CHANNEL_SNMP_TRAPS = 0x0010;
-   public static final int CHANNEL_AUDIT_LOG = 0x0020;
-   public static final int CHANNEL_SITUATIONS = 0x0040;
+   // Core notification channels
+   public static final String CHANNEL_EVENTS = "Core.Events";
+   public static final String CHANNEL_SYSLOG = "Core.Syslog";
+   public static final String CHANNEL_ALARMS = "Core.Alarms";
+   public static final String CHANNEL_OBJECTS = "Core.Objects";
+   public static final String CHANNEL_SNMP_TRAPS = "Core.SNMP.Traps";
+   public static final String CHANNEL_AUDIT_LOG = "Core.Audit";
+   public static final String CHANNEL_SITUATIONS = "Core.Situations";
 
    // Object sync options
    public static final int OBJECT_SYNC_NOTIFY = 0x0001;
@@ -3174,36 +3174,36 @@ public class NXCSession
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
    }
-
+   
    /**
-    * Subscribe to notification channel(s)
+    * Subscribe to notification channel. Each subscribe call should be matched by unsubscribe call.
+    * Calling subscribe on already subscribed channel will increase internal counter, and subscription
+    * will be cancelled when this counter returns back to 0.
     *
-    * @param channels Notification channels to subscribe to. Multiple channels can be
-    *                 specified by combining them with OR operation.
+    * @param channel Notification channel to subscribe to.
     * @throws IOException  if socket I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void subscribe(int channels) throws IOException, NXCException
+   public void subscribe(String channel) throws IOException, NXCException
    {
       NXCPMessage msg = newMessage(NXCPCodes.CMD_CHANGE_SUBSCRIPTION);
-      msg.setFieldInt32(NXCPCodes.VID_FLAGS, channels);
+      msg.setField(NXCPCodes.VID_NAME, channel);
       msg.setFieldInt16(NXCPCodes.VID_OPERATION, 1);
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
    }
 
    /**
-    * Unsubscribe from notification channel(s)
+    * Unsubscribe from notification channel.
     *
-    * @param channels Notification channels to unsubscribe from. Multiple channels can
-    *                 be specified by combining them with OR operation.
+    * @param channel Notification channel to unsubscribe from.
     * @throws IOException  if socket I/O error occurs
     * @throws NXCException if NetXMS server returns an error or operation was timed out
     */
-   public void unsubscribe(int channels) throws IOException, NXCException
+   public void unsubscribe(String channel) throws IOException, NXCException
    {
       NXCPMessage msg = newMessage(NXCPCodes.CMD_CHANGE_SUBSCRIPTION);
-      msg.setFieldInt32(NXCPCodes.VID_FLAGS, channels);
+      msg.setField(NXCPCodes.VID_NAME, channel);
       msg.setFieldInt16(NXCPCodes.VID_OPERATION, 0);
       sendMessage(msg);
       waitForRCC(msg.getMessageId());
index a9f24a5..8682ca6 100644 (file)
@@ -33,7 +33,7 @@ public final class ProtocolVersion
    public static final int PUSH = 1;
    public static final int TRAP = 1;
    public static final int MOBILE = 1;
-   public static final int FULL = 3;
+   public static final int FULL = 4;
    
    // Indexes
    public static final int INDEX_BASE = 0;
index 94ff607..2d62708 100644 (file)
@@ -138,7 +138,7 @@ public class LoginJob implements IRunnableWithProgress
          monitor.worked(1);
 
          monitor.setTaskName(Messages.get().LoginJob_subscribe);
-         session.subscribe(NXCSession.CHANNEL_ALARMS | NXCSession.CHANNEL_OBJECTS | NXCSession.CHANNEL_EVENTS);
+         session.subscribe(NXCSession.CHANNEL_ALARMS);
          monitor.worked(1);
 
          ConsoleSharedData.setSession(session);
index f9278a6..6be2de8 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.views;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
@@ -26,8 +27,12 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.contexts.IContextService;
 import org.eclipse.ui.part.ViewPart;
+import org.netxms.client.NXCSession;
+import org.netxms.ui.eclipse.console.Activator;
 import org.netxms.ui.eclipse.console.Messages;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
 
 /**
@@ -35,6 +40,8 @@ import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
  */
 public abstract class AbstractTraceView extends ViewPart
 {
+   protected NXCSession session = ConsoleSharedData.getSession();
+   
        private AbstractTraceWidget traceWidget;
        private Action actionClear;
        
@@ -138,4 +145,51 @@ public abstract class AbstractTraceView extends ViewPart
        {
                traceWidget.setFocus();
        }
+       
+       /**
+        * Subscribe to channel
+        * 
+        * @param channel
+        */
+       protected void subscribe(final String channel)
+       {
+      new ConsoleJob(String.format("Subscribing to channel %s", channel), this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.subscribe(channel);
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format("Cannot subscribe to channel %s", channel);
+         }
+      }.start();
+       }
+       
+       /**
+        * Unsubscribe from channel
+        * 
+        * @param channel
+        */
+       protected void unsubscribe(final String channel)
+       {
+      ConsoleJob job = new ConsoleJob(String.format("Unsubscribing from channel %s", channel), null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.unsubscribe(channel);
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format("Cannot unsubscribe from channel %s", channel);
+         }
+      };
+      job.setUser(false);
+      job.setSystem(true);
+      job.start();
+       }
 }
index ac6db50..467630b 100644 (file)
  */
 package org.netxms.ui.eclipse.eventmanager.actions;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.ui.PartInitException;
-import org.netxms.client.NXCSession;
-import org.netxms.ui.eclipse.eventmanager.Activator;
 import org.netxms.ui.eclipse.eventmanager.Messages;
 import org.netxms.ui.eclipse.eventmanager.views.SyslogMonitor;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 
 /**
@@ -65,34 +60,14 @@ public class OpenSyslogMonitor implements IWorkbenchWindowActionDelegate
                if(window == null)
                        return;
 
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().OpenSyslogMonitor_JobTitle, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.subscribe(NXCSession.CHANNEL_SYSLOG);
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               try 
-                                               {
-                                                       window.getActivePage().showView(SyslogMonitor.ID);
-                                               } 
-                                               catch (PartInitException e) 
-                                               {
-                                                       MessageDialogHelper.openError(window.getShell(), Messages.get().OpenSyslogMonitor_Error, Messages.get().OpenSyslogMonitor_ErrorText + e.getMessage());
-                                               }
-                                       }
-                               });
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().OpenSyslogMonitor_JobError;
-                       }
-               }.start();
+               try 
+               {
+                       window.getActivePage().showView(SyslogMonitor.ID);
+               } 
+               catch (PartInitException e) 
+               {
+                       MessageDialogHelper.openError(window.getShell(), Messages.get().OpenSyslogMonitor_Error, Messages.get().OpenSyslogMonitor_ErrorText + e.getMessage());
+               }
        }
 
        /* (non-Javadoc)
index 0c5e9b8..8dd78ce 100644 (file)
@@ -22,6 +22,9 @@ import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.netxms.client.NXCSession;
 import org.netxms.ui.eclipse.eventmanager.widgets.EventTraceWidget;
 import org.netxms.ui.eclipse.views.AbstractTraceView;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
@@ -34,6 +37,26 @@ public class EventMonitor extends AbstractTraceView
        public static final String ID = "org.netxms.ui.eclipse.eventmanager.views.EventMonitor"; //$NON-NLS-1$
        
        /* (non-Javadoc)
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      subscribe(NXCSession.CHANNEL_EVENTS);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#dispose()
+    */
+   @Override
+   public void dispose()
+   {
+      unsubscribe(NXCSession.CHANNEL_EVENTS);
+      super.dispose();
+   }
+
+   /* (non-Javadoc)
         * @see org.netxms.ui.eclipse.views.AbstractTraceView#fillLocalPullDown(org.eclipse.jface.action.IMenuManager)
         */
        @Override
index 8839eac..395fcc2 100644 (file)
  */
 package org.netxms.ui.eclipse.eventmanager.views;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.PartInitException;
 import org.netxms.client.NXCSession;
-import org.netxms.ui.eclipse.eventmanager.Activator;
-import org.netxms.ui.eclipse.eventmanager.Messages;
 import org.netxms.ui.eclipse.eventmanager.widgets.SyslogTraceWidget;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.views.AbstractTraceView;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
 
@@ -43,32 +37,16 @@ public class SyslogMonitor extends AbstractTraceView
        public static final String ID = "org.netxms.ui.eclipse.eventmanager.views.SyslogMonitor"; //$NON-NLS-1$
        
        /* (non-Javadoc)
-        * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
-        */
-       @Override
-       public void init(IViewSite site, IMemento memento) throws PartInitException
-       {
-               super.init(site, memento);
-               if (memento != null)
-               {
-                       final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-                       new ConsoleJob(Messages.get().SyslogMonitor_SubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                               @Override
-                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                               {
-                                       session.subscribe(NXCSession.CHANNEL_SYSLOG);
-                               }
-                               
-                               @Override
-                               protected String getErrorMessage()
-                               {
-                                       return Messages.get().SyslogMonitor_SubscribeJob_Error;
-                               }
-                       }.start();
-               }
-       }
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      subscribe(NXCSession.CHANNEL_SYSLOG);
+   }
 
-       /* (non-Javadoc)
+   /* (non-Javadoc)
         * @see org.netxms.ui.eclipse.views.AbstractTraceView#createTraceWidget(org.eclipse.swt.widgets.Composite)
         */
        @Override
@@ -95,20 +73,7 @@ public class SyslogMonitor extends AbstractTraceView
        @Override
        public void dispose()
        {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().SyslogMonitor_UnsubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.unsubscribe(NXCSession.CHANNEL_SYSLOG);
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().SyslogMonitor_UnsubscribeJob_Error;
-                       }
-               }.start();
+      unsubscribe(NXCSession.CHANNEL_SYSLOG);
                super.dispose();
        }
 }
index 27e7722..b4323ab 100644 (file)
  */
 package org.netxms.ui.eclipse.snmp.views;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.PartInitException;
 import org.netxms.client.NXCSession;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.snmp.Activator;
-import org.netxms.ui.eclipse.snmp.Messages;
 import org.netxms.ui.eclipse.snmp.widgets.SnmpTrapTraceWidget;
 import org.netxms.ui.eclipse.views.AbstractTraceView;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
@@ -41,51 +35,22 @@ public class SnmpTrapMonitor extends AbstractTraceView
        public static final String ID = "org.netxms.ui.eclipse.snmp.views.SnmpTrapMonitor"; //$NON-NLS-1$
        
        /* (non-Javadoc)
-        * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
-        */
-       @Override
-       public void init(IViewSite site, IMemento memento) throws PartInitException
-       {
-               super.init(site, memento);
-               if (memento != null)
-               {
-                       final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-                       new ConsoleJob(Messages.get().SnmpTrapMonitor_SubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                               @Override
-                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                               {
-                                       session.subscribe(NXCSession.CHANNEL_SNMP_TRAPS);
-                               }
-                               
-                               @Override
-                               protected String getErrorMessage()
-                               {
-                                       return Messages.get().SnmpTrapMonitor_SubscribeJob_Error;
-                               }
-                       }.start();
-               }
-       }
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      subscribe(NXCSession.CHANNEL_SNMP_TRAPS);
+   }
 
-       /* (non-Javadoc)
+   /* (non-Javadoc)
         * @see org.eclipse.ui.part.WorkbenchPart#dispose()
         */
        @Override
        public void dispose()
        {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().SnmpTrapMonitor_UnsubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.unsubscribe(NXCSession.CHANNEL_SNMP_TRAPS);
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().SnmpTrapMonitor_UnsubscribeJob_Error;
-                       }
-               }.start();
+      unsubscribe(NXCSession.CHANNEL_SNMP_TRAPS);
                super.dispose();
        }
 
index bcf3139..3de39a0 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2013 Victor Kirhenshtein
+** 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
@@ -127,7 +127,7 @@ static void SendNewRecord(ClientSession *pSession, void *pArg)
 {
    UPDATE_INFO *pUpdate;
 
-   if (pSession->isAuthenticated() && pSession->isSubscribed(NXC_CHANNEL_AUDIT_LOG))
+   if (pSession->isAuthenticated() && pSession->isSubscribedTo(NXC_CHANNEL_AUDIT_LOG))
        {
       pUpdate = (UPDATE_INFO *)malloc(sizeof(UPDATE_INFO));
       pUpdate->dwCategory = INFO_CAT_AUDIT_RECORD;
index d665715..441a5d9 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2015 Raden Solutions
+** Copyright (C) 2003-2016 Raden Solutions
 **
 ** 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
@@ -103,7 +103,7 @@ typedef struct
 } LIBRARY_IMAGE_UPDATE_INFO;
 
 /**
- * Callback to delete agent connections for loading files in distructor
+ * Callback to delete agent connections for loading files in destructor
  */
 static void DeleteCallback(NetObj* obj, void *data)
 {
@@ -135,7 +135,7 @@ static void ImageLibraryDeleteCallback(ClientSession *pSession, void *pArg)
        pData->pSession = this; \
        pData->pMsg = msg; \
        msg = NULL; /* prevent deletion by main processing thread*/ \
-       m_dwRefCount++; \
+       InterlockedIncrement(&m_refCount); \
        ThreadPoolExecute(g_mainThreadPool, ThreadStarter_##func, pData); \
 }
 
@@ -144,7 +144,7 @@ void ClientSession::ThreadStarter_##func(void *pArg) \
 { \
    ((PROCTHREAD_START_DATA *)pArg)->pSession->debugPrintf(6, _T("Method ") _T(#func) _T(" called on background thread")); \
    ((PROCTHREAD_START_DATA *)pArg)->pSession->func(((PROCTHREAD_START_DATA *)pArg)->pMsg); \
-       ((PROCTHREAD_START_DATA *)pArg)->pSession->m_dwRefCount--; \
+       InterlockedDecrement(&((PROCTHREAD_START_DATA *)pArg)->pSession->m_refCount); \
        delete ((PROCTHREAD_START_DATA *)pArg)->pMsg; \
        free(pArg); \
 }
@@ -227,7 +227,7 @@ THREAD_RESULT THREAD_CALL ClientSession::updateThreadStarter(void *pArg)
 /**
  * Client session class constructor
  */
-ClientSession::ClientSession(SOCKET hSocket, struct sockaddr *addr)
+ClientSession::ClientSession(SOCKET hSocket, struct sockaddr *addr) : m_subscriptions(true)
 {
    m_pSendQueue = new Queue;
    m_pMessageQueue = new Queue;
@@ -249,6 +249,7 @@ ClientSession::ClientSession(SOCKET hSocket, struct sockaddr *addr)
    m_mutexSendAuditLog = MutexCreate();
    m_mutexSendSituations = MutexCreate();
    m_mutexPollerInit = MutexCreate();
+   m_subscriptionLock = MutexCreate();
    m_dwFlags = 0;
        m_clientType = CLIENT_TYPE_DESKTOP;
        m_clientAddr = (struct sockaddr *)nx_memdup(addr, (addr->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6));
@@ -263,15 +264,21 @@ ClientSession::ClientSession(SOCKET hSocket, struct sockaddr *addr)
    _tcscpy(m_sessionName, _T("<not logged in>"));
        _tcscpy(m_clientInfo, _T("n/a"));
    m_dwUserId = INVALID_INDEX;
+   m_dwSystemAccess = 0;
    m_dwOpenDCIListSize = 0;
    m_pOpenDCIList = NULL;
    m_ppEPPRuleList = NULL;
+   m_wCurrentCmd = 0;
    m_hCurrFile = -1;
    m_dwFileRqId = 0;
-   m_dwRefCount = 0;
+   m_dwUploadCommand = 0;
+   m_dwNumRecordsToUpload = 0;
+   m_dwRecordsUploaded = 0;
+   m_refCount = 0;
    m_dwEncryptionRqId = 0;
+   m_dwEncryptionResult = 0;
+   m_dwUploadData = 0;
    m_condEncryptionSetup = INVALID_CONDITION_HANDLE;
-   m_dwActiveChannels = 0;
        m_console = NULL;
    m_loginTime = time(NULL);
    m_musicTypeList.add(_T("wav"));
@@ -299,6 +306,7 @@ ClientSession::~ClientSession()
    MutexDestroy(m_mutexSendAuditLog);
    MutexDestroy(m_mutexSendSituations);
    MutexDestroy(m_mutexPollerInit);
+   MutexDestroy(m_subscriptionLock);
    safe_free(m_pOpenDCIList);
    if (m_ppEPPRuleList != NULL)
    {
@@ -355,6 +363,17 @@ void ClientSession::debugPrintf(int level, const TCHAR *format, ...)
 }
 
 /**
+ * Check channel subscription
+ */
+bool ClientSession::isSubscribedTo(const TCHAR *channel) const
+{
+   MutexLock(m_subscriptionLock);
+   bool subscribed = m_subscriptions.contains(channel);
+   MutexUnlock(m_subscriptionLock);
+   return subscribed;
+}
+
+/**
  * Read thread
  */
 void ClientSession::readThread()
@@ -568,13 +587,13 @@ void ClientSession::readThread()
    }
 
    // Waiting while reference count becomes 0
-   if (m_dwRefCount > 0)
+   if (m_refCount > 0)
    {
       debugPrintf(3, _T("Waiting for pending requests..."));
       do
       {
          ThreadSleep(1);
-      } while(m_dwRefCount > 0);
+      } while(m_refCount > 0);
    }
 
    if (m_dwFlags & CSF_AUTHENTICATED)
@@ -1456,7 +1475,7 @@ void ClientSession::processingThread()
                                                        if (status == NXMOD_COMMAND_ACCEPTED_ASYNC)
                                                        {
                                                                pMsg = NULL;    // Prevent deletion
-                                                               m_dwRefCount++;
+                                                               InterlockedIncrement(&m_refCount);
                                                        }
                                                        break;   // Message was processed by the module
                                                }
@@ -2694,7 +2713,7 @@ void ClientSession::onNewEvent(Event *pEvent)
 {
    UPDATE_INFO *pUpdate;
    NXCPMessage *msg;
-   if (isAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_EVENTS) && (m_dwSystemAccess & SYSTEM_ACCESS_VIEW_EVENT_LOG))
+   if (isAuthenticated() && isSubscribedTo(NXC_CHANNEL_EVENTS) && (m_dwSystemAccess & SYSTEM_ACCESS_VIEW_EVENT_LOG))
    {
       NetObj *object = FindObjectById(pEvent->getSourceId());
       //If can't find object - just send to all events, if object found send to thous who have rights
@@ -2718,7 +2737,7 @@ void ClientSession::onObjectChange(NetObj *object)
 {
    UPDATE_INFO *pUpdate;
 
-   if (isAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_OBJECTS))
+   if (isAuthenticated() && isSubscribedTo(NXC_CHANNEL_OBJECTS))
       if (object->isDeleted() || object->checkAccessRights(m_dwUserId, OBJECT_ACCESS_READ))
       {
          pUpdate = (UPDATE_INFO *)malloc(sizeof(UPDATE_INFO));
@@ -5449,7 +5468,7 @@ void ClientSession::onAlarmUpdate(UINT32 dwCode, NXC_ALARM *pAlarm)
    UPDATE_INFO *pUpdate;
    NetObj *object;
 
-   if (isAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_ALARMS))
+   if (isAuthenticated() && isSubscribedTo(NXC_CHANNEL_ALARMS))
    {
       object = FindObjectById(pAlarm->sourceObject);
       if (object != NULL)
@@ -6176,7 +6195,7 @@ void ClientSession::forcedNodePoll(NXCPMessage *pRequest)
          if (object->checkAccessRights(m_dwUserId, OBJECT_ACCESS_MODIFY))
          {
             ((Node *)object)->incRefCount();
-            m_dwRefCount++;
+            InterlockedIncrement(&m_refCount);
 
             pData->pNode = (Node *)object;
             ThreadPoolExecute(g_mainThreadPool, pollerThreadStarter, pData);
@@ -7040,7 +7059,7 @@ void ClientSession::DeployPackage(NXCPMessage *pRequest)
          _tcscpy(pInfo->szPlatform, szPlatform);
          _tcscpy(pInfo->szVersion, szVersion);
 
-         m_dwRefCount++;
+         InterlockedIncrement(&m_refCount);
          ThreadCreate(DeploymentManager, 0, pInfo);
          msg.setField(VID_RCC, RCC_SUCCESS);
       }
@@ -8044,26 +8063,53 @@ void ClientSession::execTableTool(NXCPMessage *pRequest)
 /**
  * Change current subscription
  */
-void ClientSession::changeSubscription(NXCPMessage *pRequest)
+void ClientSession::changeSubscription(NXCPMessage *request)
 {
    NXCPMessage msg;
-   UINT32 dwFlags;
-
-   dwFlags = pRequest->getFieldAsUInt32(VID_FLAGS);
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(request->getId());
 
-   if (pRequest->getFieldAsUInt16(VID_OPERATION) != 0)
+   TCHAR channel[64];
+   request->getFieldAsString(VID_NAME, channel, 64);
+   Trim(channel);
+   if (channel[0] != 0)
    {
-      m_dwActiveChannels |= dwFlags;   // Subscribe
+      MutexLock(m_subscriptionLock);
+      UINT32 *count = m_subscriptions.get(channel);
+      if (request->getFieldAsBoolean(VID_OPERATION))
+      {
+         // Subscribe
+         if (count == NULL)
+         {
+            count = new UINT32;
+            *count = 1;
+            m_subscriptions.set(channel, count);
+         }
+         else
+         {
+            (*count)++;
+         }
+         debugPrintf(5, _T("Subscription added: %s (%d)"), channel, *count);
+      }
+      else
+      {
+         // Unsubscribe
+         if (count != NULL)
+         {
+            (*count)--;
+            debugPrintf(5, _T("Subscription removed: %s (%d)"), channel, *count);
+            if (*count == 0)
+               m_subscriptions.remove(channel);
+         }
+      }
+      MutexUnlock(m_subscriptionLock);
+      msg.setField(VID_RCC, RCC_SUCCESS);
    }
    else
    {
-      m_dwActiveChannels &= ~dwFlags;   // Unsubscribe
+      msg.setField(VID_RCC, RCC_INVALID_ARGUMENT);
    }
 
-   // Send response message
-   msg.setCode(CMD_REQUEST_COMPLETED);
-   msg.setId(pRequest->getId());
-   msg.setField(VID_RCC, RCC_SUCCESS);
    sendMessage(&msg);
 }
 
@@ -8456,7 +8502,7 @@ void ClientSession::KillSession(NXCPMessage *pRequest)
 void ClientSession::onSyslogMessage(NX_SYSLOG_RECORD *pRec)
 {
    UPDATE_INFO *pUpdate;
-   if (isAuthenticated() && isSubscribed(NXC_CHANNEL_SYSLOG) && (m_dwSystemAccess & SYSTEM_ACCESS_VIEW_SYSLOG))
+   if (isAuthenticated() && isSubscribedTo(NXC_CHANNEL_SYSLOG) && (m_dwSystemAccess & SYSTEM_ACCESS_VIEW_SYSLOG))
    {
       NetObj *object = FindObjectById(pRec->dwSourceObject);
       //If can't find object - just send to all events, if object found send to thous who have rights
@@ -8589,7 +8635,7 @@ void ClientSession::sendSyslog(NXCPMessage *pRequest)
 void ClientSession::onNewSNMPTrap(NXCPMessage *pMsg)
 {
    UPDATE_INFO *pUpdate;
-   if (isAuthenticated() && isSubscribed(NXC_CHANNEL_SNMP_TRAPS) && (m_dwSystemAccess & SYSTEM_ACCESS_VIEW_TRAP_LOG))
+   if (isAuthenticated() && isSubscribedTo(NXC_CHANNEL_SNMP_TRAPS) && (m_dwSystemAccess & SYSTEM_ACCESS_VIEW_TRAP_LOG))
    {
       NetObj *object = FindObjectById(pMsg->getFieldAsUInt32(VID_TRAP_LOG_MSG_BASE + 3));
       //If can't find object - just send to all events, if object found send to thous who have rights
@@ -8809,7 +8855,7 @@ void ClientSession::StartSnmpWalk(NXCPMessage *pRequest)
             msg.setField(VID_RCC, RCC_SUCCESS);
 
             object->incRefCount();
-            m_dwRefCount++;
+            InterlockedIncrement(&m_refCount);
 
             pArg = (WALKER_THREAD_ARGS *)malloc(sizeof(WALKER_THREAD_ARGS));
             pArg->pSession = this;
@@ -10743,7 +10789,7 @@ void ClientSession::onSituationChange(NXCPMessage *msg)
 {
    UPDATE_INFO *pUpdate;
 
-   if (isAuthenticated() && (m_dwActiveChannels & NXC_CHANNEL_SITUATIONS))
+   if (isAuthenticated() && isSubscribedTo(NXC_CHANNEL_SITUATIONS))
    {
       pUpdate = (UPDATE_INFO *)malloc(sizeof(UPDATE_INFO));
       pUpdate->dwCategory = INFO_CAT_SITUATION;
index 86244cb..287b4dc 100644 (file)
@@ -439,14 +439,15 @@ private:
    UINT32 m_dwUploadData;
    uuid_t m_uploadImageGuid;
    TCHAR m_szCurrFileName[MAX_PATH];
-   UINT32 m_dwRefCount;
+   VolatileCounter m_refCount;
    UINT32 m_dwEncryptionRqId;
    UINT32 m_dwEncryptionResult;
    CONDITION m_condEncryptionSetup;
-   UINT32 m_dwActiveChannels;     // Active data channels
        CONSOLE_CTX m_console;                  // Server console context
        StringList m_musicTypeList;
        ObjectIndex m_agentConn;
+       StringObjectMap<UINT32> m_subscriptions;
+       MUTEX m_subscriptionLock;
 
    static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
    static THREAD_RESULT THREAD_CALL writeThreadStarter(void *);
@@ -722,8 +723,8 @@ public:
    ClientSession(SOCKET hSocket, struct sockaddr *addr);
    ~ClientSession();
 
-   void incRefCount() { m_dwRefCount++; }
-   void decRefCount() { if (m_dwRefCount > 0) m_dwRefCount--; }
+   void incRefCount() { InterlockedIncrement(&m_refCount); }
+   void decRefCount() { InterlockedDecrement(&m_refCount); }
 
    void run();
 
@@ -733,27 +734,28 @@ public:
    void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszMsg);
        BOOL sendFile(const TCHAR *file, UINT32 dwRqId, long offset);
 
-   int getId() { return m_id; }
+   int getId() const { return m_id; }
    void setId(int id) { if (m_id == -1) m_id = id; }
-   int getState() { return m_state; }
-   const TCHAR *getLoginName() { return m_loginName; }
-   const TCHAR *getSessionName() { return m_sessionName; }
-   const TCHAR *getClientInfo() { return m_clientInfo; }
-       const TCHAR *getWorkstation() { return m_workstation; }
-   const TCHAR *getWebServerAddress() { return m_webServerAddress; }
-   UINT32 getUserId() { return m_dwUserId; }
-       UINT64 getSystemRights() { return m_dwSystemAccess; }
-   UINT32 getFlags() { return m_dwFlags; }
-   bool isAuthenticated() { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
-   bool isTerminated() { return (m_dwFlags & CSF_TERMINATED) ? true : false; }
-   bool isConsoleOpen() { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
-   bool isSubscribed(UINT32 dwChannel) { return (m_dwActiveChannels & dwChannel) ? true : false; }
-   WORD getCurrentCmd() { return m_wCurrentCmd; }
-   int getCipher() { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
-       int getClientType() { return m_clientType; }
-   time_t getLoginTime() { return m_loginTime; }
 
-       bool checkSysAccessRights(UINT64 requiredAccess)
+   int getState() const { return m_state; }
+   const TCHAR *getLoginName() const { return m_loginName; }
+   const TCHAR *getSessionName() const { return m_sessionName; }
+   const TCHAR *getClientInfo() const { return m_clientInfo; }
+       const TCHAR *getWorkstation() const { return m_workstation; }
+   const TCHAR *getWebServerAddress() const { return m_webServerAddress; }
+   UINT32 getUserId() const { return m_dwUserId; }
+       UINT64 getSystemRights() const { return m_dwSystemAccess; }
+   UINT32 getFlags() const { return m_dwFlags; }
+   bool isAuthenticated() const { return (m_dwFlags & CSF_AUTHENTICATED) ? true : false; }
+   bool isTerminated() const { return (m_dwFlags & CSF_TERMINATED) ? true : false; }
+   bool isConsoleOpen() const { return (m_dwFlags & CSF_CONSOLE_OPEN) ? true : false; }
+   WORD getCurrentCmd() const { return m_wCurrentCmd; }
+   int getCipher() const { return (m_pCtx == NULL) ? -1 : m_pCtx->getCipher(); }
+       int getClientType() const { return m_clientType; }
+   time_t getLoginTime() const { return m_loginTime; }
+   bool isSubscribedTo(const TCHAR *channel) const;
+
+       bool checkSysAccessRights(UINT64 requiredAccess) const
    {
       return (m_dwUserId == 0) ? true :
          ((requiredAccess & m_dwSystemAccess) == requiredAccess);
index bba7450..6b425be 100644 (file)
@@ -141,7 +141,7 @@ public class LoginJob implements IRunnableWithProgress
          monitor.worked(5);
 
          monitor.setTaskName(Messages.get(display).LoginJob_subscribe);
-         session.subscribe(NXCSession.CHANNEL_ALARMS | NXCSession.CHANNEL_OBJECTS | NXCSession.CHANNEL_EVENTS);
+         session.subscribe(NXCSession.CHANNEL_ALARMS);
          monitor.worked(5);
 
          RWT.getUISession(display).setAttribute(ConsoleSharedData.ATTRIBUTE_SESSION, session);
index de6d0a8..2a820b2 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.netxms.ui.eclipse.views;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
@@ -26,8 +27,12 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.contexts.IContextService;
 import org.eclipse.ui.part.ViewPart;
+import org.netxms.client.NXCSession;
+import org.netxms.ui.eclipse.console.Activator;
 import org.netxms.ui.eclipse.console.Messages;
 import org.netxms.ui.eclipse.console.resources.SharedIcons;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
 
 /**
@@ -35,6 +40,8 @@ import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
  */
 public abstract class AbstractTraceView extends ViewPart
 {
+   protected NXCSession session = ConsoleSharedData.getSession();
+   
        private AbstractTraceWidget traceWidget;
        private Action actionClear;
        
@@ -138,4 +145,51 @@ public abstract class AbstractTraceView extends ViewPart
        {
                traceWidget.setFocus();
        }
+       
+       /**
+        * Subscribe to channel
+        * 
+        * @param channel
+        */
+       protected void subscribe(final String channel)
+       {
+      new ConsoleJob(String.format("Subscribing to channel %s", channel), this, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.subscribe(channel);
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format("Cannot subscribe to channel %s", channel);
+         }
+      }.start();
+       }
+       
+       /**
+        * Unsubscribe from channel
+        * 
+        * @param channel
+        */
+       protected void unsubscribe(final String channel)
+       {
+      ConsoleJob job = new ConsoleJob(String.format("Unsubscribing from channel %s", channel), null, Activator.PLUGIN_ID, null) {
+         @Override
+         protected void runInternal(IProgressMonitor monitor) throws Exception
+         {
+            session.unsubscribe(channel);
+         }
+         
+         @Override
+         protected String getErrorMessage()
+         {
+            return String.format("Cannot unsubscribe from channel %s", channel);
+         }
+      };
+      job.setUser(false);
+      job.setSystem(true);
+      job.start();
+       }
 }
index ac6db50..467630b 100644 (file)
  */
 package org.netxms.ui.eclipse.eventmanager.actions;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.ui.PartInitException;
-import org.netxms.client.NXCSession;
-import org.netxms.ui.eclipse.eventmanager.Activator;
 import org.netxms.ui.eclipse.eventmanager.Messages;
 import org.netxms.ui.eclipse.eventmanager.views.SyslogMonitor;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
 
 /**
@@ -65,34 +60,14 @@ public class OpenSyslogMonitor implements IWorkbenchWindowActionDelegate
                if(window == null)
                        return;
 
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().OpenSyslogMonitor_JobTitle, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.subscribe(NXCSession.CHANNEL_SYSLOG);
-                               runInUIThread(new Runnable() {
-                                       @Override
-                                       public void run()
-                                       {
-                                               try 
-                                               {
-                                                       window.getActivePage().showView(SyslogMonitor.ID);
-                                               } 
-                                               catch (PartInitException e) 
-                                               {
-                                                       MessageDialogHelper.openError(window.getShell(), Messages.get().OpenSyslogMonitor_Error, Messages.get().OpenSyslogMonitor_ErrorText + e.getMessage());
-                                               }
-                                       }
-                               });
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().OpenSyslogMonitor_JobError;
-                       }
-               }.start();
+               try 
+               {
+                       window.getActivePage().showView(SyslogMonitor.ID);
+               } 
+               catch (PartInitException e) 
+               {
+                       MessageDialogHelper.openError(window.getShell(), Messages.get().OpenSyslogMonitor_Error, Messages.get().OpenSyslogMonitor_ErrorText + e.getMessage());
+               }
        }
 
        /* (non-Javadoc)
index 0c5e9b8..8dd78ce 100644 (file)
@@ -22,6 +22,9 @@ import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.netxms.client.NXCSession;
 import org.netxms.ui.eclipse.eventmanager.widgets.EventTraceWidget;
 import org.netxms.ui.eclipse.views.AbstractTraceView;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
@@ -34,6 +37,26 @@ public class EventMonitor extends AbstractTraceView
        public static final String ID = "org.netxms.ui.eclipse.eventmanager.views.EventMonitor"; //$NON-NLS-1$
        
        /* (non-Javadoc)
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      subscribe(NXCSession.CHANNEL_EVENTS);
+   }
+
+   /* (non-Javadoc)
+    * @see org.eclipse.ui.part.WorkbenchPart#dispose()
+    */
+   @Override
+   public void dispose()
+   {
+      unsubscribe(NXCSession.CHANNEL_EVENTS);
+      super.dispose();
+   }
+
+   /* (non-Javadoc)
         * @see org.netxms.ui.eclipse.views.AbstractTraceView#fillLocalPullDown(org.eclipse.jface.action.IMenuManager)
         */
        @Override
index 8839eac..395fcc2 100644 (file)
  */
 package org.netxms.ui.eclipse.eventmanager.views;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.PartInitException;
 import org.netxms.client.NXCSession;
-import org.netxms.ui.eclipse.eventmanager.Activator;
-import org.netxms.ui.eclipse.eventmanager.Messages;
 import org.netxms.ui.eclipse.eventmanager.widgets.SyslogTraceWidget;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
 import org.netxms.ui.eclipse.views.AbstractTraceView;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
 
@@ -43,32 +37,16 @@ public class SyslogMonitor extends AbstractTraceView
        public static final String ID = "org.netxms.ui.eclipse.eventmanager.views.SyslogMonitor"; //$NON-NLS-1$
        
        /* (non-Javadoc)
-        * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
-        */
-       @Override
-       public void init(IViewSite site, IMemento memento) throws PartInitException
-       {
-               super.init(site, memento);
-               if (memento != null)
-               {
-                       final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-                       new ConsoleJob(Messages.get().SyslogMonitor_SubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                               @Override
-                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                               {
-                                       session.subscribe(NXCSession.CHANNEL_SYSLOG);
-                               }
-                               
-                               @Override
-                               protected String getErrorMessage()
-                               {
-                                       return Messages.get().SyslogMonitor_SubscribeJob_Error;
-                               }
-                       }.start();
-               }
-       }
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      subscribe(NXCSession.CHANNEL_SYSLOG);
+   }
 
-       /* (non-Javadoc)
+   /* (non-Javadoc)
         * @see org.netxms.ui.eclipse.views.AbstractTraceView#createTraceWidget(org.eclipse.swt.widgets.Composite)
         */
        @Override
@@ -95,20 +73,7 @@ public class SyslogMonitor extends AbstractTraceView
        @Override
        public void dispose()
        {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().SyslogMonitor_UnsubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.unsubscribe(NXCSession.CHANNEL_SYSLOG);
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().SyslogMonitor_UnsubscribeJob_Error;
-                       }
-               }.start();
+      unsubscribe(NXCSession.CHANNEL_SYSLOG);
                super.dispose();
        }
 }
index 27e7722..b4323ab 100644 (file)
  */
 package org.netxms.ui.eclipse.snmp.views;
 
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IMemento;
 import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.PartInitException;
 import org.netxms.client.NXCSession;
-import org.netxms.ui.eclipse.jobs.ConsoleJob;
-import org.netxms.ui.eclipse.shared.ConsoleSharedData;
-import org.netxms.ui.eclipse.snmp.Activator;
-import org.netxms.ui.eclipse.snmp.Messages;
 import org.netxms.ui.eclipse.snmp.widgets.SnmpTrapTraceWidget;
 import org.netxms.ui.eclipse.views.AbstractTraceView;
 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
@@ -41,51 +35,22 @@ public class SnmpTrapMonitor extends AbstractTraceView
        public static final String ID = "org.netxms.ui.eclipse.snmp.views.SnmpTrapMonitor"; //$NON-NLS-1$
        
        /* (non-Javadoc)
-        * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
-        */
-       @Override
-       public void init(IViewSite site, IMemento memento) throws PartInitException
-       {
-               super.init(site, memento);
-               if (memento != null)
-               {
-                       final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-                       new ConsoleJob(Messages.get().SnmpTrapMonitor_SubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                               @Override
-                               protected void runInternal(IProgressMonitor monitor) throws Exception
-                               {
-                                       session.subscribe(NXCSession.CHANNEL_SNMP_TRAPS);
-                               }
-                               
-                               @Override
-                               protected String getErrorMessage()
-                               {
-                                       return Messages.get().SnmpTrapMonitor_SubscribeJob_Error;
-                               }
-                       }.start();
-               }
-       }
+    * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
+    */
+   @Override
+   public void init(IViewSite site) throws PartInitException
+   {
+      super.init(site);
+      subscribe(NXCSession.CHANNEL_SNMP_TRAPS);
+   }
 
-       /* (non-Javadoc)
+   /* (non-Javadoc)
         * @see org.eclipse.ui.part.WorkbenchPart#dispose()
         */
        @Override
        public void dispose()
        {
-               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
-               new ConsoleJob(Messages.get().SnmpTrapMonitor_UnsubscribeJob_Title, null, Activator.PLUGIN_ID, null) {
-                       @Override
-                       protected void runInternal(IProgressMonitor monitor) throws Exception
-                       {
-                               session.unsubscribe(NXCSession.CHANNEL_SNMP_TRAPS);
-                       }
-                       
-                       @Override
-                       protected String getErrorMessage()
-                       {
-                               return Messages.get().SnmpTrapMonitor_UnsubscribeJob_Error;
-                       }
-               }.start();
+      unsubscribe(NXCSession.CHANNEL_SNMP_TRAPS);
                super.dispose();
        }