コード例 #1
0
ファイル: SocketPool.cs プロジェクト: ZhouHengYi/HFramework
 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
ファイル: ServerAuth.cs プロジェクト: Stripped/DeployT
 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
ファイル: ServerPoolObserver.cs プロジェクト: nitman118/CSSL
        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;
 }
コード例 #6
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);
        }
コード例 #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
ファイル: ServerPoolObserver.cs プロジェクト: nitman118/CSSL
        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
ファイル: MemcachedClient.cs プロジェクト: noear/Weed3
        //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);
        }
コード例 #19
0
 public FlushOperation(ServerPool pool) : base(pool)
 {
 }
コード例 #20
0
 internal DeleteOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
コード例 #21
0
 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;
 }
コード例 #24
0
 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)
 {
 }
コード例 #26
0
 internal IncrementOperation(ServerPool pool, string key, uint amount)
     : base(pool, key)
 {
     this.amount = amount;
 }
コード例 #27
0
 public StatsOperation(ServerPool pool) : base(pool)
 {
 }
コード例 #28
0
ファイル: MemcachedClient.cs プロジェクト: javithalion/NCache
		//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)
            { }
            
		}
コード例 #29
0
 internal DeleteOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
コード例 #30
0
 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;
 }
コード例 #33
0
 internal GetOperation(ServerPool pool, string key)
     : base(pool, key)
 {
 }
コード例 #34
0
 public StatsOperation(ServerPool pool)
     : base(pool)
 {
 }
コード例 #35
0
 protected ItemOperation(ServerPool pool, string key)
     : base(pool)
 {
     this.key = key;
 }
コード例 #36
0
 protected Operation(ServerPool serverPool)
 {
     this.serverPool = serverPool;
 }
コード例 #37
0
 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);
        }