james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oki DZ <ok...@pindad.com>
Subject DB connection pooling in 1.3-dev
Date Fri, 20 Jul 2001 04:31:54 GMT
Hi,

I just started to test the version 1.3 of James. It works. I don't know
how much faster it is; I use it on a production machine, so that the
necessary ports are basically used. Anyway, I think the JDBCUserRepository
and JDBCMailRepository should use a database connection pooling service,
so that the server doesn't have to always connecting and disconnecting to
the db server each time it has to retrieve/store mail.

There is JdbcDataSource class from Avalon Excalibur that does connection
pooling; unfortunately, it doesn't work (I have posted a message to the
dev. list). Hopefully, it gets fixed soon. I think it would be pretty
natural to use the conn. pooling from Avalon; James already uses Avalon,
so having an extension of it to support the pooling would be the right
choice.

BTW, if you want to use another pooling implementation, you can use
Turbine. It would sound a bit overkill to use it just to have the pooling
service. But for the long run, it might be good. For example, if James
would implement a web based administration service. Turbine has a
templating service, and I think Avalon could have a simple servlet
container in the future. This would be beneficial for those who'd like to
have James but don't want to install a fullblown servlet container like
Tomcat.  Additionally, you can choose to have the necessary Turbine
services to be started; so the memory usage could be set into minimum. 

Just in case you want to use Turbine, I already have Turbine got loaded by
James (ie: Phoenix). Turbine is a singleton, so you want to make sure that
it gets loaded once (twice or more would be allright, except that it would
print out some message). The snippet code is in the following:

public class TurbineLoader extends AbstractLoggable
    implements Block, Configurable, Initializable {

    private String turbinePath, turbineFilename;

    public void configure(Configuration configuration) 
	throws ConfigurationException {
	turbinePath = configuration.getChild("properties")
	    .getChild("path")
	    .getValue(".");
	turbineFilename = configuration.getChild("properties")
	    .getChild("filename")
	    .getValue("TurbineResources.properties");
	getLogger().info("Configuration loaded.");
    }

    public void initialize() throws Exception {
	try {
	    new TurbineConfig(turbinePath, turbineFilename).init();
	    getLogger().info("Turbine initialized.");
	} catch(Exception e) {
	    getLogger().error("Turbine initialization failed." + 
			      e.getMessage(), e);
	    throw e;
	}
    }
} // TurbineLoader 

And in assembly.xml:
 <block class="com.pindad.james.services.TurbineLoader"
name="class-loader">
  </block>

in config.xml:
  <class-loader name="Turbine">
    <properties>
      <path>/some/path/jakarta-james/dist/apps/james/conf</path>
      <filename>TurbineResources.properties</filename>
    </properties>
  </class-loader>
I think having a "turbine-loader" instead of "class-loader" would be
nicer.

And some changes in server.xml to have the elements for the appropriate
logger.

The only problem is that you'd have an additional config file to maintain;
Turbine needs it. Hopefully, Turbine can be configured by using a
java.util.Properties in the future, so that the props could be set from
James' config.xml.

BTW, to get a connection is pretty straightforward:
// countUsers() in UsersRepository
    public int countUsers() {
	int numofusers = 0;
	try {
	    DBConnection dbConn = getConnection();
	    count = dbConn.getConnection().prepareStatement(countStr);
	    rs = count.executeQuery();
	    if (rs.next())
		numofusers = rs.getInt(1);
	    rs.close();
	    releaseConnection(dbConn);
	} catch(Exception e) { 
	    getLogger().error("Error in getting user count - " +
e.getMessage(), e);
	}
	return numofusers;
    }  

Oki


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


Mime
View raw message