Project

General

Profile

« Previous | Next » 

Revision 1122

Added by Jing Tao about 22 years ago

In returnDBConnection method, a new parameter named serialNumber was added. It will compare to the checkOutSerialNumber in DBConnection.

View differences:

src/edu/ucsb/nceas/metacat/DBConnectionPool.java
200 200
            
201 201
            //set this DBConnection status
202 202
            db.setStatus(BUSY);
203
            //increase checkout serial number
204
            db.increaseCheckOutSerialNumber(1);
203 205
            //increase one usageCount
204 206
            db.increaseUsageCount(1);
205 207
            //set method name to DBConnection
206 208
            db.setCheckOutMethodName(methodName);
207 209
            //debug message
208 210
            MetaCatUtil.debugMessage("The connection is checked out: "
209
                                       +db.getTag(), 5);
210
            MetaCatUtil.debugMessage("The age is "+db.getAge(), 5);
211
            MetaCatUtil.debugMessage("The usage is "+db.getUsageCount(), 5);
211
                                       +db.getTag(), 20);
212
            MetaCatUtil.debugMessage("The age is "+db.getAge(), 25);
213
            MetaCatUtil.debugMessage("The usage is "+db.getUsageCount(), 25);
212 214
            MetaCatUtil.debugMessage("The conection time it has: "
213
                                                +db.getConnectionTime(), 5);
215
                                                +db.getConnectionTime(), 25);
214 216
            //set check out time
215 217
            db.setCheckOutTime(System.currentTimeMillis());
216 218
            //check it out
......
296 298
            
297 299
            //set this DBConnection status
298 300
            db.setStatus(BUSY);
301
            //increase checkout serial number
302
            db.increaseCheckOutSerialNumber(1);
299 303
            //increase one usageCount
300 304
            db.increaseUsageCount(1);
301 305
            //debug message
302 306
            MetaCatUtil.debugMessage("The connection is checked out: "
303
                                       +db.getTag(), 5);
304
            MetaCatUtil.debugMessage("The age is "+db.getAge(), 5);
305
            MetaCatUtil.debugMessage("The usage is "+db.getUsageCount(), 5);
307
                                       +db.getTag(), 25);
308
            MetaCatUtil.debugMessage("The age is "+db.getAge(), 25);
309
            MetaCatUtil.debugMessage("The usage is "+db.getUsageCount(), 25);
306 310
            MetaCatUtil.debugMessage("The conection time it has: "
307
                                                +db.getConnectionTime(), 5);
311
                                                +db.getConnectionTime(), 25);
308 312
            //set check out time
309 313
            db.setCheckOutTime(System.currentTimeMillis());
310 314
            //check it out
......
384 388
    if (dbConn.getUsageCount() >= MAXIMUMUSAGENUMBER )
385 389
    {
386 390
      MetaCatUtil.debugMessage("Connection usageCount is too many: "+
387
      dbConn.getUsageCount(), 50);
391
      dbConn.getUsageCount(), 40);
388 392
      return false;
389 393
    }
390 394
    
......
392 396
    if (dbConn.getConnectionTime() >= MAXIMUMCONNECTIONTIME)
393 397
    {
394 398
      MetaCatUtil.debugMessage("Connection has too much connection time: "+
395
      dbConn.getConnectionTime(), 50);
399
      dbConn.getConnectionTime(), 40);
396 400
      return false;
397 401
    }
398 402
    
399 403
    //Check if the DBConnection is too old
400 404
    if (dbConn.getAge() >=MAXIMUMAGE)
401 405
    {
402
      MetaCatUtil.debugMessage("Connection is too old: "+dbConn.getAge(), 50);
406
      MetaCatUtil.debugMessage("Connection is too old: "+dbConn.getAge(), 40);
403 407
      return false;
404 408
    }
405 409
    
......
431 435
   * Method to return a connection to DBConnection pool.
432 436
   * @param conn, the Connection object need to check in
433 437
   */
434
  public static synchronized void returnDBConnection(DBConnection conn)
438
  public static synchronized void returnDBConnection(DBConnection conn, 
439
                                                              int serialNumber)
