Exemplo n.º 1
0
        private T GetOrCreateTopic <T>(string name)
        {
            using (var @rlock = m_lockScope.Reader(Timeout))
            {
                if ([email protected])
                {
                    throw new TimeoutException("Get topic has timed out");
                }

                T value;
                if (!DictionaryHelper.TryGetValue <T>(m_catalog, name, out value))
                {
                    using (var @wlock = m_lockScope.UpgradeToWriter(Timeout))
                    {
                        if ([email protected])
                        {
                            throw new TimeoutException("Create topic has timed out");
                        }

                        value           = (T)Activator.CreateInstance(typeof(T), name);
                        m_catalog[name] = value;
                    }
                }

                return(value);
            }
        }
Exemplo n.º 2
0
        public override T Take(object state)
        {
            T item = state as T;

            using (var @rlock = m_lockScope.Reader(m_timeout))
            {
                if ([email protected])
                {
                    if (g_traceInfo.IsWarningEnabled)
                    {
                        TraceHelper.TraceWarning(g_traceInfo, "{0} - Take timed out", Name);
                    }

                    return(default(T));
                }

                if (item != null)
                {
                    using (var @wlock = m_lockScope.UpgradeToWriter(m_timeout))
                    {
                        if ([email protected])
                        {
                            if (g_traceInfo.IsWarningEnabled)
                            {
                                TraceHelper.TraceWarning(g_traceInfo, "{0} - Take timed out on remove", Name);
                            }

                            return(default(T));
                        }

                        if (!Remove(item))
                        {
                            if (g_traceInfo.IsWarningEnabled)
                            {
                                TraceHelper.TraceWarning(g_traceInfo, "{0} - Failed to remove", Name);
                            }

                            return(default(T));
                        }
                    }
                }
                else
                {
                    item = Lookup(state);
                }
            }

            return(item);
        }