Пример #1
0
        public override void StopCacheInstance(string cacheName, CacheInfo cacheInfo, CacheStopReason reason)
        {
            LeasedCache cache = cacheInfo.Cache;

            if (cache != null && cache.Name == cacheName)
            {
                if (cache.IsRunning)
                {
                    if (reason.Equals(CacheStopReason.Expired))
                    {
                        cache.NCacheLog.CriticalInfo("NCache license has expired on this machine. Stopping cache...");
                    }
                    cache.Stop();
                    if (cacheInfo != null)
                    {
                        cacheInfo.SyncConfiguration();
                    }

                    //instrumentation Code
#if COMMUNITY
                    if (InstrumentCache.OnCacheStopped != null)
                    {
                        InstrumentCache.OnCacheStopped(cache.Name);
                    }
#endif
                }
            }
            else
            {
                throw new Runtime.Exceptions.ManagementException("Specified cacheId is not registered");
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="nCache"></param>
        internal InprocCacheEventsListener(CacheEventsListenerBase parent, Alachisoft.NCache.Caching.Cache nCache)
        {
            _listener = parent;
            _nCache   = nCache;


            _itemAdded          = new ItemAddedCallback(this.OnItemAdded);
            _itemUpdated        = new ItemUpdatedCallback(this.OnItemUpdated);
            _itemRemoved        = new ItemRemovedCallback(this.OnItemRemoved);
            _cacheCleared       = new Alachisoft.NCache.Caching.CacheClearedCallback(this.OnCacheCleared);
            _customNotification =
                new Alachisoft.NCache.Caching.CustomNotificationCallback(this.OnCustomNotification);
            _cacheStopped  = new Alachisoft.NCache.Caching.CacheStoppedCallback(this.OnCacheStopped);
            _queryChanged  = new ActiveQueryCallback(this.OnActiveQueryChanged);
            _pollRequested = OnPollNotified;

            _nCache.ItemAdded    += _itemAdded;
            _nCache.ItemUpdated  += _itemUpdated;
            _nCache.ItemRemoved  += _itemRemoved;
            _nCache.CacheCleared += _cacheCleared;
            _nCache.CustomNotif  += _customNotification;
            _nCache.CacheStopped += _cacheStopped;


            _customRemoveCallback = new CustomRemoveCallback(this.OnCustomRemoveCallback);
            _customUpdateCallback = new CustomUpdateCallback(this.OnCustomUpdateCallback);


            _nCache.CustomRemoveCallbackNotif += _customRemoveCallback;
            _nCache.CustomUpdateCallbackNotif += _customUpdateCallback;

            _nCache.ActiveQueryCallbackNotif += _queryChanged;
        }
Пример #3
0
        /// <summary>
        /// Initialize a registered cache given by the ID.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="timeout"></param>
        /// <exception cref="ArgumentNullException">data is a null reference (Nothing in Visual Basic).</exception>
        /// <returns>A reference to <see cref="Cache"/> object.</returns>
        public static Alachisoft.NCache.Caching.Cache GetCacheInstance(CacheConfig data, TimeSpan timeout, bool autoStart)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            try
            {
                if (data == null)
                {
                    return(null);
                }
                if (data.UseInProc)
                {
                    return(CacheFactory.CreateFromPropertyString(data.PropertyString));
                }

                Alachisoft.NCache.Caching.Cache cache = ConnectCacheInstance(data, timeout, autoStart);
                return(cache);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #4
0
        public override void StopCacheInstance(string cacheName, CacheInfo cacheInfo, CacheServer.CacheStopReason reason)
        {
            LeasedCache cache = cacheInfo.Cache;

            if (cache != null && cache.Name == cacheName)
            {
                if (cache.IsRunning)
                {
                    if (!cache.VerifyNodeShutDown())
                    {
                        throw new Runtime.Exceptions.ManagementException("Graceful shutdown is already in progress...");
                    }

                    if (reason.Equals(CacheStopReason.Expired))
                    {
                        cache.NCacheLog.CriticalInfo("NCache license has expired on this machine. Stopping cache...");
                    }

                    cache.Stop();
                    if (cacheInfo != null)
                    {
                        cacheInfo.SyncConfiguration();
                    }

                    if (InstrumentCache.OnCacheStopped != null)
                    {
                        InstrumentCache.OnCacheStopped(cache.Name);
                    }
                }
            }
            else
            {
                throw new Runtime.Exceptions.ManagementException(ErrorCodes.CacheInit.CACHE_ID_NOT_REGISTERED, ErrorMessages.GetErrorMessage(ErrorCodes.CacheInit.CACHE_ID_NOT_REGISTERED));
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize the cache instance.
        /// </summary>
        internal NCache(string cacheId, ClientManager client)
        {
            this._cacheId = cacheId;
            this._client = client;

            try
            {
              _cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cacheId);
            }
            catch (Exception) { throw; }

            if (_cache == null) throw new Exception("Cache is not registered");
            if (!_cache.IsRunning) throw new Exception("Cache is not running");

            _onItemUpdatedCallback = new CustomUpdateCallback(CustomUpdate);
            _cache.CustomUpdateCallbackNotif += _onItemUpdatedCallback;

            _onItemRemoveCallback = new CustomRemoveCallback(CustomRemove);
            _cache.CustomRemoveCallbackNotif += _onItemRemoveCallback;

            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver+".ctor", "Registering cache stopped event for " + _client.ClientID);
            }

            _cacheStopped = new CacheStoppedCallback(OnCacheStopped);
            _cache.CacheStopped += _cacheStopped;

            if (SocketServer.Logger.IsErrorLogsEnabled) SocketServer.Logger.NCacheLog.Error(_cacheserver+".ctor", "Cache stopped event registered for " + _client.ClientID);
            _cache.ClientsInvalidated += new ClientsInvalidatedCallback(OnClientsInvalidated);

            _cache.OnClientConnected(client.ClientID, cacheId);
        }
Пример #6
0
        private void StartCacheInstance(LeasedCache cache, CacheInfo cacheInfo,
                                        ItemAddedCallback itemAdded,
                                        ItemRemovedCallback itemRemoved,
                                        ItemUpdatedCallback itemUpdated,
                                        CacheClearedCallback cacheCleared,
                                        CustomRemoveCallback customRemove,
                                        CustomUpdateCallback customUpdate,
                                        bool twoPhaseInitialization)
        {
            if (cache != null)
            {
                if (itemAdded != null)
                {
                    cache.ItemAdded += itemAdded;
                }
                if (itemRemoved != null)
                {
                    cache.ItemRemoved += itemRemoved;
                }
                if (itemUpdated != null)
                {
                    cache.ItemUpdated += itemUpdated;
                }
                if (cacheCleared != null)
                {
                    cache.CacheCleared += cacheCleared;
                }
                if (customRemove != null)
                {
                    cache.CustomRemoveCallbackNotif += customRemove;
                }
                if (customUpdate != null)
                {
                    cache.CustomUpdateCallbackNotif += customUpdate;
                }

                if (!cache.IsRunning)
                {
                    cacheInfo.SyncConfiguration();
                    cache.StartInstance(Renderer, twoPhaseInitialization);

#if COMMUNITY
                    if (InstrumentCache.OnCacheStarted != null)
                    {
                        InstrumentCache.OnCacheStarted(cache.Name);
                    }
#endif
                }
            }

            else
            {
                throw new Runtime.Exceptions.ManagementException("Specified cacheId is not registered");
            }
        }
Пример #7
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID));
                }
                return;
            }

            Alachisoft.NCache.Caching.Cache cache = null;

            try
            {
                string server = ConnectionManager.ServerIpAddress;
                int    port   = ConnectionManager.ServerPort;

                Dictionary <string, int> runningServers = new Dictionary <string, int>();
                runningServers = ((NCache)clientManager.CmdExecuter).Cache.GetRunningServers(server, port);

                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetRunningServersResponse getRunningServerResponse = new Alachisoft.NCache.Common.Protobuf.GetRunningServersResponse();

                //getRunningServerResponse = new List<Common.Protobuf.KeyValuePair>();
                if (runningServers != null)
                {
                    Dictionary <string, int> .Enumerator ide = runningServers.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        Common.Protobuf.KeyValuePair pair = new Common.Protobuf.KeyValuePair();
                        pair.key   = ide.Current.Key;
                        pair.value = ide.Current.Value.ToString();
                        getRunningServerResponse.keyValuePair.Add(pair);
                    }
                }

                response.requestId        = Convert.ToInt64(cmdInfo.RequestId);
                response.commandID        = command.commandID;
                response.getRunningServer = getRunningServerResponse;
                response.responseType     = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_RUNNING_SERVERS;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID));
            }
        }
