[asterisk-scf-commits] asterisk-scf/integration/ice.git branch "icebox-local-services" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Feb 18 12:42:57 CST 2011


branch "icebox-local-services" has been created
        at  d7d335cd7ea2452fd16a9ba5afb05579da54f366 (commit)

- Log -----------------------------------------------------------------
commit d7d335cd7ea2452fd16a9ba5afb05579da54f366
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Wed Jun 16 17:46:50 2010 -0500

    import icebox local services code

diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp
index be713d9..0262574 100644
--- a/cpp/src/IceBox/ServiceManagerI.cpp
+++ b/cpp/src/IceBox/ServiceManagerI.cpp
@@ -134,6 +134,8 @@ IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator, int& argc
     {
         _argv.push_back(argv[i]);
     }
+
+    _localServiceManager = new LocalServiceManagerI();
 }
 
 IceBox::ServiceManagerI::~ServiceManagerI()
@@ -666,6 +668,12 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
             communicator = info.communicator;
         }
         
+        ServiceWithLocalServicesPtr lservice = ServiceWithLocalServicesPtr::dynamicCast(info.service);
+        if(lservice)
+        {
+            lservice->setLocalServiceManager(_localServiceManager);
+        }
+
         //
         // Start the service.
         //
@@ -969,3 +977,30 @@ IceBox::ServiceManagerI::createServiceProperties(const string& service)
     }
     return properties;
 }
+
+void ServiceManagerI::LocalServiceManagerI::addLocalService(const std::string& name, const Ice::LocalObjectPtr& service)
+{
+    IceUtil::Mutex::Lock lock(_lock);
+    _dict[name] = service;
+}
+
+void ServiceManagerI::LocalServiceManagerI::removeLocalService(const std::string& name)
+{
+    IceUtil::Mutex::Lock lock(_lock);
+    _dict.erase(name);
+}
+
+Ice::LocalObjectPtr ServiceManagerI::LocalServiceManagerI::findLocalService(const std::string& name)
+{
+    IceUtil::Mutex::Lock lock(_lock);
+    map<string, Ice::LocalObjectPtr>::const_iterator search = _dict.find(name);
+    if(search == _dict.end())
+    {
+        return 0;
+    }
+    else
+    {
+        return search->second;
+    }
+
+}
diff --git a/cpp/src/IceBox/ServiceManagerI.h b/cpp/src/IceBox/ServiceManagerI.h
index 507bff8..07e8b0e 100644
--- a/cpp/src/IceBox/ServiceManagerI.h
+++ b/cpp/src/IceBox/ServiceManagerI.h
@@ -21,6 +21,22 @@ namespace IceBox
 
 class ServiceManagerI : public ServiceManager, public IceUtil::Monitor<IceUtil::Mutex>
 {
+    class LocalServiceManagerI : public LocalServiceManager
+    {
+    public:
+
+        virtual void addLocalService(const std::string&, const Ice::LocalObjectPtr&);
+        virtual void removeLocalService(const std::string&);
+        virtual Ice::LocalObjectPtr findLocalService(const std::string&);
+
+    private:
+
+        IceUtil::Mutex _lock;
+        std::map<std::string, Ice::LocalObjectPtr> _dict;
+    };
+    
+    typedef IceUtil::Handle<LocalServiceManagerI> LocalServiceManagerIPtr;
+
 public:
 
     ServiceManagerI(Ice::CommunicatorPtr, int&, char*[]);
@@ -81,6 +97,8 @@ private:
 
     std::set<ServiceObserverPrx> _observers;
     int _traceServiceObserver;
+
+    LocalServiceManagerPtr _localServiceManager;
 };
 
 typedef IceUtil::Handle<ServiceManagerI> ServiceManagerIPtr;
diff --git a/cs/src/IceBox/ServiceManagerI.cs b/cs/src/IceBox/ServiceManagerI.cs
index fc29d74..828c5a6 100644
--- a/cs/src/IceBox/ServiceManagerI.cs
+++ b/cs/src/IceBox/ServiceManagerI.cs
@@ -22,6 +22,47 @@ namespace IceBox
 //
 class ServiceManagerI : ServiceManagerDisp_
 {
+    class LocalServiceManagerI : LocalServiceManager
+    {
+        public LocalServiceManagerI()
+        {
+            _dict = new Dictionary<string, Object>();
+        }
+        
+        public void addLocalService(string name, System.Object service)
+        {
+            lock(this)
+            {
+                _dict.Add(name, service);
+            }
+        }
+        
+        public void removeLocalService(string name)
+        {
+            lock(this)
+            {
+                _dict.Remove(name);
+            }
+        }
+        
+        public System.Object findLocalService(string name)
+        {
+            lock(this)
+            {
+                if(!_dict.ContainsKey(name))
+                {
+                    return null;
+                }
+                else
+                {
+                    return _dict[name];
+                }
+            }
+        }
+        
+        private Dictionary<string, Object> _dict;
+    }
+
     class AMIServicesStartedCallback : AMI_ServiceObserver_servicesStarted
     {
         public AMIServicesStartedCallback(ServiceManagerI serviceManager, ServiceObserverPrx observer)
@@ -81,7 +122,7 @@ class ServiceManagerI : ServiceManagerDisp_
         _logger = _communicator.getLogger();
         _argv = args;
         _traceServiceObserver = _communicator.getProperties().getPropertyAsInt("IceBox.Trace.ServiceObserver");
-
+        _localServiceManager = new LocalServiceManagerI();
     }
 
     public override Dictionary<string, string>
@@ -619,6 +660,16 @@ class ServiceManagerI : ServiceManagerDisp_
                 throw e;
             }
 
