[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/pool DbPool.java,NONE,1.1 IDRSPool.java,NONE,1.
Brought to you by:
bigman921
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/pool
In directory usw-pr-cvs1:/tmp/cvs-serv21727/dev/src/net/sourceforge/idrs/pool
Added Files:
DbPool.java IDRSPool.java IDRSRepPool.java JDBCPool.java
RepPool.java ScriptContextPool.java ScriptPool.java
Log Message:
Synced development
--- NEW FILE: DbPool.java ---
package net.sourceforge.idrs.pool;
import java.sql.*;
import net.sourceforge.idrs.jdbc.*;
/**
* Defines the basis for a DB pool, must be exteded
*/
public abstract class DbPool implements IDRSPool {
JDBCInfo info;
String poolname;
int min;
int limit;
int idleTime;
long sleepTime;
String logpath;
public void build(String poolname, String drivername, String url,
String username, String password, int min, int limit,
long daysOpen, long sleep, String path) throws Exception {
info = new JDBCInfo(poolname, drivername, url, username, password);
}
/**
*Retrieves a connection
*/
public Connection getConnection() throws Exception {
return (Connection) getObj();
}
/**
*Returns a connection
*/
public void returnConnection(Connection con) throws Exception {
returnObj(con);
}
/**
*Returns the jdbcinfo object
*/
public JDBCInfo getInfo() {
return info;
}
}
--- NEW FILE: IDRSPool.java ---
package net.sourceforge.idrs.pool;
import java.util.*;
/**
* This interface acts as a connection between the IDRS and a
* pooling implementation
*/
public interface IDRSPool {
/**
*Retrieves an object from the pool, does not define failure condition
*/
public Object getObj() throws Exception;
/**
*Returns an object to the pool, does not define failure conditions
*/
public void returnObj(Object obj) throws Exception;
/**
*Deinitializes the pool
*/
public void close() throws Exception;
}
--- NEW FILE: IDRSRepPool.java ---
package net.sourceforge.idrs.pool;
import org.apache.commons.pool.*;
import org.apache.commons.pool.impl.*;
import net.sourceforge.idrs.core.report.*;
public class IDRSRepPool extends net.sourceforge.idrs.pool.RepPool {
ObjectPool pool;
public void build(int objectMin, int objectLimit, IDRSRep rep, long sleepTime, String path,int trys) throws Exception {
super.build(objectMin,objectLimit,rep,sleepTime,path,trys);
GenericObjectPool.Config conf = new GenericObjectPool.Config();
conf.maxActive = limit;
conf.maxWait = sleepTime;
conf.testOnBorrow = true;
conf.timeBetweenEvictionRunsMillis = 100000;
conf.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
pool = new GenericObjectPool(new ReportFactory(rep),conf);
}
public Object getObj() throws Exception {
return pool.borrowObject();
}
public void returnObj(Object obj) throws Exception {
pool.returnObject(obj);
}
public void close() throws Exception {
pool.close();
}
}
class ReportFactory implements PoolableObjectFactory {
IDRSRep rep;
public ReportFactory(IDRSRep rep) {
this.rep = rep;
}
public void activateObject(Object obj) throws Exception {
}
public void destroyObject(Object obj) throws Exception {
}
public Object makeObject() throws Exception {
return rep.clone();
}
public void passivateObject(Object obj) throws Exception {
}
public boolean validateObject(Object obj) {
return obj != null;
}
}
--- NEW FILE: JDBCPool.java ---
package net.sourceforge.idrs.pool;
import org.apache.commons.pool.*;
import org.apache.commons.pool.impl.*;
import net.sourceforge.idrs.jdbc.*;
import java.sql.*;
public class JDBCPool extends DbPool {
ObjectPool pool;
public void build(String poolname, String drivername, String url,
String username, String password, int min, int limit,
long daysOpen, long sleep, String path) throws Exception {
super.build(poolname,drivername,url,username,password,min,limit,daysOpen,sleep,path);
GenericObjectPool.Config conf = new GenericObjectPool.Config();
conf.maxActive = limit;
conf.maxWait = sleepTime;
conf.testOnBorrow = true;
conf.timeBetweenEvictionRunsMillis = 100000;
conf.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
pool = new GenericObjectPool(new JDBCFactory(info),conf);
}
public Object getObj() throws Exception {
return pool.borrowObject();
}
public void returnObj(Object obj) throws Exception {
pool.returnObject(obj);
}
public void close() throws Exception {
pool.close();
}
}
class JDBCFactory implements PoolableObjectFactory {
JDBCInfo jdbcInfo;
public JDBCFactory(JDBCInfo jdbc) {
this.jdbcInfo = jdbc;
}
public void activateObject(Object obj) throws Exception {
}
public void destroyObject(Object obj) throws Exception {
((Connection) obj).close();
}
public Object makeObject() throws Exception {
return jdbcInfo.build();
}
public void passivateObject(Object obj) throws Exception {
}
public boolean validateObject(Object obj) {
try {
return obj != null && ! ((Connection) obj).isClosed();
}
catch (Exception e) {
return false;
}
}
}
--- NEW FILE: RepPool.java ---
package net.sourceforge.idrs.pool;
import net.sourceforge.idrs.core.report.*;
import java.sql.*;
/**
* Defines the basis for a Report pool, must be exteded
*/
public abstract class RepPool implements IDRSPool {
String poolname;
int min;
int limit;
int idleTime;
long sleepTime;
String logPath;
IDRSRep rep;
public void build(int objectMin, int objectLimit, IDRSRep rep, long sleepTime, String path,int trys) throws Exception {
this.rep = rep;
this.min = objectMin;
this.limit=objectLimit;
this.sleepTime = sleepTime;
this.logPath = path;
}
/**
*Retrieves a Report
*/
public IDRSRep getReport() throws Exception {
return (IDRSRep) getObj();
}
/**
*Returns a Report
*/
public void returnReport(IDRSRep rep) throws Exception {
returnObj(rep);
}
}
--- NEW FILE: ScriptContextPool.java ---
package net.sourceforge.idrs.pool;
import org.apache.commons.pool.*;
import org.apache.commons.*;
import org.apache.commons.pool.impl.*;
import org.apache.commons.*;
import net.sourceforge.idrs.script.embedable.*;
public class ScriptContextPool extends ScriptPool {
ObjectPool pool;
public void build(int objectMin, int objectLimit, String scriptClass, long sleepTime, String path,int trys) throws Exception {
super.build(objectMin,objectLimit,scriptClass,sleepTime,path,trys);
GenericObjectPool.Config conf = new GenericObjectPool.Config();
conf.maxActive = limit;
conf.maxWait = sleepTime;
conf.testOnBorrow = true;
conf.timeBetweenEvictionRunsMillis = 100000;
conf.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
pool = new GenericObjectPool(new ScriptFactory(scriptClass),conf);
}
public Object getObj() throws Exception {
return pool.borrowObject();
}
public void returnObj(Object obj) throws Exception {
pool.returnObject(obj);
}
public void close() throws Exception {
pool.close();
}
}
class ScriptFactory implements PoolableObjectFactory {
String scriptClass;
public ScriptFactory(String scriptClass) {
this.scriptClass = scriptClass;
}
public void activateObject(Object obj) throws Exception {
}
public void destroyObject(Object obj) throws Exception {
}
public Object makeObject() throws Exception {
return Class.forName(scriptClass).newInstance();
}
public void passivateObject(Object obj) throws Exception {
}
public boolean validateObject(Object obj) {
return obj != null;
}
}
--- NEW FILE: ScriptPool.java ---
package net.sourceforge.idrs.pool;
import java.sql.*;
import net.sourceforge.idrs.script.embedable.*;
/**
* Defines the basis for a Report pool, must be exteded
*/
public abstract class ScriptPool implements IDRSPool {
String poolname;
int min;
int limit;
int idleTime;
long sleepTime;
String logPath;
String scriptClass;
public void build(int objectMin, int objectLimit, String scriptClass, long sleepTime, String path,int trys) throws Exception {
this.min = objectMin;
this.limit=objectLimit;
this.sleepTime = sleepTime;
this.logPath = path;
this.scriptClass = scriptClass;
}
/**
*Retrieves a Conetext
*/
public IDRSScriptLanguage getContext() throws Exception {
return (IDRSScriptLanguage) getObj();
}
/**
*Returns a Context
*/
public void returnContext(IDRSScriptLanguage script) throws Exception {
returnObj(script);
}
}
|