Пример #8
0
 public override void ClearCacheContent(string cacheId)
 {
     if (cacheInfo != null)
     {
         InstrumentCache cache = cacheInfo.Cache;
         if (cache != null)
         {
             cache.Clear();
         }
     }
 }
Пример #9
0
 public override void ApplyHotConfiguration(string cacheId, HotConfig hotConfig)
 {
     if (cacheInfo != null)
     {
         InstrumentCache cache = cacheInfo.Cache;
         if (cache != null)
         {
             cache.ApplyHotConfiguration(hotConfig);
         }
     }
 }
Пример #10
0
        private void StartCacheInstance(LeasedCache cache, CacheInfo cacheInfo,
                                        ItemAddedCallback itemAdded,
                                        ItemRemovedCallback itemRemoved,
                                        ItemUpdatedCallback itemUpdated,
                                        CacheClearedCallback cacheCleared,
                                        CustomRemoveCallback customRemove,
                                        CustomUpdateCallback customUpdate,
                                        bool twoPhaseInitialization)
        {
            if (cache != null)
            {
                if (itemAdded != null)
                {
                    cache.ItemAdded += itemAdded;
                }
                if (itemRemoved != null)
                {
                    cache.ItemRemoved += itemRemoved;
                }
                if (itemUpdated != null)
                {
                    cache.ItemUpdated += itemUpdated;
                }
                if (cacheCleared != null)
                {
                    cache.CacheCleared += cacheCleared;
                }
                if (customRemove != null)
                {
                    cache.CustomRemoveCallbackNotif += customRemove;
                }
                if (customUpdate != null)
                {
                    cache.CustomUpdateCallbackNotif += customUpdate;
                }

                if (!cache.IsRunning)
                {
                    cacheInfo.SyncConfiguration();
                    cache.StartInstance(Renderer, twoPhaseInitialization);

                    if (InstrumentCache.OnCacheStarted != null)
                    {
                        InstrumentCache.OnCacheStarted(cache.Name);
                    }
                }
            }

            else
            {
                throw new Runtime.Exceptions.ManagementException(ErrorCodes.CacheInit.CACHE_ID_NOT_REGISTERED, ErrorMessages.GetErrorMessage(ErrorCodes.CacheInit.CACHE_ID_NOT_REGISTERED));
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="nCache"></param>
        internal InprocCacheAsyncEventsListener(CacheAsyncEventsListenerBase parent,
                                                Alachisoft.NCache.Caching.Cache nCache)
        {
            _parent = parent;
            _nCache = nCache;

            _asyncOperationCompleted         = new AsyncOperationCompletedCallback(this.OnAsyncOperationCompleted);
            _nCache.AsyncOperationCompleted += _asyncOperationCompleted;

            _dsUpdatedCallback         = new DataSourceUpdatedCallback(this.OnDSUpdated);
            _nCache.DataSourceUpdated += _dsUpdatedCallback;
        }
Пример #12
0
 public override CacheStatistics GetStatistics(string cacheId)
 {
     if (cacheInfo != null)
     {
         InstrumentCache cache = cacheInfo.Cache;
         if (cache != null && cache.IsRunning)
         {
             return(cache.Statistics);
         }
     }
     return(null);
 }
Пример #13
0
 public override bool IsUnderStateTransfer(string cacheId)
 {
     if (cacheInfo != null)
     {
         InstrumentCache cache = cacheInfo.Cache;
         if (cache != null && cache.IsRunning)
         {
             return(cache.IsClusterInStateTransfer());
         }
     }
     return(false);
 }
Пример #14
0
 public override bool CanApplyHotConfiguration(string cacheId, long size)
 {
     if (cacheInfo != null)
     {
         InstrumentCache cache = cacheInfo.Cache;
         if (cache != null)
         {
             return(cacheInfo.Cache.IsHotApplyFeasible(size * 1024 * 1024));
         }
     }
     return(false);
 }
Пример #15
0
        public override void BalanceDataloadOnCache(string cacheId)
        {
            if (cacheInfo != null)
            {
                InstrumentCache cache = cacheInfo.Cache;

                if (cache != null)
                {
                    cache.BalanceDataLoad();
                }
            }
        }
Пример #16
0
        public override double GetCounterValue(string cacheId, string counterName, string category, bool replica = false)
        {
            double value = 0.0;

            if (cacheInfo != null)
            {
                InstrumentCache cache = cacheInfo.Cache;
                if (cache != null && !string.IsNullOrEmpty(cacheId) && cache.Name.ToLower().Equals(cacheId.ToLower()))
                {
                    value = cache.GetCounterValue(counterName, replica, category);
                }
            }
            return(value);
        }
Пример #17
0
 public Exception CanApplyHotConfig(CacheServerConfig config)
 {
     if (cacheInfo != null)
     {
         if (cacheInfo != null)
         {
             InstrumentCache cache = cacheInfo.Cache;
             if (cache != null)
             {
                 return(cacheInfo.Cache.CanApplyHotConfig(config.Storage.Size * 1024 * 1024));
             }
         }
     }
     return(null);
 }
Пример #18
0
 public override bool  IsRunning(string cacheId)
 {
     if (cacheInfo != null)
     {
         InstrumentCache cache = cacheInfo.Cache;
         if (cache != null && !String.IsNullOrEmpty(cacheId))
         {
             if (cache.Name.ToLower().Equals(cacheId.ToLower()))
             {
                 return(cache.IsRunning);
             }
         }
     }
     return(false);
 }
Пример #19
0
        public override CacheNodeStatistics[] GetCacheStatistics(string cacheId)
        {
            Alachisoft.NCache.Caching.Cache cache      = GetCacheInstance(cacheId.ToLower(), null);
            List <CacheNodeStatistics>      statistics = null;

            if (cache != null)
            {
                statistics = cache.GetCacheNodeStatistics();
                if (statistics != null)
                {
                    return(statistics.ToArray());
                }
            }
            return(null);
        }
Пример #20
0
        public override Dictionary <string, Common.FeatureUsageData.Feature> GetFeatureUsageReport(string cacheId)
        {
            Dictionary <string, Common.FeatureUsageData.Feature> featureUsageReport = null;

            if (cacheInfo != null)
            {
                InstrumentCache cache = cacheInfo.Cache;
                if (cache != null)
                {
                    featureUsageReport = cache.GetCacheFeaturesUsageReport();
                }
            }

            return(featureUsageReport);
        }
Пример #21
0
        public override ClientProfileDom GetClientProfileReport(string cacheId)
        {
            ClientProfileDom clientProfile = null;

            if (cacheInfo != null)
            {
                InstrumentCache cache = cacheInfo.Cache;
                if (cache != null)
                {
                    clientProfile = cache.GetClientProfileReport();
                }
            }

            return(clientProfile);
        }
Пример #22
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager).clone();
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithoutType(exc, command.requestID, command.commandID));
                }
                return;
            }

            Alachisoft.NCache.Caching.Cache cache = null;

            try
            {
                string server = ConnectionManager.ServerIpAddress;
                int    port   = ConnectionManager.ServerPort;
                cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cmdInfo.CacheId);
                if (cache == null)
                {
                    throw new Exception("Cache is not registered");
                }
                if (!cache.IsRunning)
                {
                    throw new Exception("Cache is not running");
                }


