client library service manager implementation changed; cosmetic fixes
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 28 May 2014 21:39:25 +0000 (00:39 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 28 May 2014 21:39:25 +0000 (00:39 +0300)
.gitignore
doc/internal/nxcp_command_ranges.txt
src/java/netxms-client-api/src/main/java/org/netxms/api/client/services/ServiceManager.java
src/java/netxms-eclipse/Core/META-INF/MANIFEST.MF
src/java/nxreporting/pom.xml

index 270daa1..dcc74e8 100644 (file)
@@ -27,13 +27,7 @@ Makefile.in
 pom.xml.versionsBackup
 
 Debug
-Debug64
-Debug64_UNICODE
-Debug_UNICODE
 Release
-Release64
-Release64_UNICODE
-Release_UNICODE
 bin
 target
 
@@ -215,4 +209,3 @@ target
 *.jar
 *.war
 *.ear
-
index 38d4e46..399b4bd 100644 (file)
@@ -1,5 +1,5 @@
 0000 .. 0FFF   Core system commands
-1000 .. 100F   NXVS
+1000 .. 10FF   ATM monitoring
 1100 .. 11FF   Reporting
 5000 .. 5FFF    TTC Marconi
 6000 .. 60FF    FIS/IST
index 3f7d3ec..28354cd 100644 (file)
  */
 package org.netxms.api.client.services;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ServiceLoader;
 
 /**
  * Manager for client services
  */
 public final class ServiceManager
 {
-   private static Map<String, ServiceHandler> servicesByName = new HashMap<String, ServiceHandler>();
-   private static Map<Class<? extends ServiceHandler>, ServiceHandler> servicesByClass = new HashMap<Class<? extends ServiceHandler>, ServiceHandler>();
+   private static ServiceLoader<ServiceHandler> serviceLoader = ServiceLoader.load(ServiceHandler.class);
    
    /**
-    * Register service
-    * 
-    * @param name
-    * @param handler
-    * @return
+    * Reload service providers
     */
-   public static synchronized boolean registerService(ServiceHandler handler)
+   public static synchronized void reload(ClassLoader loader)
    {
-      if (servicesByName.containsKey(handler.getServiceName()) || servicesByClass.containsKey(handler.getClass()))
-         return false;
-      servicesByName.put(handler.getServiceName(), handler);
-      servicesByClass.put(handler.getClass(), handler);
-      return true;
+      serviceLoader = ServiceLoader.load(ServiceHandler.class, loader);
    }
    
    /**
-    * Unregister service
-    * 
-    * @param name
-    */
-   public static synchronized void unregisterService(String name)
-   {
-      ServiceHandler h = servicesByName.get(name);
-      if (h != null)
-      {
-         servicesByName.remove(name);
-         servicesByClass.remove(h.getClass());
-      }
-   }
-
-   /**
     * Get service handler by name and check if handler class is correct.
     * 
     * @param name
@@ -69,8 +44,10 @@ public final class ServiceManager
     */
    public static synchronized ServiceHandler getServiceHandler(String name, Class<? extends ServiceHandler> serviceClass)
    {
-      ServiceHandler h = servicesByName.get(name);
-      return serviceClass.isInstance(h) ? h : null;
+      for(ServiceHandler s : serviceLoader)
+         if (s.getServiceName().equals(name) && serviceClass.isInstance(s))
+            return s;
+      return null;
    }
    
    /**
@@ -81,7 +58,10 @@ public final class ServiceManager
     */
    public static synchronized ServiceHandler getServiceHandler(String name)
    {
-      return servicesByName.get(name);
+      for(ServiceHandler s : serviceLoader)
+         if (s.getServiceName().equals(name))
+            return s;
+      return null;
    }
    
    /**
@@ -92,6 +72,18 @@ public final class ServiceManager
     */
    public static synchronized ServiceHandler getServiceHandler(Class<? extends ServiceHandler> serviceClass)
    {
-      return servicesByClass.get(serviceClass);
+      for(ServiceHandler s : serviceLoader)
+         if (serviceClass.isInstance(s))
+            return s;
+      return null;
+   }
+   
+   /**
+    * Debug method to dump all registered services
+    */
+   public static synchronized void dump()
+   {
+      for(ServiceHandler s : serviceLoader)
+         System.out.println(s.getServiceName());
    }
 }
index 3f0370d..882a9f7 100644 (file)
@@ -25,6 +25,7 @@ Export-Package: org.netxms.api.client,
  org.netxms.api.client.reporting,
  org.netxms.api.client.scripts,
  org.netxms.api.client.servermanager,
+ org.netxms.api.client.services,
  org.netxms.api.client.users,
  org.netxms.base,
  org.netxms.client,
index 1a2154e..80be823 100644 (file)
         <dependency>
             <groupId>org.netxms</groupId>
             <artifactId>netxms-base</artifactId>
-            <version>1.2.14</version>
+            <version>${version}</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.netxms</groupId>
             <artifactId>netxms-client-api</artifactId>
-            <version>1.2.14</version>
+            <version>${version}</version>
             <scope>compile</scope>
         </dependency>