/// <summary> /// Initializes the instance of <see cref="Alachisoft.NCache.Web.Caching.Cache"/> for this application. Allows you /// to control the startup type of the <see cref="Alachisoft.NCache.Web.Caching.Cache"/>. /// </summary> /// <param name="cacheId">The identifier for the <see cref="Alachisoft.NCache.Web.Caching.Cache"/> /// item to initialize.</param> /// <param name="mode">Cache startup mode.</param> /// <remarks> /// The <paramref name="cacheId"/> parameter represents the registration/config id of the cache. /// The startup type of the cache is controlled by the <paramref name="mode"/> parameter. /// <para> /// Calling this method twice with the same <paramref name="cacheId"/> increments the reference count /// of the cache. The number of <see cref="InitializeCache"/> calls must be balanced by a corresponding /// same number of <see cref="Alachisoft.NCache.Web.Caching.Cache.Dispose"/> calls. /// </para> /// <para> /// Multiple cache instances can be inititalized within the same application domain. If multiple cache /// instances are initialized, <see cref="NCache.Cache"/> refers to the first instance of the cache. /// </para> /// <para> /// <b>Note:</b> If the value of <paramref name=""/> is <see cref="CacheMode.OutProc"/>, this method /// attempts to start NCache service on the local machine if it is not already running. However it does not /// start the cache automatically. /// </para> /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="cacheId"/> is a null reference (Nothing in Visual Basic).</exception> /// <example> This sample shows how to use the <see cref="InitializeCache"/> method inside a sample Web application. /// <code> /// /// public override void Init() /// { /// // A cache with id 'myCache' is already registered. /// try /// { /// Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("myCache", CacheMode.InProc); /// } /// catch(Exception e) /// { /// // Cache is not available. /// } /// } /// /// </code> /// </example> private static Cache InitializeCache(string cacheId, CacheMode mode) { CacheInitParams initParams = new CacheInitParams(); initParams.Mode = mode; return(InitializeCache(cacheId, initParams)); }
/// <summary> /// Creates Clone for deep copy of the initParam /// </summary> /// <returns></returns> public object Clone() { CacheInitParams _cloneParam = new CacheInitParams(); lock (this) { _cloneParam._dirtyFlags = (Hashtable)this._dirtyFlags.Clone(); // creating shallow copy of hashtable _cloneParam.ClientRequestTimeOut = this.ClientRequestTimeOut; _cloneParam.ConnectionRetries = this.ConnectionRetries; _cloneParam.ConnectionTimeout = this.ConnectionTimeout; _cloneParam.DefaultReadThruProvider = this.DefaultReadThruProvider; _cloneParam.DefaultWriteThruProvider = this.DefaultWriteThruProvider; _cloneParam.LoadBalance = this.LoadBalance; _cloneParam.Mode = this.Mode; _cloneParam.Port = this.Port; _cloneParam.RetryConnectionDelay = this.RetryConnectionDelay; _cloneParam.RetryInterval = this.RetryInterval; _cloneParam.Server = this.Server; _cloneParam.BindIP = this.BindIP; _cloneParam._enabeKeepAlive = this.EnableKeepAlive; _cloneParam._keepAliveInterval = this.KeepAliveInterval; _cloneParam.ServerList = (CacheServerInfo[])this.ServerList.Clone(); // creating shallow copy of serverlist } return(_cloneParam); }
/// <summary> /// Initializes the instance of <see cref="Alachisoft.NCache.Web.Caching.Cache"/> for this application. /// </summary> /// <param name="cacheId">The identifier for the <see cref="Alachisoft.NCache.Web.Caching.Cache"/> /// item to initialize.</param> /// <param name="server">The identifier for the server where the cache is running.</param> /// <param name="port">The port at which the server accepts the remote client connections.</param> /// <remarks> /// The <paramref name="cacheId"/> parameter represents the registration/config id of the cache. /// Depending upon the configuration the <see cref="Alachisoft.NCache.Web.Caching.Cache"/> object is /// created inproc or outproc. /// <para> /// As this overload does not take <see cref="Alachisoft.NCache.Web.Security.SecurityParams"/>, internally /// it tries to load this information from "client.ncconf" file. For more details see NCache Help Collection. /// </para> /// <para> /// Calling this method twice with the same <paramref name="cacheId"/> increments the reference count /// of the cache. The number of <see cref="InitializeCache"/> calls must be balanced by a corresponding /// same number of <see cref="Alachisoft.NCache.Web.Caching.Cache.Dispose"/> calls. /// </para> /// <para> /// Multiple cache instances can be inititalized within the same application domain. If multiple cache /// instances are initialized, <see cref="NCache.Cache"/> refers to the first instance of the cache. /// </para> /// <para> /// <b>Note:</b> When starting a <see cref="Alachisoft.NCache.Web.Caching.Cache"/> as outproc, this method /// attempts to start NCache service on the local machine if it is not already running. However it does not /// start the cache automatically. /// </para> /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="cacheId"/> is a null reference (Nothing in Visual Basic).</exception> /// <example> This sample shows how to use the <see cref="InitializeCache"/> method inside a sample Web application. /// <code> /// /// public override void Init() /// { /// // A cache with id 'myCache' is already registered. /// try /// { /// Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("myCache", "server-name","9900")); /// } /// catch(Exception e) /// { /// // Cache is not available. /// } /// } /// /// </code> /// </example> private static Cache InitializeCache(string cacheId, string server, int port) { CacheInitParams initParams = new CacheInitParams(); initParams.Server = server; initParams.Port = port; bool isPessimistic = false; return(InitializeCache(cacheId, initParams)); }
internal static Cache InitializeCache(string cacheId, CacheInitParams initParams, bool isPessimistic) { if (initParams == null) { initParams = new CacheInitParams(); } initParams.Initialize(cacheId); Cache cache = InitializeCacheInternal(cacheId, initParams); cache.SetMessagingServiceCacheImpl(cache.CacheImpl); return(cache); }
/// <summary> /// Creates Clone for deep copy of the initParam /// </summary> /// <returns></returns> public object Clone() { CacheInitParams _cloneParam = new CacheInitParams(); lock (this) { _cloneParam._dirtyFlags = (Hashtable)this._dirtyFlags.Clone();// creating shallow copy of hashtable _cloneParam.ClientRequestTimeOut = this.ClientRequestTimeOut; _cloneParam.ConnectionRetries = this.ConnectionRetries; _cloneParam.ConnectionTimeout = this.ConnectionTimeout; _cloneParam.LoadBalance = this.LoadBalance; _cloneParam.Mode = this.Mode; _cloneParam._retryConnectionDelay = this._retryConnectionDelay; _cloneParam.RetryInterval = this.RetryInterval; _cloneParam.BindIP = this.BindIP; _cloneParam.ServerList = (CacheServerInfo[])this.ServerList.Clone();// creating shallow copy of serverlist } return(_cloneParam); }
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; } }
/// <summary> /// Initializes the instance of <see cref="Alachisoft.NCache.Web.Caching.Cache"/> for this application. /// </summary> /// <param name="cacheId">The identifier for the <see cref="Alachisoft.NCache.Web.Caching.Cache"/> /// item to initialize.</param> /// <param name="initParams">Holds the initialization parameters for <see cref="Alachisoft.NCache.Web.Caching.Cache"/>. </param> /// <remarks> /// The <paramref name="cacheId"/> parameter represents the registration/config id of the cache. /// <para> /// Calling this method twice with the same <paramref name="cacheId"/> increments the reference count /// of the cache. The number of <see cref="InitializeCache"/> calls must be balanced by a corresponding /// same number of <see cref="Alachisoft.NCache.Web.Caching.Cache.Dispose"/> calls. /// </para> /// <para> /// Multiple cache instances can be inititalized within the same application domain. If multiple cache /// instances are initialized, <see cref="NCache.Cache"/> refers to the first instance of the cache. /// </para> /// <para> /// <b>Note:</b> When starting a <see cref="Alachisoft.NCache.Web.Caching.Cache"/> as outproc, this method /// attempts to start NCache service on the local machine if it is not already running. However it does not /// start the cache automatically. /// </para> /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="cacheId"/> is a null reference (Nothing in Visual Basic).</exception> /// <example> This sample shows how to use the <see cref="InitializeCache"/> method inside a sample Web application. /// <code> /// public override void Init() /// { /// // A cache with id 'myCache' is already registered. /// try /// { /// CacheInitParams initParams = new CacheInitParams(); /// initParams.BalanceNodes = true; /// initParams.ConnectionRetries = 5; /// initParams.Mode = CacheMode.OutProc; /// initParams.MultiPartitionConnection = false; /// initParams.OperationTimeout = 30; /// initParams.Port = 9900; /// initParams.PrimaryUserCredentials = new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id", "password"); /// initParams.RetryInterval = 5; /// initParams.SecondaryUserCredentials = new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id", "password"); /// initParams.Server = "server"; /// Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("myCache", initParams); /// } /// catch(Exception e) /// { /// // Cache is not available. /// } /// } /// /// </code> /// </example> public static Cache InitializeCache(string cacheId, CacheInitParams initParams) { bool isPessimistic = false; return(InitializeCache(cacheId, initParams, isPessimistic)); }
//Moiz: added to set the internal cacheInitparam with the parameters from above internal ClientConfiguration(string cacheId, CacheInitParams param) { _cacheId = cacheId; initParam = (CacheInitParams)param.Clone(); if (initParam != null) { if (initParam.ServerList != null && initParam.ServerList.Length > 0) { foreach (CacheServerInfo serverInfo in initParam.ServerList) { AddServer(serverInfo.ServerInfo); } _loadServersFromConfigFile = false; } else if (initParam.ServerList != null && initParam.ServerList.Length > 0) { AddServer(new RemoteServer(initParam.ServerList[0].Name, initParam.ServerList[0].Port)); } } }
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; } }
/// <summary> /// Creates Clone for deep copy of the initParam /// </summary> /// <returns></returns> public object Clone() { CacheInitParams _cloneParam = new CacheInitParams(); lock (this) { _cloneParam._dirtyFlags = (Hashtable)this._dirtyFlags.Clone();// creating shallow copy of hashtable _cloneParam.ClientRequestTimeOut = this.ClientRequestTimeOut; _cloneParam.ConnectionRetries = this.ConnectionRetries; _cloneParam.ConnectionTimeout = this.ConnectionTimeout; _cloneParam.LoadBalance = this.LoadBalance; _cloneParam.Mode = this.Mode; _cloneParam.RetryConnectionDelay = this.RetryConnectionDelay; _cloneParam.RetryInterval = this.RetryInterval; _cloneParam.BindIP = this.BindIP; _cloneParam.ServerList = (CacheServerInfo[])this.ServerList.Clone();// creating shallow copy of serverlist } return _cloneParam; }
public static Cache InitializeCache(string cacheId, CacheInitParams initParams) { return InitializeCacheInternal(cacheId, initParams); }
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(); }
internal Broker(RemoteCache cache, CacheInitParams initParams, PerfStatsCollector2 statsCol) : this(cache, true, statsCol, initParams) { }
public ClientConfiguration(string cacheId) { _cacheId = cacheId; initParam = null; }
public static Cache InitializeCache(string cacheId, CacheInitParams initParams) { return(InitializeCacheInternal(cacheId, initParams)); }
internal RemoteCache(string cacheId, Cache parent, CacheInitParams initParams, PerfStatsCollector2 perfStatsCol) : base() { _parent = parent; _perfStatsCollector = perfStatsCol; if (_parent != null) { _asyncListener = new CacheAsyncEventsListener(_parent.AsyncListener); _eventListener = new CacheEventsListener(_parent.EventListener); } _cacheId = cacheId; _broker = new Broker(this, initParams, perfStatsCol); // changed this for init param task RemoteServer server = _broker.GetInitialServer(); _broker.StartServices(cacheId, server.IpString, server.Port); if (!_broker.IsConnected) throw new OperationFailedException("No server is available to process the request for " + _cacheId); if (initParams.ServerList != null && initParams.ServerList.Length > 0) _serverId = initParams.ServerList[0].Name; }
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; } }
private static CacheInitParams GetInitParams(ref ToolArgs toolArgs) { CacheInitParams initParams = new CacheInitParams(); string ip = ""; if (string.IsNullOrEmpty(toolArgs.Server)) { return initParams; } else { int port = toolArgs.Port != 0 ? toolArgs.Port : 9800; CacheServerInfo[] cacheServerInfos = new CacheServerInfo[1]; cacheServerInfos[0] = new CacheServerInfo(ip, port); initParams.ServerList = cacheServerInfos; return initParams; } }