#if (SERVER)
                if (cache.CacheType.Equals("replicated-server"))
                {
                    cache.GetLeastLoadedServer(ref server, ref port);
                }
                else
                {
                    if (cache.IsCoordinator) /*return this node information...*/ } {
                    else
                    {
                        cache.GetActiveServer(ref server, ref port);
                    }
            }
Пример #23
0
        public override Dictionary <string, TopicStats> GetTopicStats(string cacheId, bool defaultTopicStats = false)
        {
            Dictionary <string, TopicStats> topicStatList = new Dictionary <string, TopicStats>();

            if (cacheId == null)
            {
                throw new ArgumentNullException("cacheId");
            }
            if (cacheInfo != null)
            {
                InstrumentCache cache = cacheInfo.Cache;
                if (cache != null && !string.IsNullOrEmpty(cacheId) && cache.Name.ToLower().Equals(cacheId.ToLower()))
                {
                    topicStatList = cache.GetTopicsStats(defaultTopicStats);
                }
            }
            return(topicStatList);
        }
Пример #24
0
 private void StartCacheInstance(LeasedCache cache, CacheInfo cacheInfo, bool twoPhaseInitialization)
 {
     if (cache != null)
     {
         if (!cache.IsRunning)
         {
             cacheInfo.SyncConfiguration();
             cache.StartInstance(Renderer, twoPhaseInitialization);
             if (InstrumentCache.OnCacheStarted != null)
             {
                 InstrumentCache.OnCacheStarted(cache.Name);
             }
         }
     }
     else
     {
         throw new Runtime.Exceptions.ManagementException("Specified cacheId is not registered");
     }
 }
