Пример #1
0
 internal void SetClientAmount(uint amount)
 {
     lockObject.EnterWriteLock();
     for (int i = 0; i < amount; i++)
     {
         int newID = databaseClients.Count + 1;
         DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this);
         databaseClients.Add(newID, newClient);
         newClient.Connect();
     }
     lockObject.ExitWriteLock();
 }
Пример #2
0
        internal DatabaseClientOld GetClient()
        {
            lockObject.EnterReadLock();
            DatabaseClientOld returnClient = null;

            foreach (DatabaseClientOld client in databaseClients.Values)
            {
                if (client.isWorking)
                {
                    continue;
                }
                if (client.State == ConnectionState.Closed)
                {
                    client.Connect();
                }
                if (client.State == ConnectionState.Open)
                {
                    returnClient = client;
                    returnClient.UpdateLastActivity();
                    break;
                }
            }

            lockObject.ExitReadLock();
            if (returnClient != null)
            {
                return(returnClient);
            }

            if (databaseClients.Count < databaseSettings.maxPoolSize)
            {
                lockObject.EnterWriteLock();
                int newID = databaseClients.Count + 1;
                DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this);
                databaseClients.Add(newID, newClient);
                newClient.Connect();
                newClient.UpdateLastActivity();

                lockObject.ExitWriteLock();
                return(newClient);
            }

            DatabaseClientOld anonymousClient = new DatabaseClientOld(0, connectionString, this);

            anonymousClient.Connect();
            anonymousClient.UpdateLastActivity();
            return(anonymousClient);
        }
Пример #3
0
        internal DatabaseClientOld GetClient()
        {
            lockObject.EnterReadLock();
            DatabaseClientOld returnClient = null;

            foreach (DatabaseClientOld client in databaseClients.Values)
            {
                if (client.isWorking)
                    continue;
                if (client.State == ConnectionState.Closed)
                    client.Connect();
                if (client.State == ConnectionState.Open)
                {
                    returnClient = client;
                    returnClient.UpdateLastActivity();
                    break;
                }
            }

            lockObject.ExitReadLock();
            if (returnClient != null)
                return returnClient;

            if (databaseClients.Count < databaseSettings.maxPoolSize)
            {
                lockObject.EnterWriteLock();
                int newID = databaseClients.Count + 1;
                DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this);
                databaseClients.Add(newID, newClient);
                newClient.Connect();
                newClient.UpdateLastActivity();

                lockObject.ExitWriteLock();
                return newClient;
            }

            DatabaseClientOld anonymousClient = new DatabaseClientOld(0, connectionString, this);
            anonymousClient.Connect();
            anonymousClient.UpdateLastActivity();
            return anonymousClient;
        }
Пример #4
0
 internal void SetClientAmount(uint amount)
 {
     lockObject.EnterWriteLock();
     for (int i = 0; i < amount; i++)
     {
         int newID = databaseClients.Count + 1;
         DatabaseClientOld newClient = new DatabaseClientOld((uint)newID, connectionString, this);
         databaseClients.Add(newID, newClient);
         newClient.Connect();
     }
     lockObject.ExitWriteLock();
 }