Skip to content

Commit

Permalink
RC3 check-in. This includes improvements to connection pooling and a …
Browse files Browse the repository at this point in the history
…few more functors to make writing configurations easier.
  • Loading branch information
jjg-123 committed Jun 18, 2018
1 parent da990f9 commit 335685d
Show file tree
Hide file tree
Showing 559 changed files with 4,241 additions and 9,872 deletions.
Original file line number Diff line number Diff line change
@@ -1,114 +1,128 @@
package edu.uiuc.ncsa.security.core.util;


import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

/**
* A pool of items, that is to say, a managed list that keeps valid items
* on it and can create or destroy them as needed. when pushing and popping off a stack.
* <p>Supremely useful with SQL connections.
* <p>Supremely useful with SQL connections. This does check for validity as a matter
* of course.
* <p>Created by Jeff Gaynor<br>
* on Mar 12, 2010 at 3:48:20 PM
*/
public abstract class Pool<T> {
int INFINITY = -1;
int MAX_SIZE = 1000;
public static final int INFINITE = -1;
int maxSize = INFINITE;
protected int inUse = 0;
List<T> stack = new LinkedList<T>();
static int inUse = 0;

/**
* Create a new one.
*
* @return
* Create a new, ready-to-use object for the pool
* @return the object
*/
public abstract T create();
public abstract T create() throws PoolException;

/**
* Destroy the given element.
*
* @param t
* Destroy an object that is no longer needed.
* @param object the object
*/
public abstract void destroy(T t);

public Pool(int maximumSize) {
this.MAX_SIZE = maximumSize;
}

public Pool() {
}

static int maxStackSize = 0;
public abstract void destroy(T object) throws PoolException;

protected synchronized int maxStackSize() {
if (maxStackSize < stack.size()) {
maxStackSize = stack.size();
}
return maxStackSize;
/**
* Is this item still good? If not it will be removed from the
* pool so a new one can be created. Default is to return true.
*/
public boolean isValid(T object) throws PoolException {
return true;
}

static int stopValue = 0;

public synchronized T pop() {
T t = null;
/**
* Pop an object off the stack if ther eis one, otherwise, create one.
* @return the object
*/
public synchronized T pop() throws PoolException {
try {
if (!stack.isEmpty()) {
t = stack.remove(0);
T item = stack.remove(0);
if(!isValid(item)){
return doCreate();
}
} catch (IndexOutOfBoundsException | NoSuchElementException ix) {
// do nothing.
inUse++;
return item;
} catch(IndexOutOfBoundsException x) { // pool is empty
return doCreate();
} catch(NoSuchElementException x) { // pool is empty
return doCreate();
}
if (t == null) {
t = realCreate();
}
inUse++;
return t;
}

protected synchronized T realCreate() {
if (MAX_SIZE == INFINITY || inUse < MAX_SIZE) {
T t = create();
maxStackSize();
return t;
}
throw new PoolException("Error: Maximum capacity of " + MAX_SIZE + " elements has been exceeded");
public synchronized T doCreate() throws PoolException {
// this is only called if stack.size()==0
if(maxSize == INFINITE || inUse < maxSize) {
T item = create();
inUse++;
return item;
} else {
throw new PoolException("pool at capacity: "+inUse+" item(s) checked out. " + stack.size() + " items in stack.");
}
}

public synchronized void realDestroy(T t) {
destroy(t);
inUse--;

/**
* Destroying an item reduces the number of in-use items.
* Do not call this on an item that hasn't been checked out.
* @param item the item
* @throws PoolException
*/
public synchronized void doDestroy(T item) throws PoolException {
destroy(item);
inUse--;
}

public synchronized void push(T t) {
if (MAX_SIZE <= stack.size()) {
realDestroy(t);
return;
}
if (stack.contains(t)) {
throw new PoolException("Error: This element has already been checked into the pool");
}
stack.add(0, t);
inUse--;

/**
* Set the maximum number of items.
* @param c
*/
public void setMaxSize(int c) {
maxSize = c;
}
/**
* Get the maximum number of items
* @return capacity
*/
public int getMaxSize() {
return maxSize;
}


/**
* Remove and destroy all elements on stack.
* Check an object into the pool. If the pool is at capacity,
* destroy the object.
* @param object the object
*/
public synchronized boolean clear() {
boolean ok = true;
while (!stack.isEmpty()) {
public synchronized void push(T object) throws PoolException {
if((maxSize != INFINITE && stack.size() >= maxSize) || !isValid(object)) {
doDestroy(object);
} else if(stack.contains(object)) {
throw new PoolException("can't check in object more than once: " + object);
} else {
stack.add(0, object);
inUse--;
}
}

public synchronized boolean destroyAll() {
boolean success = true;
Iterator<T> it = stack.iterator();
while(it.hasNext()) {
try {
destroy(pop());
inUse--;
} catch (Exception x) {
ok = false;
// rock on.
doDestroy(it.next());
} catch(PoolException x) {
success = false;
}
it.remove();
}
return ok;
return success;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public URI host(URI... x) {


protected Pool<HttpClient> clientPool = new Pool<HttpClient>() {

VerifyingHTTPClientFactory f;

public VerifyingHTTPClientFactory getF() {
Expand Down Expand Up @@ -180,7 +181,7 @@ public String getRawResponse(String requestString) {
ServiceClientHTTPException xx = new ServiceClientHTTPException("Error contacting server with code of " + response.getStatusLine().getStatusCode());
xx.setContent(x);
xx.setStatus(response.getStatusLine().getStatusCode());
clientPool.realDestroy(client);
clientPool.destroy(client);
throw xx;
}
clientPool.push(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_05) on Wed Nov 23 11:56:20 CST 2016 -->
<!-- Generated by javadoc (1.8.0_92) on Mon Jun 18 11:48:41 CDT 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Classes (NCSA security utilities for servlets 3.4-SNAPSHOT API)</title>
<meta name="date" content="2016-11-23">
<title>All Classes (NCSA security utilities for servlets 3.6-SNAPSHOT API)</title>
<meta name="date" content="2018-06-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand All @@ -28,6 +28,7 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="edu/uiuc/ncsa/security/servlet/ServiceClient.html" title="class in edu.uiuc.ncsa.security.servlet" target="classFrame">ServiceClient</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/ServiceClientHTTPException.html" title="class in edu.uiuc.ncsa.security.servlet" target="classFrame">ServiceClientHTTPException</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/ServletConfigUtil.html" title="class in edu.uiuc.ncsa.security.servlet" target="classFrame">ServletConfigUtil</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/ServletDebugUtil.html" title="class in edu.uiuc.ncsa.security.servlet" target="classFrame">ServletDebugUtil</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/mail/ServletMailUtil.html" title="class in edu.uiuc.ncsa.security.servlet.mail" target="classFrame">ServletMailUtil</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/mail/ServletMailUtilProvider.html" title="class in edu.uiuc.ncsa.security.servlet.mail" target="classFrame">ServletMailUtilProvider</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/TrivialUsernameTransformer.html" title="class in edu.uiuc.ncsa.security.servlet" target="classFrame">TrivialUsernameTransformer</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_05) on Wed Nov 23 11:56:20 CST 2016 -->
<!-- Generated by javadoc (1.8.0_92) on Mon Jun 18 11:48:41 CDT 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Classes (NCSA security utilities for servlets 3.4-SNAPSHOT API)</title>
<meta name="date" content="2016-11-23">
<title>All Classes (NCSA security utilities for servlets 3.6-SNAPSHOT API)</title>
<meta name="date" content="2018-06-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand All @@ -28,6 +28,7 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="edu/uiuc/ncsa/security/servlet/ServiceClient.html" title="class in edu.uiuc.ncsa.security.servlet">ServiceClient</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/ServiceClientHTTPException.html" title="class in edu.uiuc.ncsa.security.servlet">ServiceClientHTTPException</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/ServletConfigUtil.html" title="class in edu.uiuc.ncsa.security.servlet">ServletConfigUtil</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/ServletDebugUtil.html" title="class in edu.uiuc.ncsa.security.servlet">ServletDebugUtil</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/mail/ServletMailUtil.html" title="class in edu.uiuc.ncsa.security.servlet.mail">ServletMailUtil</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/mail/ServletMailUtilProvider.html" title="class in edu.uiuc.ncsa.security.servlet.mail">ServletMailUtilProvider</a></li>
<li><a href="edu/uiuc/ncsa/security/servlet/TrivialUsernameTransformer.html" title="class in edu.uiuc.ncsa.security.servlet">TrivialUsernameTransformer</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_05) on Wed Nov 23 11:56:20 CST 2016 -->
<!-- Generated by javadoc (1.8.0_92) on Mon Jun 18 11:48:41 CDT 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Constant Field Values (NCSA security utilities for servlets 3.4-SNAPSHOT API)</title>
<meta name="date" content="2016-11-23">
<title>Constant Field Values (NCSA security utilities for servlets 3.6-SNAPSHOT API)</title>
<meta name="date" content="2018-06-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Constant Field Values (NCSA security utilities for servlets 3.4-SNAPSHOT API)";
parent.document.title="Constant Field Values (NCSA security utilities for servlets 3.6-SNAPSHOT API)";
}
}
catch(err) {
Expand Down Expand Up @@ -150,6 +150,6 @@ <h2 title="edu.uiuc">edu.uiuc.*</h2>
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2016. All rights reserved.</small></p>
<p class="legalCopy"><small>Copyright &#169; 2018. All rights reserved.</small></p>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_05) on Wed Nov 23 11:56:20 CST 2016 -->
<!-- Generated by javadoc (1.8.0_92) on Mon Jun 18 11:48:41 CDT 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Deprecated List (NCSA security utilities for servlets 3.4-SNAPSHOT API)</title>
<meta name="date" content="2016-11-23">
<title>Deprecated List (NCSA security utilities for servlets 3.6-SNAPSHOT API)</title>
<meta name="date" content="2018-06-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Deprecated List (NCSA security utilities for servlets 3.4-SNAPSHOT API)";
parent.document.title="Deprecated List (NCSA security utilities for servlets 3.6-SNAPSHOT API)";
}
}
catch(err) {
Expand Down Expand Up @@ -121,6 +121,6 @@ <h2 title="Contents">Contents</h2>
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2016. All rights reserved.</small></p>
<p class="legalCopy"><small>Copyright &#169; 2018. All rights reserved.</small></p>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_05) on Wed Nov 23 11:56:20 CST 2016 -->
<!-- Generated by javadoc (1.8.0_92) on Mon Jun 18 11:48:41 CDT 2018 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>AbstractServlet (NCSA security utilities for servlets 3.4-SNAPSHOT API)</title>
<meta name="date" content="2016-11-23">
<title>AbstractServlet (NCSA security utilities for servlets 3.6-SNAPSHOT API)</title>
<meta name="date" content="2018-06-18">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="AbstractServlet (NCSA security utilities for servlets 3.4-SNAPSHOT API)";
parent.document.title="AbstractServlet (NCSA security utilities for servlets 3.6-SNAPSHOT API)";
}
}
catch(err) {
Expand Down Expand Up @@ -201,7 +201,7 @@ <h3>Method Summary</h3>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>protected static <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colFirst"><code>static <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../edu/uiuc/ncsa/security/servlet/AbstractServlet.html#CONST-java.lang.String-">CONST</a></span>(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</code>
<div class="block">Utility to get constants or code gets really wordy.</div>
</td>
Expand Down Expand Up @@ -728,7 +728,7 @@ <h4>resetState</h4>
<ul class="blockList">
<li class="blockList">
<h4>CONST</h4>
<pre>protected static&nbsp;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;CONST(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</pre>
<pre>public static&nbsp;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;CONST(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;key)</pre>
<div class="block">Utility to get constants or code gets really wordy.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
Expand Down Expand Up @@ -839,6 +839,6 @@ <h4>printAllParameters</h4>
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2016. All rights reserved.</small></p>
<p class="legalCopy"><small>Copyright &#169; 2018. All rights reserved.</small></p>
</body>
</html>
Loading

0 comments on commit 335685d

Please sign in to comment.