Пример #25
0
        public override void StopCacheInstance(string cacheName, CacheInfo cacheInfo, CacheServer.CacheStopReason reason)
        {
            LeasedCache cache = cacheInfo.Cache;

            if (cache != null && cache.Name == cacheName)
            {
                if (cache.IsRunning)
                {
                    cache.Stop();
                    if (cacheInfo != null)
                    {
                        cacheInfo.SyncConfiguration();
                    }
                    InstrumentCache.OnCacheStopped(cache.Name);
                }
            }
            else
            {
                throw new Runtime.Exceptions.ManagementException("Specified cacheId is not registered");
            }
        }
Пример #26
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;
                    } 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;
            }
        }
Пример #27
0
		/// <summary>
		/// Internal method that actually creates the cache. A HashMap containing the config parameters 
		/// is passed to this method.
		/// </summary>
		/// <param name="propertyTable">contains the properties provided by the user in the for of Hashtable</param>
		/// <param name="itemAdded">item added handler</param>
		/// <param name="itemRemoved">item removed handler</param>
		/// <param name="itemUpdated">item updated handler</param>
		/// <param name="cacheMiss">cache miss handler</param>
		/// <param name="cacheCleared">cache cleared handler</param>
		/// <returns>return the Cache object</returns>
		static private Cache CreateFromProperties(IDictionary properties,
                                        CacheServerConfig config,
										CustomRemoveCallback customRemove,
										CustomUpdateCallback customUpdate,
                                        bool isStartingAsMirror,
                                        bool twoPhaseInitialization)
		{
			Cache cache = new Cache();
            cache.Configuration = config;
            if (customRemove != null)
                cache.CustomRemoveCallbackNotif += customRemove;
            if (customUpdate != null)
                cache.CustomUpdateCallbackNotif += customUpdate;

            cache.Initialize(properties, true, isStartingAsMirror,twoPhaseInitialization);
			return cache;
		}
