示例#1
0
 internal SocketPool(ServerPool owner, string host)
 {
     Host = host;
     this.owner = owner;
     endPoint = getEndPoint(host);
     queue = new Queue<PooledSocket>();
 }
示例#2
0
        public void TestNoRandomization()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Servers     = startUrls;
            opts.NoRandomize = true;

            for (int i = 0; i < 10; i++)
            {
                var sp = new ServerPool();
                sp.Setup(opts);

                var poolUrls = sp.GetServerList(false);
                Assert.True(poolUrls.Length == startUrls.Length);
                Assert.True(poolUrls.SequenceEqual(startUrls));
            }

            for (int i = 0; i < 10; i++)
            {
                var sp = new ServerPool();
                sp.Setup(opts);

                var poolUrls = sp.GetServerList(false);
                Assert.True(poolUrls.Length == startUrls.Length);
                Assert.True(poolUrls.SequenceEqual(startUrls));

                string[] impUrls =
                {
                    "nats://impA:4222", "nats://impB:4222", "nats://impC:4222", "nats://impD:4222",
                    "nats://impE:4222", "nats://impF:4222", "nats://impG:4222", "nats://impH:4222",
                };
                sp.Add(impUrls, true);
                Assert.True(poolUrls.SequenceEqual(startUrls));
            }
        }
示例#3
0
 public Task <string> LoginToServerAsync(ServerPool serverPool)
 {
     return(serverPool.ConnectionType switch
     {
         "SSH" => Task.FromResult(SshConnection(serverPool.Hostname, serverPool.Port, serverPool.UserName, serverPool.Password)),
         "WinRM" => Task.FromResult(WinRMConnection(serverPool.Hostname, serverPool.UserName, serverPool.Password)),
         _ => Task.FromResult("Connection Unsuccessfull"),
     });
示例#4
0
        protected override void OnInitialized(ModelElementBase modelElement)
        {
            ServerPool serverPool = (ServerPool)modelElement;

            nrOfJobs.UpdateValue(serverPool.JobCount);

            Writer.WriteLine($"Current Simulation Time,Average number of jobs, StDev on average number of jobs");
        }
示例#5
0
 public StartupService(ILogger <StartupService> logger, ServerPool serverPool, ItemDatabase idb, EventManager eventManager,
                       WorldManager worldManager)
 {
     _logger       = logger;
     _serverPool   = serverPool;
     _idb          = idb;
     _eventManager = eventManager;
     _worldManager = worldManager;
 }
        internal StoreOperation(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt)
            : base(pool, key)
        {
            this.mode = mode;
            this.value = value;
            this.casValue = casValue;

            expires = GetExpiration(validFor, expiresAt);
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration.
        /// </summary>
        /// <param name="configuration">The client configuration.</param>
        public MemcachedClient(IMemcachedClientConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            this.pool = new ServerPool(configuration);
        }
示例#8
0
        internal StoreOperation(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt)
            : base(pool, key)
        {
            this.mode     = mode;
            this.value    = value;
            this.casValue = casValue;

            expires = GetExpiration(validFor, expiresAt);
        }
示例#9
0
        protected override void OnUpdate(ModelElementBase modelElement)
        {
            ServerPool serverPool = (ServerPool)modelElement;

            nrOfJobs.UpdateValue(serverPool.JobCount);
            nrOfJobsStatistic.Collect(nrOfJobs.Value, nrOfJobs.Weight);

            Writer.WriteLine($"{serverPool.GetTime}',{nrOfJobsStatistic.Average()},{nrOfJobsStatistic.StandardDeviation()}");
        }
示例#10
0
        /// <summary>
        /// Initializes a new MemcacedClient instance using the specified configuration section.
        /// This overload allows to create multiple MemcachedClients with different pool configurations.
        /// </summary>
        /// <param name="sectionName">The name of the configuration section to be used for configuring the behavior of the client.</param>
        public MemcachedClient(string sectionName)
        {
            MemcachedClientSection section = (MemcachedClientSection)ConfigurationManager.GetSection(sectionName);

            if (section == null)
            {
                throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
            }

            this.pool = new ServerPool(section);
        }
示例#11
0
        public void TestDefault()
        {
            var sp = new ServerPool();

            sp.Setup(new Options());

            var poolUrls = sp.GetServerList(false);

            Assert.True(poolUrls.Length == 1);
            Assert.Equal(poolUrls[0], Defaults.Url);
        }
示例#12
0
        //Private constructor
        private MemcachedClient(string name, string[] hosts)
        {
            if (String.IsNullOrEmpty(name)) {
                throw new ConfigurationErrorsException("Name of MemcachedClient instance cannot be empty.");
            }
            if (hosts == null || hosts.Length == 0) {
                throw new ConfigurationErrorsException("Cannot configure MemcachedClient with empty list of hosts.");
            }

            Name = name;
            serverPool = new ServerPool(hosts);
        }
示例#13
0
        /// <summary>
        /// Releases all resources allocated by this instance
        /// </summary>
        /// <remarks>Technically it's not really neccesary to call this, since the client does not create "really" disposable objects, so it's safe to assume that when the AppPool shuts down all resources will be released correctly and no handles or such will remain in the memory.</remarks>
        public void Dispose()
        {
            if (this.pool == null)
            {
                throw new ObjectDisposedException("MemcachedClient");
            }

            lock (this)
            {
                ((IDisposable)this.pool).Dispose();
                this.pool = null;
            }
        }
示例#14
0
        private static bool Store(ServerPool pool, StoreCommand mode, string key, byte[] value, ulong casValue, int offset, int length, TimeSpan validFor, DateTime expiresAt)
        {
            if (value == null)
            {
                return(false);
            }

            using (StoreOperation s = new StoreOperation(pool, mode, key, new ArraySegment <byte>(value, offset, length), casValue, validFor, expiresAt))
            {
                s.Execute();

                return(s.Success);
            }
        }
示例#15
0
        private static bool Store(ServerPool pool, StoreCommand mode, string key, object value, ulong casValue, TimeSpan validFor, DateTime expiresAt)
        {
            if (value == null)
            {
                return(false);
            }

            using (StoreOperation s = new StoreOperation(pool, mode, key, value, casValue, validFor, expiresAt))
            {
                s.Execute();

                return(s.Success);
            }
        }
示例#16
0
        public void TestBasicRandomization()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Servers = startUrls;

            for (int i = 0; i < 10; i++)
            {
                var sp = new ServerPool();
                sp.Setup(opts);

                var poolUrls = sp.GetServerList(false);
                Assert.True(poolUrls.Length == startUrls.Length);
                Assert.False(poolUrls.SequenceEqual(startUrls));
            }
        }
示例#17
0
        public void TestIdempotency()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Servers = startUrls;

            var sp = new ServerPool();

            sp.Setup(opts);

            var poolUrls = sp.GetServerList(false);

            Assert.True(poolUrls.Length == startUrls.Length);

            sp.Add(startUrls, true);
            Assert.True(poolUrls.Length == startUrls.Length);
        }
