コード例 #1
0
ファイル: ServiceRegistry.cs プロジェクト: zhaoyin/officeOBA
        /// <summary>
        /// 根据过滤条件和接口契约查找服务注册者
        /// </summary>
        /// <param name="clazz"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private IList LookupServiceRegistrations(string clazz, IFilter filter)
        {
            IList result;

            lock (this)
            {
                if (clazz == null)
                { /* all services */
                    result = allPublishedServices;
                }
                else
                {
                    /* services registered under the class name */
                    result = (IList)publishedServicesByClass[clazz];
                }

                if ((result == null) || (result.Count == 0))
                {
                    return(null);
                }

                result = new ArrayList(result); /* make a new list since we don't want to change the real list */
            }

            if (filter == null)
            {
                return(result);
            }

            IList listWaitForDeleting = new ArrayList();
            var   iter = result.GetEnumerator();

            while (iter.MoveNext())
            {
                ServiceRegistrationImpl registration = (ServiceRegistrationImpl)iter.Current;
                ServiceReferenceImpl    reference;
                try
                {
                    reference = registration.GetReferenceImpl();
                }
                catch (Exception e)
                {
                    Log.Warn(e);
                    listWaitForDeleting.Add(iter.Current); /* service was unregistered after we left the synchronized block above */
                    continue;
                }
                if (!filter.Match(reference))
                {
                    listWaitForDeleting.Add(iter.Current);
                }
            }

            foreach (var item in listWaitForDeleting)
            {
                result.Remove(item);
            }

            return(result);
        }