Ejemplo n.º 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();
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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();
 }