Пример #28
0
 public EntryProcessorManager(String cacheName, CacheRuntimeContext context, Alachisoft.NCache.Caching.Cache cacheRoot)
 {
     _cacheName = cacheName;
     _context   = context;
     _cacheRoot = cacheRoot;
 }
Пример #29
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="nCache"></param>
 internal ClusterEventsListener(Cache.ClusterEventsListener parent, Alachisoft.NCache.Caching.Cache nCache)
 {
     _listener = parent;
     _nCache = nCache;
 }
Пример #30
0
        /// <summary>
        /// Initializes a new instance of the Cache class.
        /// </summary>
        /// <param name="objectCache"></param>
        /// <param name="config"></param>
        internal InprocCache(Alachisoft.NCache.Caching.Cache objectCache, CacheConfig config, Cache parent)
            : base()
        {
            _nCache = objectCache;

            this.TypeMap = _nCache.GetTypeInfoMap();
            _config = config;
            _parent = parent;

            if (_nCache != null)
            {
                _listener = new CacheEventsListener(_parent.EventListener, _nCache);
                _nCache.OnClientConnected(ClientID, _config.CacheId);
                _serializationContext = _nCache.Name; //Sets the serialization context.
            }

            AddRef();
        }
Пример #31
0
            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="parent"></param>
            /// <param name="nCache"></param>
            internal CacheEventsListener(Cache.CacheEventsListener parent, Alachisoft.NCache.Caching.Cache nCache)
            {
                _listener = parent;
                _nCache = nCache;
                _customRemoveCallback = new CustomRemoveCallback(this.OnCustomRemoveCallback);
                _customUpdateCallback = new CustomUpdateCallback(this.OnCustomUpdateCallback);
                _nCache.CustomRemoveCallbackNotif += _customRemoveCallback;
                _nCache.CustomUpdateCallbackNotif += _customUpdateCallback;


            }
Пример #32
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="nCache"></param>
 internal CacheAsyncEventsListener(Cache.CacheAsyncEventsListener parent, Alachisoft.NCache.Caching.Cache nCache)
 {
     _parent = parent;
     _nCache = nCache;
 }