示例#18
0
        public void TestImplicitRandomization()
        {
            var opts = ConnectionFactory.GetDefaultOptions();

            opts.Url     = null;
            opts.Servers = startUrls;

            var sp = new ServerPool();

            sp.Setup(opts);

            string[] impUrls =
            {
                "nats://impA:4222", "nats://impB:4222", "nats://impC:4222", "nats://impD:4222",
                "nats://impE:4222", "nats://impF:4222", "nats://impG:4222", "nats://impH:4222",
            };
            sp.Add(impUrls, true);

            var poolUrls = sp.GetServerList(false);

            // Ensure length is OK and that we have randomized the list
            Assert.True(poolUrls.Length == startUrls.Length + impUrls.Length);
            Assert.False(poolUrls.SequenceEqual(startUrls));

            // Ensure implicit urls aren't placed at the end of the list.
            int i;

            for (i = 0; i < startUrls.Length; i++)
            {
                if (poolUrls[i].Contains("imp"))
                {
                    break;
                }
            }
            Assert.True(i != startUrls.Length);
        }
 public FlushOperation(ServerPool pool) : base(pool)
 {
 }
 internal DeleteOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
 protected ItemOperation(ServerPool pool, string key)
     : base(pool)
 {
     this.key = key;
 }
示例#22
0
 /// <summary>
 /// Initializes a new MemcachedClient instance using the default configuration section (enyim/memcached).
 /// </summary>
 public MemcachedClient()
 {
     this.pool = new ServerPool();
 }
示例#23
0
 protected Operation(ServerPool serverPool)
 {
     this.serverPool = serverPool;
 }
 internal IncrementOperation(ServerPool pool, string key, uint amount)
     : base(pool, key)
 {
     this.amount = amount;
 }
示例#25
0
 internal GetOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
 internal IncrementOperation(ServerPool pool, string key, uint amount)
     : base(pool, key)
 {
     this.amount = amount;
 }
