Re: again:dropped connection

From: Riccardo Cohen <rcohen@xxx.oleane.com>
Date: Mon Sep 16 2002 - 03:05:32 PDT

here is what we do to request a new connection object (called art_db)
Before giving the object, we always check if it is connected .

  //MMMMMMMMMMMMMM
  /** returns null if none available. caller should try later */
  synchronized public art_db get_connection()
  {
    art_db ret=null,db;
    Iterator iter=pool.iterator();
//int cnt=1;
    while(iter.hasNext())
    {
      db=(art_db)iter.next();
      if (!db.is_in_use())
      {
//art_log.send("POOL OPEN NB "+cnt);
        db.set_in_use(true);
        total_in_use+=1;
        ret=db;
        break;
      }
//cnt+=1;
    }
    if (ret==null && pool.size()<max_pool_size)
    {
      db=new art_db();
      db.set_driver(driver_name);
      if (db.connect(url,username,password))
      {
//art_log.send("POOL CREATE NB "+(pool.size()+1)+" / "+ max_pool_size);
        ret=db;
        pool.addLast(db);
        db.set_in_use(true);
        total_in_use+=1;
      }
    }
    if (ret!=null && !ret.is_connected())
    {
//art_log.send("art_dbpool.get_connection : found but not connected");
      if (!ret.connect(url,username,password))
        art_log.send("art_dbpool.get_connection : re-connecting impossible");
      if (!ret.is_connected())
      {
        art_log.send("art_dbpool.get_connection : re-connecting failed");
        ret=null;
      }
//else
// art_log.send("art_dbpool.get_connection : re-connecting OK!");
    }
    if (ret==null)
      art_log.send("art_dbpool.get_connection : cannot get connection, total_in_use="+total_in_use+"/"+max_pool_size);
    return ret;
  }

-- 
Riccardo Cohen
Articque
Les Roches
37230 Fondettes
France
email = rcohen@xxx.oleane.com
web = http://www.articque.com
tel: +33 02 47 49 90 49
fax: +33 02 47 49 91 49
Received on Mon 16 Sep 2002 03:05:32 -0700

This archive was generated by hypermail 2.1.8 : Thu Sep 28 2006 - 20:17:14 PDT