PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/vt-ldap/tags/vt-ldap-3.3.3/src/main/java/edu/vt/middleware/ldap/pool/LdapPoolConfig.java

http://vt-middleware.googlecode.com/
Java | 379 lines | 164 code | 62 blank | 153 comment | 21 complexity | f1d73385133c56c0e56306fdbfb84cb5 MD5 | raw file
Possible License(s): GPL-3.0, Apache-2.0, LGPL-3.0, LGPL-2.1
  1. /*
  2. $Id: LdapPoolConfig.java 1330 2010-05-23 22:10:53Z dfisher $
  3. Copyright (C) 2003-2010 Virginia Tech.
  4. All rights reserved.
  5. SEE LICENSE FOR MORE INFORMATION
  6. Author: Middleware Services
  7. Email: middleware@vt.edu
  8. Version: $Revision: 1330 $
  9. Updated: $Date: 2010-05-24 00:10:53 +0200 (Mon, 24 May 2010) $
  10. */
  11. package edu.vt.middleware.ldap.pool;
  12. import java.io.InputStream;
  13. import edu.vt.middleware.ldap.props.AbstractPropertyConfig;
  14. import edu.vt.middleware.ldap.props.LdapConfigPropertyInvoker;
  15. import edu.vt.middleware.ldap.props.LdapProperties;
  16. /**
  17. * <code>LdapPoolConfig</code> contains all the configuration data that the
  18. * pooling implementations need to control the pool.
  19. *
  20. * @author Middleware Services
  21. * @version $Revision: 1330 $ $Date: 2010-05-24 00:10:53 +0200 (Mon, 24 May 2010) $
  22. */
  23. public class LdapPoolConfig extends AbstractPropertyConfig
  24. {
  25. /** Domain to look for ldap properties in, value is {@value}. */
  26. public static final String PROPERTIES_DOMAIN = "edu.vt.middleware.ldap.pool.";
  27. /** Default min pool size, value is {@value}. */
  28. public static final int DEFAULT_MIN_POOL_SIZE = 3;
  29. /** Default max pool size, value is {@value}. */
  30. public static final int DEFAULT_MAX_POOL_SIZE = 10;
  31. /** Default validate on check in, value is {@value}. */
  32. public static final boolean DEFAULT_VALIDATE_ON_CHECKIN = false;
  33. /** Default validate on check out, value is {@value}. */
  34. public static final boolean DEFAULT_VALIDATE_ON_CHECKOUT = false;
  35. /** Default validate periodically, value is {@value}. */
  36. public static final boolean DEFAULT_VALIDATE_PERIODICALLY = false;
  37. /** Default validate timer period, value is {@value}. */
  38. public static final long DEFAULT_VALIDATE_TIMER_PERIOD = 1800000;
  39. /** Default prune timer period, value is {@value}. */
  40. public static final long DEFAULT_PRUNE_TIMER_PERIOD = 300000;
  41. /** Default expiration time, value is {@value}. */
  42. public static final long DEFAULT_EXPIRATION_TIME = 600000;
  43. /** Invoker for ldap properties. */
  44. private static final LdapConfigPropertyInvoker PROPERTIES =
  45. new LdapConfigPropertyInvoker(LdapPoolConfig.class, PROPERTIES_DOMAIN);
  46. /** Min pool size. */
  47. private int minPoolSize = DEFAULT_MIN_POOL_SIZE;
  48. /** Max pool size. */
  49. private int maxPoolSize = DEFAULT_MAX_POOL_SIZE;
  50. /** Whether the ldap object should be validated when returned to the pool. */
  51. private boolean validateOnCheckIn = DEFAULT_VALIDATE_ON_CHECKIN;
  52. /** Whether the ldap object should be validated when given from the pool. */
  53. private boolean validateOnCheckOut = DEFAULT_VALIDATE_ON_CHECKOUT;
  54. /** Whether the pool should be validated periodically. */
  55. private boolean validatePeriodically = DEFAULT_VALIDATE_PERIODICALLY;
  56. /** Time in milliseconds that the validate pool timer should repeat. */
  57. private long validateTimerPeriod = DEFAULT_VALIDATE_TIMER_PERIOD;
  58. /** Time in milliseconds that the prune pool timer should repeat. */
  59. private long pruneTimerPeriod = DEFAULT_PRUNE_TIMER_PERIOD;
  60. /** Time in milliseconds that ldap objects should be considered expired. */
  61. private long expirationTime = DEFAULT_EXPIRATION_TIME;
  62. /** Default constructor. */
  63. public LdapPoolConfig() {}
  64. /**
  65. * This returns the min pool size for the <code>LdapPoolConfig</code>. Default
  66. * value is {@link #DEFAULT_MIN_POOL_SIZE}. This value represents the size of
  67. * the pool after the prune timer has run.
  68. *
  69. * @return <code>int</code> - min pool size
  70. */
  71. public int getMinPoolSize()
  72. {
  73. return this.minPoolSize;
  74. }
  75. /**
  76. * This returns the max pool size for the <code>LdapPoolConfig</code>. Default
  77. * value is {@link #DEFAULT_MAX_POOL_SIZE}. This value may or may not be
  78. * strictly enforced depending on the pooling implementation.
  79. *
  80. * @return <code>int</code> - max pool size
  81. */
  82. public int getMaxPoolSize()
  83. {
  84. return this.maxPoolSize;
  85. }
  86. /**
  87. * This returns the validate on check in flag for the <code>
  88. * LdapPoolConfig</code>. Default value is {@link
  89. * #DEFAULT_VALIDATE_ON_CHECKIN}.
  90. *
  91. * @return <code>boolean</code> - validate on check in
  92. */
  93. public boolean isValidateOnCheckIn()
  94. {
  95. return this.validateOnCheckIn;
  96. }
  97. /**
  98. * This returns the validate on check out flag for the <code>
  99. * LdapPoolConfig</code>. Default value is {@link
  100. * #DEFAULT_VALIDATE_ON_CHECKOUT}.
  101. *
  102. * @return <code>boolean</code> - validate on check in
  103. */
  104. public boolean isValidateOnCheckOut()
  105. {
  106. return this.validateOnCheckOut;
  107. }
  108. /**
  109. * This returns the validate periodically flag for the <code>
  110. * LdapPoolConfig</code>. Default value is {@link
  111. * #DEFAULT_VALIDATE_PERIODICALLY}.
  112. *
  113. * @return <code>boolean</code> - validate periodically
  114. */
  115. public boolean isValidatePeriodically()
  116. {
  117. return this.validatePeriodically;
  118. }
  119. /**
  120. * This returns the prune timer period for the <code>LdapPoolConfig</code>.
  121. * Default value is {@link #DEFAULT_PRUNE_TIMER_PERIOD}. The prune timer
  122. * attempts to execute {@link LdapPool#prune()}.
  123. *
  124. * @return <code>long</code> - prune timer period in milliseconds
  125. */
  126. public long getPruneTimerPeriod()
  127. {
  128. return this.pruneTimerPeriod;
  129. }
  130. /**
  131. * This returns the validate timer period for the <code>LdapPoolConfig</code>.
  132. * Default value is {@link #DEFAULT_VALIDATE_TIMER_PERIOD}. The validate timer
  133. * attempts to execute {@link LdapPool#validate()}.
  134. *
  135. * @return <code>long</code> - validate timer period in milliseconds
  136. */
  137. public long getValidateTimerPeriod()
  138. {
  139. return this.validateTimerPeriod;
  140. }
  141. /**
  142. * This returns the expiration time for the <code>LdapPoolConfig</code>.
  143. * Default value is {@link #DEFAULT_EXPIRATION_TIME}. The expiration time
  144. * represents the max time an ldap object should be available before it is
  145. * considered stale. This value does not apply to objects in the pool if the
  146. * pool has only a minimum number of objects available.
  147. *
  148. * @return <code>long</code> - expiration time in milliseconds
  149. */
  150. public long getExpirationTime()
  151. {
  152. return this.expirationTime;
  153. }
  154. /**
  155. * This sets the min pool size for the <code>LdapPoolConfig</code>.
  156. *
  157. * @param size <code>int</code>
  158. */
  159. public void setMinPoolSize(final int size)
  160. {
  161. checkImmutable();
  162. if (size >= 0) {
  163. if (this.logger.isTraceEnabled()) {
  164. this.logger.trace("setting minPoolSize: " + size);
  165. }
  166. this.minPoolSize = size;
  167. }
  168. }
  169. /**
  170. * This sets the max pool size for the <code>LdapPoolConfig</code>.
  171. *
  172. * @param size <code>int</code>
  173. */
  174. public void setMaxPoolSize(final int size)
  175. {
  176. checkImmutable();
  177. if (size >= 0) {
  178. if (this.logger.isTraceEnabled()) {
  179. this.logger.trace("setting maxPoolSize: " + size);
  180. }
  181. this.maxPoolSize = size;
  182. }
  183. }
  184. /**
  185. * This sets the validate on check in flag for the <code>
  186. * LdapPoolConfig</code>.
  187. *
  188. * @param b <code>boolean</code>
  189. */
  190. public void setValidateOnCheckIn(final boolean b)
  191. {
  192. checkImmutable();
  193. if (this.logger.isTraceEnabled()) {
  194. this.logger.trace("setting validateOnCheckIn: " + b);
  195. }
  196. this.validateOnCheckIn = b;
  197. }
  198. /**
  199. * This sets the validate on check out flag for the <code>
  200. * LdapPoolConfig</code>.
  201. *
  202. * @param b <code>boolean</code>
  203. */
  204. public void setValidateOnCheckOut(final boolean b)
  205. {
  206. checkImmutable();
  207. if (this.logger.isTraceEnabled()) {
  208. this.logger.trace("setting validateOnCheckOut: " + b);
  209. }
  210. this.validateOnCheckOut = b;
  211. }
  212. /**
  213. * This sets the validate periodically flag for the <code>
  214. * LdapPoolConfig</code>.
  215. *
  216. * @param b <code>boolean</code>
  217. */
  218. public void setValidatePeriodically(final boolean b)
  219. {
  220. checkImmutable();
  221. if (this.logger.isTraceEnabled()) {
  222. this.logger.trace("setting validatePeriodically: " + b);
  223. }
  224. this.validatePeriodically = b;
  225. }
  226. /**
  227. * Sets the period for which the prune pool timer will run.
  228. *
  229. * @param time in milliseconds
  230. */
  231. public void setPruneTimerPeriod(final long time)
  232. {
  233. checkImmutable();
  234. if (time >= 0) {
  235. if (this.logger.isTraceEnabled()) {
  236. this.logger.trace("setting pruneTimerPeriod: " + time);
  237. }
  238. this.pruneTimerPeriod = time;
  239. }
  240. }
  241. /**
  242. * Sets the period for which the validate pool timer will run.
  243. *
  244. * @param time in milliseconds
  245. */
  246. public void setValidateTimerPeriod(final long time)
  247. {
  248. checkImmutable();
  249. if (time >= 0) {
  250. if (this.logger.isTraceEnabled()) {
  251. this.logger.trace("setting validateTimerPeriod: " + time);
  252. }
  253. this.validateTimerPeriod = time;
  254. }
  255. }
  256. /**
  257. * Sets the time that an ldap object should be considered stale and ready for
  258. * removal from the pool.
  259. *
  260. * @param time in milliseconds
  261. */
  262. public void setExpirationTime(final long time)
  263. {
  264. checkImmutable();
  265. if (time >= 0) {
  266. if (this.logger.isTraceEnabled()) {
  267. this.logger.trace("setting expirationTime: " + time);
  268. }
  269. this.expirationTime = time;
  270. }
  271. }
  272. /** {@inheritDoc} */
  273. public String getPropertiesDomain()
  274. {
  275. return PROPERTIES_DOMAIN;
  276. }
  277. /** {@inheritDoc} */
  278. public void setEnvironmentProperties(final String name, final String value)
  279. {
  280. checkImmutable();
  281. if (name != null && value != null) {
  282. if (PROPERTIES.hasProperty(name)) {
  283. PROPERTIES.setProperty(this, name, value);
  284. }
  285. }
  286. }
  287. /** {@inheritDoc} */
  288. public boolean hasEnvironmentProperty(final String name)
  289. {
  290. return PROPERTIES.hasProperty(name);
  291. }
  292. /**
  293. * Create an instance of this class initialized with properties from the input
  294. * stream. If the input stream is null, load properties from the default
  295. * properties file.
  296. *
  297. * @param is to load properties from
  298. *
  299. * @return <code>LdapPoolConfig</code> initialized ldap pool config
  300. */
  301. public static LdapPoolConfig createFromProperties(final InputStream is)
  302. {
  303. final LdapPoolConfig poolConfig = new LdapPoolConfig();
  304. LdapProperties properties = null;
  305. if (is != null) {
  306. properties = new LdapProperties(poolConfig, is);
  307. } else {
  308. properties = new LdapProperties(poolConfig);
  309. properties.useDefaultPropertiesFile();
  310. }
  311. properties.configure();
  312. return poolConfig;
  313. }
  314. }