Subversion Repositories DevTools

Rev

Rev 916 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 916 Rev 918
Line 91... Line 91...
91
  private static Connection mConnection = null;
91
  private static Connection mConnection = null;
92
 
92
 
93
  /**database session handle
93
  /**database session handle
94
   * @attribute
94
   * @attribute
95
   */
95
   */
-
 
96
  private static Connection mPlanningConnection = null;
-
 
97
  
-
 
98
  /**thread synchronisation governing non planning database connection usage
-
 
99
   * this lock is used by all build threads
-
 
100
   * @attribute
-
 
101
   */
96
  private static final ReentrantLock mSession = new ReentrantLock();
102
  private static final ReentrantLock mSession = new ReentrantLock();
97
 
103
 
-
 
104
  /**thread synchronisation governing database connection usage
-
 
105
   * this lock is used by master threads with a high priority planning requirement
-
 
106
   * and at most one thread with a low priority planning requirement
-
 
107
   * @attribute
-
 
108
   */
-
 
109
  private static final ReentrantLock mPlanningSession = new ReentrantLock();
-
 
110
 
-
 
111
  /**thread synchronisation governing database connection request queueing
-
 
112
   * this lock is used by master threads with a low priority planning requirement
-
 
113
   * use the fairness parameter to grant access to the longest waiting thread
-
 
114
   * @attribute
-
 
115
   */
-
 
116
  private static final ReentrantLock mLowPriorityQueue = new ReentrantLock(true);
-
 
117
 
98
  /**index to current ReleaseConfig item
118
  /**index to current ReleaseConfig item
99
   * @attribute
119
   * @attribute
100
   */
120
   */
101
  private int mReleaseConfigIndex = -1;
121
  private int mReleaseConfigIndex = -1;
102
 
122
 
Line 4366... Line 4386...
4366
   */
4386
   */
4367
  public void connect() throws SQLException, Exception
4387
  public void connect() throws SQLException, Exception
