comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/connectionpool/ArcSDEConnectionPool.java @ 265:e5379e129799

Fixed issue 34 geo-backend/trunk@215 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 13 Oct 2009 13:20:26 +0000
parents e4eacd613356
children ff1b7967e6b9
comparison
equal deleted inserted replaced
264:5bbdbc0bbddc 265:e5379e129799
10 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool; 10 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool;
11 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException; 11 import de.intevation.gnv.geobackend.base.connectionpool.exception.ConnectionException;
12 12
13 /** 13 /**
14 *This is the ArcSDE specific implementation of the Interface ConnectionPool 14 *This is the ArcSDE specific implementation of the Interface ConnectionPool
15 *
15 * @author Tim Englich <tim.englich@intevation.de> 16 * @author Tim Englich <tim.englich@intevation.de>
16 */ 17 */
17 public class ArcSDEConnectionPool implements ConnectionPool { 18 public class ArcSDEConnectionPool implements ConnectionPool {
18 19
19 /** 20 /**
20 * the logger, used to log exceptions and additonaly information 21 * the logger, used to log exceptions and additonaly information
21 */ 22 */
22 private static Logger log = Logger.getLogger(ArcSDEPoolableObjectFactory.class); 23 private static Logger log = Logger
23 24 .getLogger(ArcSDEPoolableObjectFactory.class);
24 /**
25 * The Pool which stores the Connections to the ArcSDE Backend
26 */
27 private GenericObjectPool pool = null;
28
29 /**
30 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object)
31 */
32 public void closeConnection(Connection connection) throws ConnectionException {
33
34 try {
35 //TODO: Muss Connection geschlossen werden?
36 this.pool.returnObject(connection);
37 } catch (Exception e) {
38 log.error(e,e);
39 throw new ConnectionException(e);
40 }
41 25
26 /**
27 * The Pool which stores the Connections to the ArcSDE Backend
28 */
29 private GenericObjectPool pool = null;
30
31 /**
32 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#closeConnection(java.lang.Object)
33 */
34 public void closeConnection(Connection connection)
35 throws ConnectionException {
36
37 try {
38 // TODO: Muss Connection geschlossen werden?
39 this.pool.returnObject(connection);
40 } catch (Exception e) {
41 log.error(e, e);
42 throw new ConnectionException(e);
43 }
44
45 }
46
47 /**
48 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String)
49 */
50 public synchronized Connection getConnection(String connectionID)
51 throws ConnectionException {
52 try {
53 Object object = this.pool.borrowObject();
54
55 if (object instanceof Connection) {
56 return (Connection) object;
57 } else {
58 throw new ConnectionException(
59 "Created Object is not an java.sql.Connection");
60 }
61
62 } catch (Exception e) {
63 log.error(e, e);
64 throw new ConnectionException(e);
65 }
66 }
67
68 /**
69 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties)
70 */
71 public void initialize(Properties properties) {
72 log.info("ArcSDEConnectionPool.initialize has been called");
73 log.info("ConnectionPool will be initialized");
74
75 PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(
76 properties);
77
78 int maxActive = Integer.parseInt(properties.getProperty("maxActive",
79 "10"));
80 long maxWait = Long.parseLong(properties.getProperty("maxWait",
81 "" + GenericObjectPool.DEFAULT_MAX_WAIT));
82 int maxIdle = Integer.parseInt(properties.getProperty("maxIdle",
83 "" + GenericObjectPool.DEFAULT_MAX_IDLE));
84 int minIdle = Integer.parseInt(properties.getProperty("minIdle",
85 "" + GenericObjectPool.DEFAULT_MIN_IDLE));
86 boolean testOnBorrow = Boolean.parseBoolean(properties.getProperty(
87 "testOnBorrow", "" + GenericObjectPool.DEFAULT_TEST_ON_BORROW));
88 boolean testOnReturn = Boolean.parseBoolean(properties.getProperty(
89 "testOnReturn", "" + GenericObjectPool.DEFAULT_TEST_ON_RETURN));
90 long timeBetweenEvictionRunsMillis = Long
91 .parseLong(properties
92 .getProperty(
93 "timeBetweenEvictionRunsMillis",
94 ""
95 + GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
96 int numTestsPerEvictionRun = Integer.parseInt(properties.getProperty(
97 "numTestsPerEvictionRun",
98 "" + GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN));
99 long minEvictableIdleTimeMillis = Long
100 .parseLong(properties
101 .getProperty(
102 "minEvictableIdleTimeMillis",
103 ""
104 + GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS));
105 boolean testWhileIdle = Boolean.parseBoolean(properties
106 .getProperty("testWhileIdle",
107 "" + GenericObjectPool.DEFAULT_TEST_WHILE_IDLE));
108
109 log.info("Maximum Number of active Connections: " + maxActive);
110 log.info("Maximum Number of waiting: " + maxWait);
111 log.info("Maximum Number of idle: " + maxIdle);
112 log.info("Minimum Number of idle: " + minIdle);
113 log.info("TestOnBorrow: " + testOnBorrow);
114 log.info("TestOnReturn: " + testOnReturn);
115 log.info("TimeBetweenEvictionRunsMillis: " + timeBetweenEvictionRunsMillis);
116 log.info("NumTestsPerEvictionRun: " + numTestsPerEvictionRun);
117 log.info("MinEvictableIdleTimeMillis: " + minEvictableIdleTimeMillis);
118 log.info("TestWhileIdle: " + testWhileIdle);
119
120 this.pool = new GenericObjectPool(poolableObjectFactory, maxActive,
121 GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, maxWait,
122 maxIdle, minIdle, testOnBorrow, testOnReturn,
123 timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
124 minEvictableIdleTimeMillis, testWhileIdle);
42 } 125 }
43
44 /**
45 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#getConnection(java.lang.String)
46 */
47 public synchronized Connection getConnection(String connectionID) throws ConnectionException{
48 try {
49 Object object = this.pool.borrowObject();
50
51 if (object instanceof Connection){
52 return (Connection)object;
53 }else{
54 throw new ConnectionException("Created Object is not an java.sql.Connection");
55 }
56
57 } catch (Exception e) {
58 log.error(e,e);
59 throw new ConnectionException(e);
60 }
61 }
62
63 /**
64 * @see de.intevation.gnv.geobackend.base.connectionpool.ConnectionPool#initialize(java.util.Properties)
65 */
66 public void initialize(Properties properties) {
67 log.info("ArcSDEConnectionPool.initialize has been called");
68 log.info("ConnectionPool will be initialized");
69
70 PoolableObjectFactory poolableObjectFactory = new ArcSDEPoolableObjectFactory(properties);
71
72 int maxActive = Integer.parseInt(properties.getProperty("maxActive", "10"));
73
74 log.info("Maximum Number of active Connections: "+maxActive);
75 // TODO weitere Werte einparsen und setzen.
76
77 this.pool = new GenericObjectPool(poolableObjectFactory,maxActive);
78
79 }
80
81 } 126 }

http://dive4elements.wald.intevation.org