+            try
+            {
+                ServiceWithLocalServices lservice = (ServiceWithLocalServices)info.service;
+                lservice.setLocalServiceManager(_localServiceManager);
+            }
+            catch(System.InvalidCastException)
+            {
+                // Nothing to do here, object does not implement ServiceWithLocalServices
+            }
+
             //
             // Invoke Service::start().
             //
@@ -1030,6 +1081,7 @@ class ServiceManagerI : ServiceManagerDisp_
     private bool _pendingStatusChanges = false;
     private Dictionary<ServiceObserverPrx, bool> _observers = new  Dictionary<ServiceObserverPrx, bool>();
     private int _traceServiceObserver = 0;
+    private LocalServiceManager _localServiceManager;
 }
 
 }
diff --git a/java/src/IceBox/ServiceManagerI.java b/java/src/IceBox/ServiceManagerI.java
index 72dd24f..6230c76 100644
--- a/java/src/IceBox/ServiceManagerI.java
+++ b/java/src/IceBox/ServiceManagerI.java
@@ -22,6 +22,7 @@ public class ServiceManagerI extends _ServiceManagerDisp
         _logger = _communicator.getLogger();
         _argv = args;
         _traceServiceObserver = _communicator.getProperties().getPropertyAsInt("IceBox.Trace.ServiceObserver");
+        _localServiceManager = new LocalServiceManagerI();
     }
 
     public java.util.Map<String, String>
@@ -515,6 +516,16 @@ public class ServiceManagerI extends _ServiceManagerDisp
             throw e;
         }
 
+        try
+        {
+            ServiceWithLocalServices lservice = (ServiceWithLocalServices)info.service;
+            lservice.setLocalServiceManager(_localServiceManager);
+        }
+        catch(ClassCastException ex)
+        {
+            // Nothing to do here, the object does not implement ServiceWithLocalServices
+        }
+
         //
         // Invoke Service::start().
         //
@@ -944,6 +955,40 @@ public class ServiceManagerI extends _ServiceManagerDisp
         String className;
     }
 
+    static class LocalServiceManagerI implements LocalServiceManager
+    {
+        public LocalServiceManagerI()
+        {
+            _dict = new java.util.HashMap<String, Object>();
+        }
+
+        public void addLocalService(String name, Object service)
+        {
+            synchronized(this)
+            {
+                _dict.put(name, service);
+            }
+        }
+
+        public void removeLocalService(String name)
+        {
+            synchronized(this)
+            {
+                _dict.remove(name);
+            }
+        }
+
+        public Object findLocalService(String name)
+        {
+            synchronized(this)
+            {
+                return _dict.get(name);
+            }
+        }
+
+        private java.util.Map<String, Object> _dict;
+    }
+
     private Ice.Properties
     createServiceProperties(String service)
     {
@@ -977,6 +1022,7 @@ public class ServiceManagerI extends _ServiceManagerDisp
     private String[] _argv; // Filtered server argument vector
     private java.util.List<ServiceInfo> _services = new java.util.LinkedList<ServiceInfo>();
     private boolean _pendingStatusChanges = false;
+    private LocalServiceManager _localServiceManager;
 
     java.util.HashSet<ServiceObserverPrx> _observers = new java.util.HashSet<ServiceObserverPrx>();
     int _traceServiceObserver = 0;
diff --git a/slice/IceBox/IceBox.ice b/slice/IceBox/IceBox.ice
index eb6d044..f5b5b8e 100644
--- a/slice/IceBox/IceBox.ice
+++ b/slice/IceBox/IceBox.ice
@@ -115,6 +115,75 @@ local interface Service
     void stop();
 };
 
+/**
+ *
+ * IceBox can provide a 'directory' of local services, which are objects
+ * provided by application services in the IceBox container that are directly
+ * accessible by other application services, without the need of proxies
+ * (i.e. as local Ice objects). Any application service wishing to use
+ * this facility can derive its service object from [ServiceWithLocalServices]
+ * and IceBox will automatically provide a reference the [LocalServiceManager].
+ *
+ **/
+local interface LocalServiceManager
+{
+    /**
+     *
+     * Register a local service.
+     *
+     * <p class="Note">If an existing service is in the [LocalServiceManager]
+     * with the provided name, it will be replaced.
+     *
+     * @param name The service's name.
+     *
+     * @param service A reference to the object providing the service.
+     *
+     **/
+    void addLocalService(string name, LocalObject service);
+
+    /**
+     *
+     * Unregister a local service.
+     *
+     * <p class="Note">If no existing service is in the [LocalServiceManager]
+     * with the provided name, no operation will be performed.
+     *
+     * @param name The service's name.
+     *
+     **/
+    void removeLocalService(string name);
+
+    /**
+     *
+     * Find a local service.
+     *
+     * @param name The service's name.
+     *
+     * @return A reference to the object providing the requested service,
+     * or null if no service by that name was found.
+     *
+     **/
+    LocalObject findLocalService(string name);
+};
+
+/**
+ *
+ * An application service managed by a [ServiceManager] that uses the [LocalServiceManager].
+ *
+ **/
+local interface ServiceWithLocalServices extends Service
+{
+    /**
+     *
+     * Set the service's [LocalServiceManager] reference. IceBox will
+     * call this operation before instantiating the service's object.
+     *
+     * @param manager The [LocalServiceManager] provided by the IceBox
+     * instance.
+     *
+     **/
+    void setLocalServiceManager(LocalServiceManager manager);
+};
 
 /**
  *

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice.git



More information about the asterisk-scf-commits mailing list