avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon/src/java/org/apache/avalon/util/datasource JdbcConnectionPool.java
Date Fri, 06 Apr 2001 13:55:52 GMT
bloritsch    01/04/06 06:55:52

  Modified:    src/java/org/apache/avalon/component
                        DefaultComponentManager.java
               src/java/org/apache/avalon/util/datasource
                        JdbcConnectionPool.java
  Log:
  Reworked ComponentManagement infrastructure a little bit, and made
  JdbcConnectionPool check to see if the server had severed a connection
  or not.
  
  Revision  Changes    Path
  1.2       +24 -42    jakarta-avalon/src/java/org/apache/avalon/component/DefaultComponentManager.java
  
  Index: DefaultComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/component/DefaultComponentManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultComponentManager.java	2001/04/05 19:40:45	1.1
  +++ DefaultComponentManager.java	2001/04/06 13:55:47	1.2
  @@ -34,7 +34,7 @@
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/04/05 19:40:45 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/04/06 13:55:47 $
    */
   public class DefaultComponentManager extends AbstractLoggable
           implements ComponentManager, Configurable, Contextualizable, Disposable {
  @@ -53,7 +53,7 @@
   
       /** RoleInfos.
        */
  -    private RoleInfo roles;
  +    private RoleManager roles;
   
       /** Is the Manager disposed or not? */
       private boolean disposed = false;
  @@ -126,7 +126,7 @@
               Configuration config = new DefaultConfiguration("", "-");
   
               try {
  -                componentClass = this.getClass().getClassLoader().loadClass(roles.defaultClass(role));
  +                componentClass = this.getClass().getClassLoader().loadClass(roles.getDefaultClassNameForRole(role));
   
                   handler = new DefaultComponentHandler(componentClass, config, this, this.context);
                   handler.setLogger(getLogger());
  @@ -161,56 +161,38 @@
        * Configure the ComponentManager.
        */
       public void configure(Configuration conf) throws ConfigurationException {
  -        DefaultRoleInfo role_info = new DefaultRoleInfo();
  +        DefaultRoleManager role_info = new DefaultRoleManager();
           role_info.setLogger(getLogger());
           role_info.configure(conf);
           roles = role_info;
   
           // Set components
   
  -        Configuration[] e = conf.getChildren("component");
  +        Configuration[] e = conf.getChildren();
           for (int i = 0; i < e.length; i++) {
  -            String type = e[i].getAttribute("type", "");
  -            String role = e[i].getAttribute("role", "");
  -            String className = e[i].getAttribute("class", "");
  +            String type = e[i].getName(); // types are already trimmed
   
  -            if (! "".equals(type)) {
  -                role = roles.lookup(type);
  -            }
  -
  -            if ("".equals(className)) {
  -                className = roles.defaultClass(role);
  -            }
  -
  -            try {
  -                getLogger().debug("Adding component (" + role + " = " + className + ")");
  -                this.addComponent(role, this.getClass().getClassLoader().loadClass(className),e[i]);
  -            } catch ( Exception ex ) {
  -                getLogger().error("Could not load class " + className, ex);
  -                throw new ConfigurationException("Could not get class " + className
  -                    + " for role " + role, ex);
  -            }
  -        }
  -
  -        Iterator r = roles.shorthandNames();
  -        while (r.hasNext()) {
  -            Configuration co = conf.getChild((String) r.next(), false);
  -
  -            if (co != null) {
  -                String role = roles.lookup(co.getName());
  -                String className = co.getAttribute("class", "");
  +            if (("role".equals(type) == false)) {
  +                String role = e[i].getAttribute("role", "");
  +                String className = e[i].getAttribute("class", "");
   
  -                if ("".equals(className)) {
  -                    className = roles.defaultClass(role);
  +                if ("".equals(role)) {
  +                    role = roles.getRoleForName(type);
                   }
   
  -                try {
  -                    getLogger().debug("Adding component (" + role + " = " + className +
")");
  -                    this.addComponent(role, this.getClass().getClassLoader().loadClass(className),
co);
  -                } catch ( Exception ex ) {
  -                    getLogger().error("Could not load class " + className, ex);
  -                    throw new ConfigurationException("Could not get class " + className
  -                        + " for role " + role, ex);
  +                if (role != null && ("".equals(role) == false)) {
  +                    if ("".equals(className)) {
  +                        className = roles.getDefaultClassNameForRole(role);
  +                    }
  +
  +                    try {
  +                        getLogger().debug("Adding component (" + role + " = " + className
+ ")");
  +                        this.addComponent(role, this.getClass().getClassLoader().loadClass(className),
e[i]);
  +                    } catch ( Exception ex ) {
  +                        getLogger().error("Could not load class " + className, ex);
  +                        throw new ConfigurationException("Could not get class " + className
  +                            + " for role " + role + " on configuration element " + e[i].getName(),
ex);
  +                    }
                   }
               }
           }
  
  
  
  1.11      +20 -8     jakarta-avalon/src/java/org/apache/avalon/util/datasource/JdbcConnectionPool.java
  
  Index: JdbcConnectionPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/util/datasource/JdbcConnectionPool.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JdbcConnectionPool.java	2001/04/04 18:05:50	1.10
  +++ JdbcConnectionPool.java	2001/04/06 13:55:49	1.11
  @@ -26,7 +26,7 @@
    * thread to manage the number of SQL Connections.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.10 $ $Date: 2001/04/04 18:05:50 $
  + * @version CVS $Revision: 1.11 $ $Date: 2001/04/06 13:55:49 $
    */
   public class JdbcConnectionPool
       extends AbstractLoggable
  @@ -164,13 +164,25 @@
           m_lock.lock(m_active);
           m_active.remove( obj );
   
  -        if(! m_disposed)
  -        {
  -            m_lock.lock(m_ready);
  -            m_ready.add( obj );
  -            m_lock.unlock(m_ready);
  -        } else {
  -            recycle((Recyclable) obj);
  +        try {
  +            if(! m_disposed)
  +            {
  +                JdbcConnection connection = (JdbcConnection) obj;
  +
  +                if (connection.isClosed()) {
  +                    getLogger().warn("Connection was closed by server, attempting to create
a new one in its stead.");
  +                    connection.recycle();
  +                    connection = this.createJdbcConnection();
  +                }
  +
  +                m_lock.lock(m_ready);
  +                m_ready.add( connection );
  +                m_lock.unlock(m_ready);
  +            } else {
  +                recycle((Recyclable) obj);
  +            }
  +        } catch (SQLException se) {
  +            getLogger().warn("Error returning connection to pool", se);
           }
   
           m_lock.unlock(m_active);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Mime
View raw message