示例#27
0
 public StatsOperation(ServerPool pool) : base(pool)
 {
 }
示例#28
0
		//Private constructor
		private MemcachedClient(string name, string[] hosts) {
			if (String.IsNullOrEmpty(name)) {
				throw new ConfigurationErrorsException("Name of MemcachedClient instance cannot be empty.");
			}
            Name = name;
            serverPool = new ServerPool(hosts);
            string cacheName = "";
            try
            {
                cacheName = ConfigurationManager.AppSettings["NCache.CacheName"];
                if (String.IsNullOrEmpty(cacheName))
                {
                    Exception ex = new Exception("Unable to read NCache Name from configuration");
                    throw ex;
                }
            }
            catch (Exception e)
            { throw e; }

            try
            {
                memcachedProvider = CacheFactory.CreateCacheProvider(cacheName);
            }
            catch (Exception e)
            { }
            
		}
 internal DeleteOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
 public FlushOperation(ServerPool pool)
     : base(pool)
 {
 }
示例#31
0
 public void Post([FromBody] string value, [FromServices] ServerPool servers)
 {
     servers.Add("http://localhost:" + value);
 }
示例#32
0
 public MultiGetOperation(ServerPool pool, IEnumerable <string> keys)
     : base(pool)
 {
     this.keys = keys;
 }
 internal GetOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
 public StatsOperation(ServerPool pool)
     : base(pool)
 {
 }
 protected ItemOperation(ServerPool pool, string key)
     : base(pool)
 {
     this.key = key;
 }
示例#36
0
 protected Operation(ServerPool serverPool)
 {
     this.serverPool = serverPool;
 }
 public MultiGetOperation(ServerPool pool, IEnumerable<string> keys)
     : base(pool)
 {
     this.keys = keys;
 }
示例#38
0
        protected override bool ExecuteAction()
        {
            // {hashed key -> normal key}: will be used when mapping the returned items back to the original keys
            Dictionary <string, string> hashedToReal = new Dictionary <string, string>(StringComparer.Ordinal);

            // {normal key -> hashed key}: we have to hash all keys anyway, so we better cache them to improve performance instead of doing the hashing later again
            Dictionary <string, string> realToHashed = new Dictionary <string, string>(StringComparer.Ordinal);

            IMemcachedKeyTransformer transformer = ServerPool.KeyTransformer;

            // and store them with the originals so we can map the returned items
            // to the original keys
            foreach (string s in keys)
            {
                string hashed = transformer.Transform(s);

                hashedToReal[hashed] = s;
                realToHashed[s]      = hashed;
            }

            // map each key to the appropriate server in the pool
            IDictionary <MemcachedNode, IList <string> > splitKeys = ServerPool.SplitKeys(keys);

            // we'll open 1 socket for each server
            List <PooledSocket> sockets = new List <PooledSocket>();

            try
            {
                // send a 'gets' to each server
                foreach (KeyValuePair <MemcachedNode, IList <string> > kp in splitKeys)
                {
                    // gets <keys>
                    //
                    // keys: key key key key
                    string[] command = new string[kp.Value.Count + 1];
                    command[0] = "gets";
                    kp.Value.CopyTo(command, 1);

                    for (int i = 1; i < command.Length; i++)
                    {
                        command[i] = realToHashed[command[i]];
                    }

                    PooledSocket socket = kp.Key.Acquire();
                    if (socket == null)
                    {
                        continue;
                    }

                    sockets.Add(socket);
                    socket.SendCommand(String.Join(" ", command));
                }

                Dictionary <string, object> retval = new Dictionary <string, object>(StringComparer.Ordinal);
                Dictionary <string, ulong>  cas    = new Dictionary <string, ulong>(StringComparer.Ordinal);

                // process each response and build a dictionary from the results
                foreach (PooledSocket socket in sockets)
                {
                    try
                    {
                        GetResponse r;

                        while ((r = GetHelper.ReadItem(socket)) != null)
                        {
                            string originalKey = hashedToReal[r.Key];

                            retval[originalKey] = ServerPool.Transcoder.Deserialize(r.Item);
                            cas[originalKey]    = r.CasValue;
                        }
                    }
                    catch (NotSupportedException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        log.Error(e);
                    }
                }

                result    = retval;
                casValues = cas;
            }
            finally
            {
                foreach (PooledSocket socket in sockets)
                {
                    ((IDisposable)socket).Dispose();
                }
            }

            return(true);
        }