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; }
/// <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; } }
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)); } }
/// <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); }
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"); } }
//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)); } }
public override void ClearCacheContent(string cacheId) { if (cacheInfo != null) { InstrumentCache cache = cacheInfo.Cache; if (cache != null) { cache.Clear(); } } }
public override void ApplyHotConfiguration(string cacheId, HotConfig hotConfig) { if (cacheInfo != null) { InstrumentCache cache = cacheInfo.Cache; if (cache != null) { cache.ApplyHotConfiguration(hotConfig); } } }
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; }
public override CacheStatistics GetStatistics(string cacheId) { if (cacheInfo != null) { InstrumentCache cache = cacheInfo.Cache; if (cache != null && cache.IsRunning) { return(cache.Statistics); } } return(null); }
public override bool IsUnderStateTransfer(string cacheId) { if (cacheInfo != null) { InstrumentCache cache = cacheInfo.Cache; if (cache != null && cache.IsRunning) { return(cache.IsClusterInStateTransfer()); } } return(false); }
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); }
public override void BalanceDataloadOnCache(string cacheId) { if (cacheInfo != null) { InstrumentCache cache = cacheInfo.Cache; if (cache != null) { cache.BalanceDataLoad(); } } }
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); }
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); }
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); }
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); }
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); }
public override ClientProfileDom GetClientProfileReport(string cacheId) { ClientProfileDom clientProfile = null; if (cacheInfo != null) { InstrumentCache cache = cacheInfo.Cache; if (cache != null) { clientProfile = cache.GetClientProfileReport(); } } return(clientProfile); }
//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); } }
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); }
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"); } }
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"); } }
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; } }
/// <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; }
public EntryProcessorManager(String cacheName, CacheRuntimeContext context, Alachisoft.NCache.Caching.Cache cacheRoot) { _cacheName = cacheName; _context = context; _cacheRoot = cacheRoot; }
/// <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; }
/// <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(); }
/// <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; }
/// <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; }
/// <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); } }
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(""); }
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; }
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; } }
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); }