Пример #33
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or 
        /// resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>The behavior of this method depends upon the cache's sharing mode (inproc/outproc) 
        /// specified in the configuration.
        /// <para>If the application uses the cache in <b>inproc</b> mode, calling Dispose closes the cache 
        /// and releases the resources used by it. If in a cluster the calling node leaves the 
        /// cluster as well. 
        /// </para>
        /// <para>If the application uses the cache in <b>outproc</b> mode, calling Dispose releases the 
        /// reference to the cache object. The cache itself remains operational and cluster remains intact. 
        /// </para>
        /// </remarks>
        private void DisposeInternal(bool disposing)
        {
            lock (this)
            {
                _refCount--;
                if (_refCount > 0) return;
                else if (_refCount < 0) _refCount = 0;
                lock (NCache.Caches)
                {
                    if (_config != null)
                        NCache.Caches.Remove(_config.CacheId);
                }
                if (_config != null && _config.UseInProc)
                {
                    if (_nCache != null) _nCache.Dispose();
                }

                _nCache = null;
                if (disposing) GC.SuppressFinalize(this);
            }
        }
Пример #34
0
		static private void PrintDetailedCacheInfo(Cache cache, string partId, bool printConf, bool xmlSyntax)
		{
			CacheStatistics s = cache.Statistics;
            long MaxSize=0;
            string schemeName = s.ClassName.ToLower(CultureInfo.CurrentCulture);
			bool running = cache.IsRunning;

			Console.WriteLine("Cache-ID:       {0}", cache.Name);
            
            if (partId != null && partId != string.Empty)
                Console.WriteLine("Partition-ID:   {0}", partId);

			Console.WriteLine("Scheme:         {0}", schemeName);
			Console.WriteLine("Status:         {0}", cache.IsRunning ? "Running":"Stopped");
			if(running)
			{
				if(s is ClusterCacheStatistics)
				{
					System.Text.StringBuilder nodes = new System.Text.StringBuilder();

					ClusterCacheStatistics cs = s as ClusterCacheStatistics;
                  
					Console.WriteLine("Cluster size:   {0}", cs.Nodes.Count);
                    
                    MaxSize = (cs.LocalNode.Statistics.MaxSize/1024)/1024;

                    
                    foreach (NodeInfo n in cs.Nodes)
                    {
                      nodes.Append("                ").Append(n.Address).Append("\n");
                    }
                    Console.Write("{0}", nodes.ToString());

                    if (partId != null && partId != string.Empty)
                    {
                        if (cs.SubgroupNodes != null && cs.SubgroupNodes.Contains(partId.ToLower()))
                        {
                            nodes = new System.Text.StringBuilder();
                            ArrayList groupNodes = cs.SubgroupNodes[partId.ToLower()] as ArrayList;
                            Console.WriteLine("Partition size: {0}", groupNodes.Count);
                           
                            foreach (Address address in groupNodes)
                            {
                                nodes.Append("                ").Append(address).Append("\n");
                            }
                        }
                        Console.Write("{0}", nodes.ToString());
                    }
				}
				Console.WriteLine("UpTime:         {0}", s.UpTime);

                if(s.MaxSize != 0)
                Console.WriteLine("Capacity:       {0} MB", ((  s.MaxSize / 1024) / 1024));
                else
                Console.WriteLine("Capacity:       {0} MB", MaxSize);

                Console.WriteLine("Count:          {0}", s.Count);
			}
			if(printConf)
			{
				try
				{
					if(xmlSyntax)
					{
						PropsConfigReader pr = new PropsConfigReader(cache.ConfigString);
						Console.WriteLine("Configuration:\n{0}", ConfigReader.ToPropertiesXml(pr.Properties, true));
					}
					else
					{
						Console.WriteLine("Configuration:\n{0}", cache.ConfigString);
					}
				}
				catch(ConfigurationException){}
			}
			Console.WriteLine("");
		}
Пример #35
0
        internal NCache(string cacheId, bool isDotNetClient, ClientManager client, string licenceInfo, string userId, string password, byte[] userIdBinary, byte[] paswordBinary, Runtime.Caching.ClientInfo clientInfo)
        {
            this._cacheId        = cacheId;
            this._isDotNetClient = isDotNetClient;
            this._client         = client;
            this._licenceCode    = licenceInfo;


            _cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cacheId);

            if (_cache == null)
            {
                throw new Exception("Cache is not registered");
            }

            if (!_cache.IsRunning)
            {
                throw new Exception("Cache is not running");
            }

            EventHelper.EventDataFormat = _cache.SocketServerDataService;
