예제 #1
0
파일: Topic.cs 프로젝트: yongwuhou/NCache
 /// <summary>
 ///
 /// </summary>
 /// <param name="topicName"></param>
 /// <param name="cacheImpl"></param>
 /// <param name="perfStatsCollector"></param>
 /// <param name="parent"></param>
 internal Topic(string topicName, CacheImplBase cacheImpl, StatisticsCounter perfStatsCollector, MessageManager parent)
 {
     _topicName          = topicName;
     _subscriptions      = new Dictionary <SubscriptionIdentifier, TopicSubscription>();
     _cacheImpl          = cacheImpl;
     _perfStatsCollector = perfStatsCollector;
     _parent             = parent;
     _publisherId        = new Shorter().GuidString;
     _readerWriterLock   = new ReaderWriterLock();
 }
예제 #2
0
        public void Dispose()
        {
            StopPolling();

            foreach (Topic messageTopic in _topicsDic.Values)
            {
                messageTopic.DisposeInternal(false);
            }
            _topicsDic.Clear();

            _cacheImpl = null;
        }
예제 #3
0
 public virtual T SafeDeserialize <T>(object serializedObject, string serializationContext, BitSet flag, CacheImplBase cacheImpl, UserObjectType userObjectType)
 {
     return(default(T));
 }
예제 #4
0
 public virtual object SafeSerialize(object serializableObject, string serializationContext, ref BitSet flag, CacheImplBase cacheImpl, ref long size, UserObjectType userObjectType, bool isCustomAttributeBaseSerialzed = false)
 {
     return(null);
 }
예제 #5
0
        private static Cache GetCacheInternal(string cacheName, CacheConnectionOptions cacheConnectionOptions)

        {
            if (cacheName == null)
            {
                throw new ArgumentNullException("cacheId");
            }
            if (cacheName == string.Empty)
            {
                throw new ArgumentException("cacheId cannot be an empty string");
            }

            IsolationLevel mode = cacheConnectionOptions.Mode.Value;



            string cacheIdWithAlias = cacheName;

            int maxTries = 2;


            try
            {
                CacheServerConfig config = null;

                if (mode != IsolationLevel.OutProc)
                {
                    do
                    {
                        try
                        {
                            config = DirectoryUtil.GetCacheDom(cacheName,
                                                               null,
                                                               null,
                                                               mode == IsolationLevel.InProc);
                        }


                        catch (Exception ex)
                        {
                            if (mode == IsolationLevel.Default)
                            {
                                mode = IsolationLevel.OutProc;
                            }
                            else
                            {
                                throw ex;
                            }
                        }
                        if (config != null)
                        {
                            if (config.CacheType.ToLower().Equals("clustered-cache"))
                            {
                                throw new OperationFailedException(ErrorCodes.CacheInit.CLUSTER_INIT_IN_INPROC, ErrorMessages.GetErrorMessage(ErrorCodes.CacheInit.CLUSTER_INIT_IN_INPROC));
                            }
                            switch (mode)
                            {
                            case IsolationLevel.InProc: config.InProc = true; break;

                            case IsolationLevel.OutProc: config.InProc = false; break;
                            }
                        }
                        break;
                    } while (maxTries > 0);
                }

                lock (typeof(CacheManager))
                {
                    Cache primaryCache = null;

                    lock (_cacheCollection)
                    {
                        if (!_cacheCollection.Contains(cacheIdWithAlias))
                        {
                            CacheImplBase cacheImpl = null;

                            if (config != null && config.InProc)
                            {
                                NCache.Caching.Cache ncache = null;
                                Cache cache = null;
                                maxTries = 2;

                                do
                                {
                                    try
                                    {
                                        CacheConfig cacheConfig = CacheConfig.FromDom(config);

                                        cache = new Cache(null, cacheConfig);


                                        ncache = CacheFactory.CreateFromPropertyString(cacheConfig.PropertyString, config, null, null, false, false);


                                        cacheImpl = new InprocCache(ncache, cacheConfig, cache, null, null);

                                        cache.CacheImpl = cacheImpl;

                                        if (primaryCache == null)
                                        {
                                            primaryCache = cache;
                                        }
                                        else
                                        {
                                            primaryCache.AddSecondaryInprocInstance(cache);
                                        }

                                        break;
                                    }
                                    catch (SecurityException se)
                                    {
                                        maxTries--;

                                        if (maxTries == 0)
                                        {
                                            throw se;
                                        }
                                    }
                                } while (maxTries > 0);
                            }
                            else
                            {
                                maxTries = 2;
                                do
                                {
                                    try
                                    {
                                        StatisticsCounter perfStatsCollector;
                                        if (ServiceConfiguration.PublishCountersToCacheHost)
                                        {
                                            perfStatsCollector = new CustomStatsCollector(cacheName, false);
                                            ClientConfiguration clientConfig = new ClientConfiguration(cacheName);
                                            clientConfig.LoadConfiguration();
                                            perfStatsCollector.StartPublishingCounters(clientConfig.BindIP);
                                        }
                                        else
                                        {
                                            perfStatsCollector = new PerfStatsCollector(cacheName, false);
                                        }


                                        primaryCache = new Cache(null, cacheName, perfStatsCollector);

                                        cacheImpl = new RemoteCache(cacheName, primaryCache, cacheConnectionOptions, perfStatsCollector);
                                        perfStatsCollector.InitializePerfCounters(false);
                                        primaryCache.CacheImpl = cacheImpl;

                                        break;
                                    }

                                    catch (OperationNotSupportedException ex)
                                    {
                                        throw ex;
                                    }
                                } while (maxTries > 0);
                            }

                            if (primaryCache != null)
                            {
                                primaryCache.InitializeCompactFramework();
                                _cacheCollection.AddCache(cacheIdWithAlias, primaryCache);
                            }
                        }
                        else
                        {
                            lock (_cacheCollection.GetCache(cacheIdWithAlias, false))
                            {
                                primaryCache = _cacheCollection.GetCache(cacheIdWithAlias, false) as Cache;

                                primaryCache.AddRef();
                            }
                        }
                    }

                    lock (_cache)
                    {
                        // it is first cache instance.
                        if (_cache.CacheImpl == null)
                        {
                            primaryCache.ExceptionsEnabled = ExceptionsEnabled;
                            _cache = primaryCache;
                        }
                    }

                    return(primaryCache);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }