Example #1
0
        private Broker(RemoteCache cache, bool importHashMap, PerfStatsCollector2 perfStatsColl,
            CacheInitParams initParams)
        {
            _bulkEventCallback = new WaitCallback(RaiseBulkEvent);
            this._clientConfig = new ClientConfiguration(cache.CacheId, initParams);
            this._cache = cache;
            this._balanceNode = _clientConfig.BalanceNodes;
            this._importHashmap = _clientConfig.ImportHashmap;

            this._operationTimeout = _clientConfig.Timeout;
            this._connectionTimeout = _clientConfig.ConnectionTimeout;
            this._connectionRetries = _clientConfig.ConnectionRetries;
            this._retryInterval = _clientConfig.RetryInterval;

            this._retryConnnectionDelay = _clientConfig.RetryConnectionDelay;
            this._retryConnectionDelayInMinutes = Convert.ToDouble(_retryConnnectionDelay)/60000;
                //Conversion to minutes from milliseconds;
            _perfStatsColl2 = perfStatsColl;

            int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
            string instanceName = "Client." + cache.CacheId + "." + pid;

            if (_perfStatsColl == null || !_perfStatsColl.InstanceName.Equals(instanceName))
            {
                _perfStatsColl = new PerfStatsCollector(instanceName, 0);
            }

            this._commandReieved = new OnCommandRecieved(CommandReceived);
            this._serverLost = new OnServerLost(ServerLost);
            this._requestTable = Hashtable.Synchronized(new Hashtable(10000, 0.75f));
            this._pool = new ConnectionPool();
        }
Example #2
0
        private static Cache InitializeCacheInternal(string cacheId, CacheInitParams initParams)
        {
            if (cacheId == null) throw new ArgumentNullException("cacheId");
            if (cacheId == string.Empty) throw new ArgumentException("cacheId cannot be an empty string");

            CacheMode mode = initParams.Mode;

            int maxTries = 2;
            try
            {
                CacheServerConfig config = null;

                if (mode != CacheMode.OutProc)
                {
                    do
                    {
                        try
                        {
                            config = DirectoryUtil.GetCacheDom(cacheId, mode == CacheMode.InProc);
                        }
                        catch (Exception ex)
                        {
                            if (mode == CacheMode.Default)
                                mode = CacheMode.OutProc;
                            else
                                throw ex;
                        }
                        if (config != null)
                        {
                            switch (mode)
                            {
                                case CacheMode.InProc: config.InProc = true; break;
                                case CacheMode.OutProc: config.InProc = false; break;
                            }
                        }
                        break; //muds: break the while loop...
                    } while (maxTries > 0);
                }

                lock (typeof(NCache))
                {

                    Cache primaryCache = null;

                    lock (s_webCaches)
                    {
                        if (!s_webCaches.Contains(cacheId))
                        {
                            CacheImplBase cacheImpl = null;

                            if (config != null && config.InProc)
                            {
                                Alachisoft.NCache.Caching.Cache ncache = null;
                                Cache cache = null;
                                maxTries = 2;
                                do
                                {
                                    try
                                    {
                                        CacheConfig cacheConfig = CacheConfig.FromDom(config);

                                        if (Web.Caching.APILogging.DebugAPIConfiguraions.LoggingEnabled)
                                            cache = new WrapperCache(new Cache(null, cacheConfig));
                                        else
                                            cache = new Cache(null, cacheConfig);

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

                                        cacheImpl = new InprocCache(ncache, cacheConfig, cache);
                                        cache.CacheImpl = cacheImpl;

                                        if (primaryCache == null)
                                            primaryCache = cache;
                                        break;
                                    }
                                    catch (Exception) { }

                                } while (maxTries > 0);
                            }
                            else
                            {
                                maxTries = 2;
                                do
                                {
                                    try
                                    {
                                        // does an AddRef() internally.

                                        PerfStatsCollector2 perfStatsCollector = new PerfStatsCollector2(cacheId, false);

                                        if (Web.Caching.APILogging.DebugAPIConfiguraions.LoggingEnabled)
                                            primaryCache = new WrapperCache(new Cache(null, cacheId, perfStatsCollector));
                                        else

                                            primaryCache = new Cache(null, cacheId, perfStatsCollector);
                                        cacheImpl = new RemoteCache(cacheId, primaryCache, initParams, perfStatsCollector);

                                        perfStatsCollector.InitializePerfCounters(false);
                                        primaryCache.CacheImpl = cacheImpl;

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

                            if (primaryCache != null)
                            {
                                primaryCache.InitializeCompactFramework();
                                s_webCaches.AddCache(cacheId, primaryCache);
                            }
                        }
                        else
                        {
                            lock (s_webCaches.GetCache(cacheId))
                            {
                                primaryCache = s_webCaches.GetCache(cacheId) as Cache;
                                primaryCache.AddRef();
                            }
                        }
                    }

                    lock (s_webCache)
                    {
                        // it is first cache instance.
                        if (s_webCache.CacheImpl == null)
                        {
                            primaryCache.ExceptionsEnabled = ExceptionsEnabled;
                            s_webCache = primaryCache;
                        }
                    }
            return primaryCache;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
 internal Broker(RemoteCache cache, CacheInitParams initParams, PerfStatsCollector2 statsCol)
     : this(cache, true, statsCol, initParams)
 {
 }