4368
  {
4388
  {
4369
    mLogger.debug("connect");
4389
    mLogger.debug("connect");
4370
    
4390
    
-
 
4391
    connect( mSession, mConnection );    
-
 
4392
  }
-
 
4393
 
-
 
4394
  /**connect to oracle
-
 
4395
   */
-
 
4396
  public void connectForPlanning( boolean priority ) throws SQLException, Exception
-
 
4397
  {
-
 
4398
    mLogger.debug("connectForPlanning");
-
 
4399
    
-
 
4400
    if ( !priority )
-
 
4401
    {
-
 
4402
      // limit only one thread with a low priority build requirement to connect
-
 
4403
      if ( mLowPriorityQueue.isHeldByCurrentThread() )
-
 
4404
      {
-
 
4405
        // by design a thread must NOT connect multiple times
-
 
4406
        // this is to ensure the lock is claimed only once
-
 
4407
        mLogger.error("connectForPlanning thread already has the lock");
-
 
4408
      }
-
 
4409
      else
-
 
4410
      {
-
 
4411
        mLogger.warn("connectForPlanning calling lock");
-
 
4412
        mLowPriorityQueue.lock();
-
 
4413
        mLogger.warn("connectForPlanning called lock");
-
 
4414
      }
-
 
4415
    }
-
 
4416
    
-
 
4417
    // threads with a high priority build requirement are not subject to the mLowPriorityQueue
-
 
4418
    connect( mPlanningSession, mPlanningConnection );    
-
 
4419
  }
-
 
4420
 
-
 
4421
  /**connect to oracle
-
 
4422
   */
-
 
4423
  private void connect( ReentrantLock session, Connection connection ) throws SQLException, Exception
-
 
4424
  {
-
 
4425
    mLogger.debug("connect");
-
 
4426
    
4371
    if ( mSession.isHeldByCurrentThread() )
4427
    if ( session.isHeldByCurrentThread() )
4372
    {
4428
    {
4373
      // by design a thread must NOT connect multiple times
4429
      // by design a thread must NOT connect multiple times
4374
      // this is to ensure the lock is claimed only once
4430
      // this is to ensure the lock is claimed only once
4375
      mLogger.error("connect thread already has the lock");
4431
      mLogger.error("connect thread already has the lock");
4376
    }
4432
    }
4377
    else
4433
    else
4378
    {
4434
    {
4379
      mLogger.warn("connect calling lock");
4435
      mLogger.warn("connect calling lock");
4380
      mSession.lock();
4436
      session.lock();
4381
      mLogger.warn("connect called lock");
4437
      mLogger.warn("connect called lock");
4382
    }
4438
    }
4383
    
4439
    
4384
    if ( !mUseDatabase )
4440
    if ( !mUseDatabase )
4385
    {
4441
    {
Line 4397... Line 4453...
4397
        mLogger.warn("connect check connection");
4453
        mLogger.warn("connect check connection");
4398
        problemConnecting = false;
4454
        problemConnecting = false;
4399
        
4455
        
4400
        try
4456
        try
4401
        {
4457
        {
4402
          if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4458
          if ( connection == null || ( connection != null && !connection.isValid(10) ) )
4403
          {
4459
          {
4404
            mLogger.warn("connect calling getConnection");
4460
            mLogger.warn("connect calling getConnection");
4405
            mConnection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
4461
            connection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
4406
            // when connection to the database is established, the connection, by default, is in auto-commit mode
4462
            // when connection to the database is established, the connection, by default, is in auto-commit mode
4407
            // to adhere to the design in the use of select for update, it is crucial to turn auto-commit off
4463
            // to adhere to the design in the use of select for update, it is crucial to turn auto-commit off
4408
            // this also improves performance
4464
            // this also improves performance
4409
            mConnection.setAutoCommit(false);
4465
            connection.setAutoCommit(false);
4410
          }
4466
          }
4411
        }
4467
        }
4412
        catch(SQLException e)
4468
        catch(SQLException e)
4413
        {
4469
        {
4414
          mLogger.warn("connect determined problem connecting");
4470
          mLogger.warn("connect determined problem connecting");
Line 4421... Line 4477...
4421
          }
4477
          }
4422
          catch (InterruptedException f)
4478
          catch (InterruptedException f)
4423
          {
4479
          {
4424
            mLogger.warn("connect caught InterruptedException");
4480
            mLogger.warn("connect caught InterruptedException");
4425
          }
4481
          }
4426
          
-
 
4427
 
4482
 
4428
          if ( mConnection == null )
4483
          if ( connection == null )
4429
          {
4484
          {
4430
            // failed on first connection attempt - unlikely due to database loading - likely bad connection parameters
4485
            // failed on first connection attempt - unlikely due to database loading - likely bad connection parameters
4431
            throw new SQLException();
4486
            throw new SQLException();
4432
          }
4487
          }
4433
        }
4488
        }
Line 4439... Line 4494...
4439
  /**disconnect from oracle
4494
  /**disconnect from oracle
4440
   */
4495
   */
4441
  public void disconnect() throws Exception
4496
  public void disconnect() throws Exception
4442
  {
4497
  {
4443
    mLogger.debug("disconnect");
4498
    mLogger.debug("disconnect");
4444
/* DEVI 46868 
4499
    
-
 
4500
    disconnect( mSession );
-
 
4501
  }
-
 
4502
 
-
 
4503
  /**disconnect from oracle
-
 
4504
   */
4445
 * never disconnect, thus the only time a connection attempt is made
4505
  public void disconnectForPlanning( boolean priority ) throws Exception
-
 
4506
  {
4446
 * is when the server has (timed out) disconnected the session
4507
    mLogger.debug("disconnectForPlanning");
-
 
4508
    
4447
 *  if ( mUseDatabase )
4509
    if ( !priority )
4448
    {
4510
    {
-
 
4511
      // allow another low priority thread to connect
-
 
4512
      mLowPriorityQueue.unlock();
4449
      try
4513
    }
4450
      {
4514
    
4451
        mConnection.close();
4515
    disconnect( mPlanningSession );
4452
      }
4516
  }
-
 
4517
 
4453
      catch(SQLException e)
4518
  /**disconnect from oracle
4454
      {
4519
   */
4455
        mLogger.error("disconnect caught Exception");
4520
  private void disconnect( ReentrantLock session ) throws Exception
4456
        throw new Exception();
-
 
4457
      }
4521
  {
4458
    }*/
4522
    mLogger.debug("disconnect");
4459
    
4523
    
4460
    // by design, a thread may call disconnect multiple times
4524
    // by design, a thread may call disconnect multiple times
4461
    // this is a technique used in finally blocks
4525
    // this is a technique used in finally blocks
4462
    // it is to ensure the lock is released in all cases
4526
    // it is to ensure the lock is released in all cases
4463
    // only unlock if it is held by this thread
4527
    // only unlock if it is held by this thread
Line 4465... Line 4529...
4465
    // the hold count is decremented
4529
    // the hold count is decremented
4466
    // connect should only let the hold count be incremented to 1
4530
    // connect should only let the hold count be incremented to 1
4467
    // when the hold count is 0 the lock is released
4531
    // when the hold count is 0 the lock is released
4468
    // and the ReentrantLock is no longer held by this thread
4532
    // and the ReentrantLock is no longer held by this thread
4469
    // only call unlock when the lock is held by this thread
4533
    // only call unlock when the lock is held by this thread
4470
    if ( mSession.isHeldByCurrentThread() )
4534
    if ( session.isHeldByCurrentThread() )
4471
    {
4535
    {
4472
      mLogger.warn("disconnected calling unlock");
4536
      mLogger.warn("disconnected calling unlock");
4473
      mSession.unlock();
4537
      session.unlock();
4474
      mLogger.warn("disconnected called unlock");
4538
      mLogger.warn("disconnected called unlock");
4475
    }
4539
    }
4476
  }
4540
  }
4477
 
4541
 
4478
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id of the first element
4542
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id of the first element