#if !CLIENT
            if (_cache.CacheType.Equals("mirror-server") && !_cache.IsCoordinator)
            {
                throw new OperationNotSupportedException("Cannot connect to Passive Node in Mirror Cluster.");
            }
#endif

            _onItemUpdatedCallback            = new CustomUpdateCallback(CustomUpdate);
            _cache.CustomUpdateCallbackNotif += _onItemUpdatedCallback;

            _onItemRemoveCallback             = new CustomRemoveCallback(CustomRemove);
            _cache.CustomRemoveCallbackNotif += _onItemRemoveCallback;

            _pollRequestCallback             = new Caching.PollRequestCallback(PollRequest);
            _cache.PollRequestCallbackNotif += _pollRequestCallback;


            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver + ".ctor", "Registering cache stopped event for " + _client.ClientID);
            }

            _cacheStopped        = new CacheStoppedCallback(OnCacheStopped);
            _cache.CacheStopped += _cacheStopped;

            if (SocketServer.Logger.IsErrorLogsEnabled)
            {
                SocketServer.Logger.NCacheLog.Error(_cacheserver + ".ctor", "Cache stopped event registered for " + _client.ClientID);
            }



            _asyncOperationCallback         = new AsyncOperationCompletedCallback(AsyncOperationCompleted);
            _cache.AsyncOperationCompleted += _asyncOperationCallback;


            _cacheBecomeActive        = new CacheBecomeActiveCallback(OnCacheBecomeActive);
            _cache.CacheBecomeActive += _cacheBecomeActive;

            _configModified = new ConfigurationModified(OnConfigModified);
            _cache.ConfigurationModified += _configModified;

            _onCompactTypeModifiedCallback = new CompactTypeModifiedCallback(CompactTypesModified);
            _cache.CompactTypeModified    += _onCompactTypeModifiedCallback;

            _blockClientActivity  = new BlockClientActivity(BlockClientActivity);
            _cache.BlockActivity += this._blockClientActivity;

            _unblockClientActivity  = new UnBlockClientActivity(UnBlockClientActivity);
            _cache.UnBlockActivity += this._unblockClientActivity;

            _operationModeChanged       += new OperationModeChangedCallback(OperationModeChanged);
            _cache.OperationModeChanged += _operationModeChanged;
        }
Пример #36
0
        private static Cache InitializeCacheInternal(string cacheId, CacheInitParams initParams,
                                                     bool isRemoveCache = true)
        {
            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)
                        {
                            if (config.CacheType.ToLower().Equals("clustered-cache"))
                            {
                                throw new Exception("Cluster cache cannot be initialized in In-Proc mode.");
                            }

                            switch (mode)
                            {
                            case CacheMode.InProc:
                                config.InProc = true;
                                break;

                            case CacheMode.OutProc:
                                config.InProc = false;
                                break;
                            }
                        }

                        break;
                    } 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
                                {
                                    CacheConfig cacheConfig = CacheConfig.FromDom(config);

                                    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;
                                    }

                                    else
                                    {
                                        primaryCache.AddSecondaryInprocInstance(cache);
                                    }

                                    break;
                                } while (maxTries > 0);
                            }
                            else
                            {
                                maxTries = 2;
                                do
                                {
                                    try
                                    {
                                        PerfStatsCollector2 perfStatsCollector =
                                            new PerfStatsCollector2(cacheId, false);

                                        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)
                            {
                                s_webCaches.AddCache(cacheId, primaryCache);
                            }
                        }
                        else
                        {
                            lock (s_webCaches.GetCache(cacheId))
                            {
                                primaryCache = s_webCaches.GetCache(cacheId) as Cache;

                                primaryCache.AddRef();
                            }
                        }
                    }

                    lock (s_webCache)
                    {
                        if (s_webCache.CacheImpl == null)
                        {
                            primaryCache.ExceptionsEnabled = ExceptionsEnabled;
                            s_webCache = primaryCache;
                        }
                    }

                    return(primaryCache);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #37
0
        static private void PrintCacheInfo(Cache cache, string partId)
        {

            CacheStatistics s = cache.Statistics;
            string schemeName = s.ClassName.ToLower(CultureInfo.CurrentCulture);
            string running = cache.IsRunning ? "Running" : "Stopped";

            Console.WriteLine("{0,-20} {1,-15} {2,-30} {3,-5}", cache.Name, partId, schemeName, running);
        }