435 440
  {
436 441
    int index = -1;
437 442
    DBConnection dbConn = null;
......
447 452
    }//if
448 453
    else
449 454
    {
450
      dbConn = (DBConnection) connectionPool.elementAt(index);
451
      //set status to free
452
      dbConn.setStatus(FREE);
453
      //count connection time
454
      dbConn.setConnectionTime
455
      //check the paramter - serialNumber which will be keep in calling method
456
      //if it is as same as the object's checkoutserial number.
457
      //if it is same return it. If it is not same, maybe the connection already
458
      // was returned ealier.
459
      MetaCatUtil.debugMessage("serial number in Connection: "
460
                                      +conn.getCheckOutSerialNumber(), 40);
461
      MetaCatUtil.debugMessage("serial number in local: "+serialNumber, 40);
462
      if (conn.getCheckOutSerialNumber() == serialNumber)
463
      {
464
        dbConn = (DBConnection) connectionPool.elementAt(index);
465
        //set status to free
466
        dbConn.setStatus(FREE);
467
        //count connection time
468
        dbConn.setConnectionTime
455 469
                          (System.currentTimeMillis()-dbConn.getCheckOutTime());
456 470
                          
457
      //set check out time to 0
458
      dbConn.setCheckOutTime(0);
471
        //set check out time to 0
472
        dbConn.setCheckOutTime(0);
459 473
      
460
      MetaCatUtil.debugMessage("Connection: "+dbConn.getTag()+" checked in.",
461
                                                                        5);
474
        MetaCatUtil.debugMessage("Connection: "+dbConn.getTag()+" checked in.",
475
                                                                        20);
476
      }//if
462 477
    }//else
463 478
   
464 479
 
......
541 556
        {
542 557
          dbConn = (DBConnection) connectionPool.elementAt(i);
543 558
          
544
          //if a DBConnection time is greater than 30000 milliseconds 
545
          //print it out
546
          if ((System.currentTimeMillis()-dbConn.getCheckOutTime())>=30000)
559
          //if a DBConnection conncectioning time for one check out is greater 
560
          //than 30000 milliseconds print it out
561
          if (dbConn.getStatus()==BUSY && 
562
            (System.currentTimeMillis()-dbConn.getCheckOutTime())>=30000)
547 563
          {
548
            MetaCatUtil.debugMessage("This DBConnection is checked out for"
549
              +(System.currentTimeMillis()-dbConn.getCheckOutTime())/1000 , 1);
564
            MetaCatUtil.debugMessage("This DBConnection is checked out for: "
565
            +(System.currentTimeMillis()-dbConn.getCheckOutTime())/1000
566
            +" secs" , 1);
550 567
            MetaCatUtil.debugMessage(dbConn.getTag(), 1);
551
            MetaCatUtil.debugMessage(dbConn.getCheckOutMethodName(), 1);
568
            MetaCatUtil.debugMessage("method: "
569
                                          +dbConn.getCheckOutMethodName(), 10);
552 570
            
553 571
          }
554 572
          
......
558 576
            try
559 577
            {
560 578
              //try to print out the warning message for every connection
561
              MetaCatUtil.debugMessage("Warning for connection "+dbConn.getTag()
562
                                    +" : "+ dbConn.getWarningMessage(), 1);
579
              if (dbConn.getWarningMessage()!=null)
580
              {
581
                MetaCatUtil.debugMessage("Warning for connection "
582
                  +dbConn.getTag()+" : "+ dbConn.getWarningMessage(), 10);
583
              }
563 584
              //check if it is valiate, if not create new one and replace old one
564 585
              if (!validateDBConnection(dbConn))
565 586
              {
587
                MetaCatUtil.debugMessage("Recyle it: "+ dbConn.getTag(), 40);
566 588
                //close this DBConnection
567 589
                dbConn.close();
568 590
                //remove it form connection pool
......
570 592
                //insert a new DBConnection to same palace
571 593
                dbConn = new DBConnection();
572 594
                connectionPool.insertElementAt(dbConn, i);
573
              }//if
595
               }//if
574 596
            }//try
575 597
            catch (SQLException e)
576 598
            {

Also available in: Unified diff