Exemple #1
0
        static void Main(string[] args)
        {
            TrimApplication.Initialize();

            Stopwatch watch = new Stopwatch();

            watch.Start();

            DatabasePoolEntry poolEntry = DatabasePool.Instance.AcquirePoolEntry("J1", "itu_tadmin");

            Console.WriteLine(poolEntry.TrimDatabase.CurrentUser.SortName);

            DatabasePool.Instance.ReleasePoolEntry(poolEntry.Id);

            watch.Stop();

            Console.WriteLine(watch.ElapsedMilliseconds);


            watch.Restart();

            poolEntry = DatabasePool.Instance.AcquirePoolEntry("J1", "itu_tadmin");


            Console.WriteLine(poolEntry.TrimDatabase.CurrentUser.SortName);

            DatabasePool.Instance.ReleasePoolEntry(poolEntry.Id);

            watch.Stop();

            Console.WriteLine(watch.ElapsedMilliseconds);

            DatabasePool.Instance.Dispose();
        }
Exemple #2
0
        public DatabasePoolEntry AcquirePoolEntry(string dbid, string identity, bool isSingleHop = false, string remoteIp = null)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("DatabasePool");
            }

            lock (_poolLock)
            {
                DatabasePoolEntry pooled = GetPoolEntry(identity, dbid);

                if (pooled != null)
                {
                    pooled.LastAccessed = DateTime.Now;

                    return(pooled);
                }
            }

            TrimPool();

            DatabasePoolEntry mine = new DatabasePoolEntry(identity, WG_NAME, WG_PORT, dbid, ALT_WG_NAME, ALT_WG_PORT, isSingleHop, remoteIp);

            lock (_poolLock)
            {
                _pool.Add(mine);
            }

            return(mine);
        }
Exemple #3
0
        private DatabasePoolEntry GetPoolEntry(string identity, string dbid)
        {
            lock (_poolLock)
            {
                DatabasePoolEntry poolEntry = _pool.Where(
                    p => p.isAvailable(identity, dbid)).FirstOrDefault();

                if (poolEntry != null)
                {
                    poolEntry.IsLocked = true;
                }

                return(poolEntry);
            }
        }
Exemple #4
0
        public void ReleasePoolEntry(Guid id)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("DatabasePool");
            }

            lock (_poolLock)
            {
                DatabasePoolEntry mine = _pool.Where(p =>
                                                     p.Id == id).FirstOrDefault();
                if (mine != null)
                {
                    mine.IsLocked = false;
                }
            }
        }