Moved JedisPool handling to RedisQueue class

Based on the review feedback comments

References #3 and #18
This commit is contained in:
Mahesh V Kelkar 2015-03-18 18:29:40 -04:00 committed by R. Tyler Croy
parent 9e8244ddb8
commit c3be62612b
24 changed files with 164 additions and 482 deletions

View File

@ -37,7 +37,7 @@ dependencies {
compile 'joda-time:joda-time:2.6+'
/* redis client */
compile 'redis.clients:jedis:2.6+'
compile 'com.fiftyonred:mock-jedis:0.4.0'
testCompile 'com.fiftyonred:mock-jedis:0.4.0'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'cglib:cglib-nodep:2.2.+'

View File

@ -17,7 +17,6 @@
<li><a href="com/github/lookout/whoas/HookRequest.html" title="class in com.github.lookout.whoas" target="classFrame">HookRequest</a></li>
<li><a href="com/github/lookout/whoas/InMemoryQueue.html" title="class in com.github.lookout.whoas" target="classFrame">InMemoryQueue</a></li>
<li><a href="com/github/lookout/whoas/Publisher.html" title="class in com.github.lookout.whoas" target="classFrame">Publisher</a></li>
<li><a href="com/github/lookout/whoas/RedisClientFactory.html" title="class in com.github.lookout.whoas" target="classFrame">RedisClientFactory</a></li>
<li><a href="com/github/lookout/whoas/RedisQueue.html" title="class in com.github.lookout.whoas" target="classFrame">RedisQueue</a></li>
<li><a href="com/github/lookout/whoas/SequentialHookRunner.html" title="class in com.github.lookout.whoas" target="classFrame">SequentialHookRunner</a></li>
<li><a href="com/github/lookout/whoas/WhoasConfiguration.html" title="interface in com.github.lookout.whoas" target="classFrame"><I>WhoasConfiguration</I></a></li>

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>AbstractHookQueue (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>AbstractHookRunner (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>HookRequest (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>InMemoryQueue (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>Publisher (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -1,283 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- **************************************************************** -->
<!-- * PLEASE KEEP COMPLICATED EXPRESSIONS OUT OF THESE TEMPLATES, * -->
<!-- * i.e. only iterate & print data where possible. Thanks, Jez. * -->
<!-- **************************************************************** -->
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<title>RedisClientFactory (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../../../groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="../../../../groovy.ico" type="image/x-icon" rel="icon">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<body class="center">
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="RedisClientFactory (whoas 0.1.2 API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<div>
<ul class="navList">
<li><a href="../../../../index.html?com/github/lookout/whoas/RedisClientFactory" target="_top">Frames</a></li>
<li><a href="RedisClientFactory.html" target="_top">No Frames</a></li>
</ul>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
Nested&nbsp;&nbsp;&nbsp;Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor&nbsp;&nbsp;&nbsp;<li><a href="#method_summary">Method</a></li>&nbsp;&nbsp;&nbsp;
</ul>
<ul class="subNavList">
<li>&nbsp;|&nbsp;Detail:&nbsp;</li>
Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor&nbsp;&nbsp;&nbsp;<li><a href="#method_detail">Method</a></li>&nbsp;&nbsp;&nbsp;
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">Package: <strong>com.github.lookout.whoas</strong></div>
<h2 title="[Groovy] Class RedisClientFactory" class="title">[Groovy] Class RedisClientFactory</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><ul class="inheritance"></ul></li><li>com.github.lookout.whoas.RedisClientFactory
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== NESTED CLASS SUMMARY =========== -->
<!-- =========== ENUM CONSTANT SUMMARY =========== -->
<!-- =========== FIELD SUMMARY =========== -->
<!-- =========== PROPERTY SUMMARY =========== -->
<!-- =========== ELEMENT SUMMARY =========== -->
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary"><!-- --></a>
<h3>Methods Summary</h3>
<ul class="blockList">
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Methods Summary table">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Type</th>
<th class="colLast" scope="col">Name and description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static&nbsp;<a href='../../../../com/github/lookout/whoas/RedisClientFactory.html'>RedisClientFactory</a></strong></code></td>
<td class="colLast"><code><strong><a href="#getInstance()">getInstance</a></strong>()</code><br></td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>redis.clients.jedis.Jedis</strong></code></td>
<td class="colLast"><code><strong><a href="#getJedis()">getJedis</a></strong>()</code><br></td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</strong></code></td>
<td class="colLast"><code><strong><a href="#returnJedis(redis.clients.jedis.Jedis)">returnJedis</a></strong>(redis.clients.jedis.Jedis jedis)</code><br></td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</strong></code></td>
<td class="colLast"><code><strong><a href="#start(java.lang.String, java.lang.Integer)">start</a></strong>(java.lang.String hostname, java.lang.Integer port)</code><br></td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</strong></code></td>
<td class="colLast"><code><strong><a href="#stop()">stop</a></strong>()</code><br></td>
</tr>
</table>
</ul>
</li>
<li class="blockList"><a name="method_summary"><!-- --></a>
<h3>Inherited Methods Summary</h3>
<ul class="blockList">
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Inherited Methods Summary table">
<caption><span>Inherited Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Methods inherited from class</th>
<th class="colLast" scope="col">Name</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>class java.lang.Object</strong></code></td>
<td class="colLast"><code>java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()</code></td>
</tr>
</table>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- =========== METHOD DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="getInstance()"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>static&nbsp;final&nbsp;<a href='../../../../com/github/lookout/whoas/RedisClientFactory.html'>RedisClientFactory</a> <strong>getInstance</strong>()</h4>
<p></p>
</li>
</ul>
<a name="getJedis()"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>redis.clients.jedis.Jedis <strong>getJedis</strong>()</h4>
<p></p>
</li>
</ul>
<a name="returnJedis(redis.clients.jedis.Jedis)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>void <strong>returnJedis</strong>(redis.clients.jedis.Jedis jedis)</h4>
<p></p>
</li>
</ul>
<a name="start(java.lang.String, java.lang.Integer)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>void <strong>start</strong>(java.lang.String hostname, java.lang.Integer port)</h4>
<p></p>
</li>
</ul>
<a name="stop()"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>void <strong>stop</strong>()</h4>
<p></p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<div>
<ul class="navList">
<li><a href="../../../../index.html?com/github/lookout/whoas/RedisClientFactory" target="_top">Frames</a></li>
<li><a href="RedisClientFactory.html" target="_top">No Frames</a></li>
</ul>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
Nested&nbsp;&nbsp;&nbsp;Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor&nbsp;&nbsp;&nbsp;<li><a href="#method_summary">Method</a></li>&nbsp;&nbsp;&nbsp;
</ul>
<ul class="subNavList">
<li>&nbsp;|&nbsp;Detail:&nbsp;</li>
Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor&nbsp;&nbsp;&nbsp;<li><a href="#method_detail">Method</a></li>&nbsp;&nbsp;&nbsp;
</ul>
</div>
<p>Groovy Documentation</p>
<a name="skip-navbar_bottom">
<!-- -->
</a>
</div>
</div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>RedisQueue (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
@ -180,17 +180,22 @@ if (location.href.indexOf('is-external=true') == -1) {
<tr class="altColor">
<td class="colFirst"><code>java.lang.Boolean</strong></code></td>
<td class="colLast"><code><strong><a href="#push(com.github.lookout.whoas.HookRequest)">push</a></strong>(<a href='../../../../com/github/lookout/whoas/HookRequest.html'>HookRequest</a> request)</code><br>Attempt to insert the request into the queue</td>
<td class="colLast"><code><strong><a href="#push(com.github.lookout.whoas.HookRequest)">push</a></strong>(<a href='../../../../com/github/lookout/whoas/HookRequest.html'>HookRequest</a> request)</code><br>The blpop returns list of strings (key and value)</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</strong></code></td>
<td class="colLast"><code><strong><a href="#start()">start</a></strong>()</code><br>Setup the Redis client factory</td>
<td class="colLast"><code><strong><a href="#start()">start</a></strong>()</code><br>Setup the Redis client</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</strong></code></td>
<td class="colLast"><code><strong><a href="#stop()">stop</a></strong>()</code><br>Stop the Redis client factory</td>
<td class="colLast"><code><strong><a href="#stop()">stop</a></strong>()</code><br>Setup jedis pool</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.Object</strong></code></td>
<td class="colLast"><code><strong><a href="#withRedis(groovy.lang.Closure)">withRedis</a></strong>(groovy.lang.Closure closure)</code><br></td>
</tr>
</table>
@ -301,11 +306,8 @@ if (location.href.indexOf('is-external=true') == -1) {
<ul class="blockListLast">
<li class="blockList">
<h4>java.lang.Boolean <strong>push</strong>(<a href='../../../../com/github/lookout/whoas/HookRequest.html'>HookRequest</a> request)</h4>
<p> Attempt to insert the request into the queue
If the request cannot be inserted, this method will return false,
otherwise true.
</p>
<p> The blpop returns list of strings (key and value)
</p>
</li>
</ul>
@ -314,7 +316,7 @@ if (location.href.indexOf('is-external=true') == -1) {
<li class="blockList">
<h4>@java.lang.Override
void <strong>start</strong>()</h4>
<p> Setup the Redis client factory
<p> Setup the Redis client
</p>
</li>
</ul>
@ -324,8 +326,21 @@ void <strong>start</strong>()</h4>
<li class="blockList">
<h4>@java.lang.Override
void <strong>stop</strong>()</h4>
<p> Stop the Redis client factory
</p>
<p> Setup jedis pool
A single jedis instance is NOT thread-safe. JedisPool maintains a thread-safe
pool of network connections. The pool will allow us to maintain a pool of
multiple jedis instances and use them reliably and efficiently across different
threads
</p>
</li>
</ul>
<a name="withRedis(groovy.lang.Closure)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>java.lang.Object <strong>withRedis</strong>(groovy.lang.Closure closure)</h4>
<p></p>
</li>
</ul>

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>SequentialHookRunner (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>WhoasConfiguration (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>WhoasFactory (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
@ -249,8 +249,8 @@ java.lang.String <strong>runnerType</strong></h4>
ClassNotFoundException - if the class is not found
IllegalAccessException - if the class or its nullary constructor is not accessible.
InstantiationException - if this Class represents an abstract class, an interface,
an array class, a primitive type, or void;
or if the class has no nullary constructor;
an array class, a primitive type, or void
or if the class has no nullary constructor
or if the instantiation fails for some other reason.
<DL><DT><B>Returns:</B></DT><DD>allocated queue</DD></DL></p>
</li>
@ -266,8 +266,8 @@ java.lang.String <strong>runnerType</strong></h4>
ClassNotFoundException - if the class is not found
IllegalAccessException - if the class or its nullary constructor is not accessible.
InstantiationException - if this Class represents an abstract class, an interface,
an array class, a primitive type, or void;
or if the class has no nullary constructor;
an array class, a primitive type, or void
or if the class has no nullary constructor
or if the instantiation fails for some other reason. <DL><DT><B>Parameters:</B></DT><DD><code>hookQueue</code> - queue to associate with allocated runner</DD></DL><DL><DT><B>Returns:</B></DT><DD></DD></DL></p>
</li>
</ul>

View File

@ -6,7 +6,7 @@
<html>
<head>
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 12:51:40 EDT 2015 -->
<!-- Generated by groovydoc (2.3.9) on Wed Mar 18 18:29:27 EDT 2015 -->
<title>WhoasQueueConfig (whoas 0.1.2 API)</title>
<meta name="date" content="2015-03-18">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
@ -116,11 +116,16 @@ if (location.href.indexOf('is-external=true') == -1) {
</tr>
<tr class="rowColor">
<td class="colFirst"><code><strong>java.lang.String</strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#key"></a>key</code><br>key to idenitfy the distributed queue</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code><strong>java.lang.Integer</strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#port"></a>port</code><br>Port number of the distributed queue server</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code><strong>java.lang.String</strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#type"></a>type</code><br>Type of queue (full class name) to create in whoas</td>
</tr>
@ -187,6 +192,18 @@ java.lang.String <strong>hostname</strong></h4>
<p> Hostname of the distributed queue server
Default hostname is localhost
</p>
</li>
</ul>
<a name="key"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>@com.fasterxml.jackson.annotation.JsonProperty
java.lang.String <strong>key</strong></h4>
<p> key to idenitfy the distributed queue
Default key is "queue"
</p>
</li>
</ul>

View File

@ -31,7 +31,7 @@
<div class="indexContainer">
<h2>Classes</h2>
<ul>
<li><a href="AbstractHookQueue.html" title="class in com.github.lookout.whoas" target="classFrame">AbstractHookQueue</a></li><li><a href="AbstractHookRunner.html" title="class in com.github.lookout.whoas" target="classFrame">AbstractHookRunner</a></li><li><a href="HookRequest.html" title="class in com.github.lookout.whoas" target="classFrame">HookRequest</a></li><li><a href="InMemoryQueue.html" title="class in com.github.lookout.whoas" target="classFrame">InMemoryQueue</a></li><li><a href="Publisher.html" title="class in com.github.lookout.whoas" target="classFrame">Publisher</a></li><li><a href="RedisClientFactory.html" title="class in com.github.lookout.whoas" target="classFrame">RedisClientFactory</a></li><li><a href="RedisQueue.html" title="class in com.github.lookout.whoas" target="classFrame">RedisQueue</a></li><li><a href="SequentialHookRunner.html" title="class in com.github.lookout.whoas" target="classFrame">SequentialHookRunner</a></li><li><a href="WhoasFactory.html" title="class in com.github.lookout.whoas" target="classFrame">WhoasFactory</a></li><li><a href="WhoasQueueConfig.html" title="class in com.github.lookout.whoas" target="classFrame">WhoasQueueConfig</a></li>
<li><a href="AbstractHookQueue.html" title="class in com.github.lookout.whoas" target="classFrame">AbstractHookQueue</a></li><li><a href="AbstractHookRunner.html" title="class in com.github.lookout.whoas" target="classFrame">AbstractHookRunner</a></li><li><a href="HookRequest.html" title="class in com.github.lookout.whoas" target="classFrame">HookRequest</a></li><li><a href="InMemoryQueue.html" title="class in com.github.lookout.whoas" target="classFrame">InMemoryQueue</a></li><li><a href="Publisher.html" title="class in com.github.lookout.whoas" target="classFrame">Publisher</a></li><li><a href="RedisQueue.html" title="class in com.github.lookout.whoas" target="classFrame">RedisQueue</a></li><li><a href="SequentialHookRunner.html" title="class in com.github.lookout.whoas" target="classFrame">SequentialHookRunner</a></li><li><a href="WhoasFactory.html" title="class in com.github.lookout.whoas" target="classFrame">WhoasFactory</a></li><li><a href="WhoasQueueConfig.html" title="class in com.github.lookout.whoas" target="classFrame">WhoasQueueConfig</a></li>
</ul>
</div>

View File

@ -138,14 +138,6 @@ function windowTitle()
<td>Publisher is the class responsible for implementing the *actual* HTTP
request logic for Whoas</td>
</tr>
<tr class="altColor">
<td class="colOne">
<strong><a href="RedisClientFactory.html" title="class in com/github/lookout/whoas">
RedisClientFactory
</a></strong>
</td>
<td></td>
</tr>
<tr class="altColor">
<td class="colOne">
<strong><a href="RedisQueue.html" title="class in com/github/lookout/whoas">

View File

@ -160,10 +160,6 @@ if (location.href.indexOf('is-external=true') == -1) {
<h2 class="title">G</h2>
<dl>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisClientFactory.html#getInstance()" title="Method in RedisClientFactory">getInstance()</a></span> - Method in <a href="com/github/lookout/whoas/RedisClientFactory.html">RedisClientFactory</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisClientFactory.html#getJedis()" title="Method in RedisClientFactory">getJedis()</a></span> - Method in <a href="com/github/lookout/whoas/RedisClientFactory.html">RedisClientFactory</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookRunner.html#getPublisher()" title="Method in AbstractHookRunner">getPublisher()</a></span> - Method in <a href="com/github/lookout/whoas/AbstractHookRunner.html">AbstractHookRunner</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookQueue.html#getSize()" title="Method in AbstractHookQueue">getSize()</a></span> - Method in <a href="com/github/lookout/whoas/AbstractHookQueue.html">AbstractHookQueue</a>
@ -272,7 +268,7 @@ if (location.href.indexOf('is-external=true') == -1) {
<dt><span class="strong"><a href="com/github/lookout/whoas/InMemoryQueue.html#push(com.github.lookout.whoas.HookRequest)" title="Method in InMemoryQueue">push(HookRequest)</a></span> - Method in <a href="com/github/lookout/whoas/InMemoryQueue.html">InMemoryQueue</a>
</dt><dd> <div class="block">Attempt to insert the request into the queue</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html#push(com.github.lookout.whoas.HookRequest)" title="Method in RedisQueue">push(HookRequest)</a></span> - Method in <a href="com/github/lookout/whoas/RedisQueue.html">RedisQueue</a>
</dt><dd> <div class="block">Attempt to insert the request into the queue</div></dd>
</dt><dd> <div class="block">The blpop returns list of strings (key and value)</div></dd>
</dl>
@ -289,14 +285,10 @@ if (location.href.indexOf('is-external=true') == -1) {
<h2 class="title">R</h2>
<dl>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisClientFactory.html" title="Class in com.github.lookout.whoas">RedisClientFactory</a></span> - Class in <a href="./com/github/lookout/whoas/package-summary.html">com.github.lookout.whoas</a>
</dt><dd><div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html" title="Class in com.github.lookout.whoas">RedisQueue</a></span> - Class in <a href="./com/github/lookout/whoas/package-summary.html">com.github.lookout.whoas</a>
</dt><dd><div class="block">A redis queue that offers distributed and persistent queue</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html#RedisQueue()" title="Constructor in RedisQueue">RedisQueue()</a></span> - Constructor in <a href="com/github/lookout/whoas/RedisQueue.html">RedisQueue</a>
</dt><dd> <div class="block">Default constructor</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisClientFactory.html#returnJedis(redis.clients.jedis.Jedis)" title="Method in RedisClientFactory">returnJedis(Jedis)</a></span> - Method in <a href="com/github/lookout/whoas/RedisClientFactory.html">RedisClientFactory</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookRunner.html#run()" title="Method in AbstractHookRunner">run()</a></span> - Method in <a href="com/github/lookout/whoas/AbstractHookRunner.html">AbstractHookRunner</a>
</dt><dd> <div class="block">Block forever and run the runner's runloop.</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/SequentialHookRunner.html#run()" title="Method in SequentialHookRunner">run()</a></span> - Method in <a href="com/github/lookout/whoas/SequentialHookRunner.html">SequentialHookRunner</a>
@ -315,20 +307,16 @@ if (location.href.indexOf('is-external=true') == -1) {
</dt><dd> <div class="block">Determine whether this response meets our criteria for retry</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookQueue.html#start()" title="Method in AbstractHookQueue">start()</a></span> - Method in <a href="com/github/lookout/whoas/AbstractHookQueue.html">AbstractHookQueue</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisClientFactory.html#start(java.lang.String, java.lang.Integer)" title="Method in RedisClientFactory">start(String, Integer)</a></span> - Method in <a href="com/github/lookout/whoas/RedisClientFactory.html">RedisClientFactory</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html#start()" title="Method in RedisQueue">start()</a></span> - Method in <a href="com/github/lookout/whoas/RedisQueue.html">RedisQueue</a>
</dt><dd> <div class="block">Setup the Redis client factory</div></dd>
</dt><dd> <div class="block">Setup the Redis client</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookQueue.html#started" title="Field in AbstractHookQueue">started</a></span> - Field in <a href="com/github/lookout/whoas/AbstractHookQueue.html">AbstractHookQueue</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookQueue.html#stop()" title="Method in AbstractHookQueue">stop()</a></span> - Method in <a href="com/github/lookout/whoas/AbstractHookQueue.html">AbstractHookQueue</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/AbstractHookRunner.html#stop()" title="Method in AbstractHookRunner">stop()</a></span> - Method in <a href="com/github/lookout/whoas/AbstractHookRunner.html">AbstractHookRunner</a>
</dt><dd> <div class="block">Tell the runloop to stop</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisClientFactory.html#stop()" title="Method in RedisClientFactory">stop()</a></span> - Method in <a href="com/github/lookout/whoas/RedisClientFactory.html">RedisClientFactory</a>
</dt><dd> <div class="block"></div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html#stop()" title="Method in RedisQueue">stop()</a></span> - Method in <a href="com/github/lookout/whoas/RedisQueue.html">RedisQueue</a>
</dt><dd> <div class="block">Stop the Redis client factory</div></dd>
</dt><dd> <div class="block">Setup jedis pool</div></dd>
</dl>
@ -366,6 +354,8 @@ if (location.href.indexOf('is-external=true') == -1) {
like sequential.</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/WhoasQueueConfig.html" title="Class in com.github.lookout.whoas">WhoasQueueConfig</a></span> - Class in <a href="./com/github/lookout/whoas/package-summary.html">com.github.lookout.whoas</a>
</dt><dd><div class="block">Whoas Queue Configuration</div></dd>
<dt><span class="strong"><a href="com/github/lookout/whoas/RedisQueue.html#withRedis(groovy.lang.Closure)" title="Method in RedisQueue">withRedis(Closure)</a></span> - Method in <a href="com/github/lookout/whoas/RedisQueue.html">RedisQueue</a>
</dt><dd> <div class="block"></div></dd>
</dl>

View File

@ -6,9 +6,6 @@ import org.joda.time.DateTime
class HookRequest {
@JsonProperty
private Long id
@JsonProperty
private Long retries

View File

@ -1,62 +0,0 @@
package com.github.lookout.whoas
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class RedisClientFactory {
private static final RedisClientFactory instance = new RedisClientFactory();
private static JedisPool pool;
private RedisClientFactory() {}
public final static RedisClientFactory getInstance() {
return instance;
}
public void start(String hostname, Integer port) {
/* Set JedisPoolConfig */
JedisPoolConfig poolConfig = new JedisPoolConfig();
/* Set max active connections to Redis instance */
poolConfig.setMaxTotal(10);
/* Tests whether connection is dead when connection
* retrieval method is called
*/
poolConfig.setTestOnBorrow(true);
/* Tests whether connection is dead when returning a connection
* to the pool
* */
poolConfig.setTestOnReturn(true);
/* Number of connections to Redis that just sit there and do
* nothing
* */
poolConfig.setMaxIdle(5);
/* Minimum number of idle connections to Redis
* These can be seen as always open and ready to serve
* */
poolConfig.setMinIdle(1);
/* Tests whether connections are dead during idle periods */
poolConfig.setTestWhileIdle(true);
/* Maximum number of connections to test in each idle check */
poolConfig.setNumTestsPerEvictionRun(10);
/* Idle connection checking period */
poolConfig.setTimeBetweenEvictionRunsMillis(60000);
/* Create the jedisPool */
pool = new JedisPool(poolConfig, hostname, port);
}
public void stop() {
pool.destroy();
}
public Jedis getJedis() {
return pool.getResource();
}
public void returnJedis(Jedis jedis) {
jedis.close()
}
}

View File

@ -1,34 +1,35 @@
package com.github.lookout.whoas
import com.fasterxml.jackson.databind.ObjectMapper
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Jedis
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
/**
* A redis queue that offers distributed and persistent queue
*/
class RedisQueue extends AbstractHookQueue {
private final RedisClientFactory redisClientFactory
private static nextId = 0
private String hostname
private Integer port
private WhoasQueueConfig queueConfig
private JedisPool pool = null
private static Integer maxActiveConnections = 10
private static Integer maxIdleConnections = 5
private static Integer minIdleConnections = 1
/**
* Create the RedisQueue with valid config
*/
RedisQueue(WhoasQueueConfig queueConfig) {
redisClientFactory = RedisClientFactory.getInstance()
this.hostname = queueConfig.hostname
this.port = queueConfig.port
this.queueConfig = queueConfig
}
/**
* Default constructor
*/
RedisQueue() {
redisClientFactory = RedisClientFactory.getInstance()
this.hostname = "localhost"
this.port = 6379
queueConfig = new WhoasQueueConfig()
}
/**
* Return the number of elements in the queue
*/
@ -36,36 +37,56 @@ class RedisQueue extends AbstractHookQueue {
if (!this.started) {
throw new Exception("Queue must be started before this operation is invoked")
}
Jedis redisclient = null
Long queueSize = 0
try {
redisclient = redisClientFactory.getJedis()
queueSize = redisclient.llen("queue")
} catch (all) {
} finally {
if (redisclient != null) {
redisClientFactory.returnJedis(redisclient)
}
return withRedis() { Jedis redisClient ->
return redisClient.llen(this.queueConfig.key)
}
return queueSize
}
/**
* Setup the Redis client factory
* Setup the Redis client
*/
@Override
void start() {
super.start()
redisClientFactory.start(this.hostname, this.port)
/**
* Setup jedis pool
*
* A single jedis instance is NOT thread-safe. JedisPool maintains a thread-safe
* pool of network connections. The pool will allow us to maintain a pool of
* multiple jedis instances and use them reliably and efficiently across different
* threads
*/
JedisPoolConfig poolConfig = new JedisPoolConfig()
poolConfig.setMaxTotal(maxActiveConnections)
poolConfig.setTestOnBorrow(true)
poolConfig.setTestOnReturn(true)
poolConfig.setMaxIdle(maxIdleConnections)
poolConfig.setMinIdle(minIdleConnections)
poolConfig.setTestWhileIdle(true)
/* Create the pool */
pool = new JedisPool(poolConfig, this.queueConfig.hostname, this.queueConfig.port)
}
/**
* Stop the Redis client factory
* Stop the Redis client
*/
@Override
void stop() {
super.stop()
redisClientFactory.stop()
pool.destroy()
pool = null
}
Object withRedis(Closure closure) {
Jedis redisClient = pool.resource
try {
return closure.call(redisClient)
}
finally {
redisClient.close()
}
}
/**
@ -84,26 +105,24 @@ class RedisQueue extends AbstractHookQueue {
throw new Exception("Queue must be started before this operation is invoked")
}
List<String> messages = null
Jedis redisclient = null
try {
redisclient = redisClientFactory.getJedis()
messages = redisclient.blpop(0, "queue");
withRedis() { Jedis redisClient ->
/* Decode message */
/**
* The blpop returns list of strings (key and value)
*/
List<String> messages = redisClient.blpop(0, this.queueConfig.key)
/* If valid, decode message */
if (messages) {
ObjectMapper mapper = new ObjectMapper()
HookRequest request = mapper.readValue(messages.get(1), HookRequest.class)
action.call(request)
}
} catch (all) {
/* Put this back on the front of the queue */
if (messages) {
redisclient.lpush("queue", messages.get(1))
}
} finally {
if (redisclient != null) {
redisClientFactory.returnJedis(redisclient)
try {
action.call(request)
} catch (Exception ex) {
/* Put this back on the front of the queue */
redisClient.lpush(this.queueConfig.key, messages.get(1))
throw ex
}
}
}
}
@ -119,20 +138,10 @@ class RedisQueue extends AbstractHookQueue {
throw new Exception("Queue must be started before this operation is invoked")
}
request.id = ++nextId
ObjectMapper mapper = new ObjectMapper()
String jsonPayload = mapper.writeValueAsString(request)
Jedis redisclient = null
Integer ret = 0
try {
redisclient = redisClientFactory.getJedis()
ret = redisclient.rpush("queue", jsonPayload)
} catch (Exception e) {
} finally {
if (redisclient != null) {
redisClientFactory.returnJedis(redisclient)
}
return withRedis() { Jedis redisClient ->
return redisClient.rpush(this.queueConfig.key, jsonPayload) != 0
}
return ret == 1;
}
}

View File

@ -9,5 +9,5 @@ import io.dropwizard.Configuration
* @param < T > Configuration class that extends dropwizard configuration
*/
public interface WhoasConfiguration<T extends Configuration> {
WhoasFactory getWhoasFactory(T configuration);
WhoasFactory getWhoasFactory(T configuration)
}

View File

@ -1,7 +1,7 @@
package com.github.lookout.whoas
import com.fasterxml.jackson.annotation.JsonProperty
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.NotEmpty
/**
* This factory will allow clients of whoas to build
@ -31,8 +31,8 @@ public class WhoasFactory {
* ClassNotFoundException - if the class is not found
* IllegalAccessException - if the class or its nullary constructor is not accessible.
* InstantiationException - if this Class represents an abstract class, an interface,
* an array class, a primitive type, or void;
* or if the class has no nullary constructor;
* an array class, a primitive type, or void
* or if the class has no nullary constructor
* or if the instantiation fails for some other reason.
* @return allocated queue
*/
@ -48,8 +48,8 @@ public class WhoasFactory {
* ClassNotFoundException - if the class is not found
* IllegalAccessException - if the class or its nullary constructor is not accessible.
* InstantiationException - if this Class represents an abstract class, an interface,
* an array class, a primitive type, or void;
* or if the class has no nullary constructor;
* an array class, a primitive type, or void
* or if the class has no nullary constructor
* or if the instantiation fails for some other reason.
* @param hookQueue queue to associate with allocated runner
* @return

View File

@ -15,6 +15,14 @@ public class WhoasQueueConfig {
@JsonProperty
String type = "com.github.lookout.whoas.InMemoryQueue"
/**
* key to idenitfy the distributed queue
*
* Default key is "queue"
*/
@JsonProperty
String key = "queue"
/**
* Hostname of the distributed queue server
*

View File

@ -1,7 +1,7 @@
package com.github.lookout.whoas
import com.fiftyonred.mock_jedis.MockJedis
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Jedis
import spock.lang.*
@ -21,11 +21,11 @@ class RedisQueueSpec extends Specification {
def "getSize() should return 0 by default"() {
given:
RedisQueue queue = new RedisQueue()
//Jedis redisClient = new MockJedis("test");
//queue.redisClientFactory.metaClass.getJedis = {redisClient}
Jedis redisClient = new MockJedis("test")
when:
queue.start()
queue.pool.metaClass.getResource = {redisClient}
then:
queue.getSize() == 0
@ -67,12 +67,12 @@ class RedisQueueSpec extends Specification {
def "push() should put onto the internal queue"() {
given:
RedisQueue queue = new RedisQueue()
Jedis redisClient = new MockJedis("test");
queue.redisClientFactory.metaClass.getJedis = {redisClient}
Jedis redisClient = new MockJedis("test")
redisClient.metaClass.rpush = {String key, String payload -> redisClient.lpush(key, payload)}
when:
queue.start()
queue.pool.metaClass.getResource = {redisClient}
queue.push(new HookRequest())
queue.push(new HookRequest())
@ -83,13 +83,13 @@ class RedisQueueSpec extends Specification {
def "pop() after push should receive a request"() {
given:
RedisQueue queue = new RedisQueue()
Jedis redisClient = new MockJedis("test");
queue.redisClientFactory.metaClass.getJedis = {redisClient}
Jedis redisClient = new MockJedis("test")
redisClient.metaClass.rpush = {String key, String payload -> redisClient.lpush(key, payload)}
redisClient.metaClass.blpop = {Integer timeout, String key -> [key, redisClient.lpop(key)]}
when:
queue.start()
queue.pool.metaClass.getResource = {redisClient}
HookRequest test = new HookRequest()
queue.push(test)
@ -102,49 +102,48 @@ class RedisQueueSpec extends Specification {
def "push() on rpush exception should return false"() {
given:
RedisQueue queue = new RedisQueue()
Jedis redisClient = new MockJedis("test");
queue.redisClientFactory.metaClass.getJedis = {redisClient}
Jedis redisClient = new MockJedis("test")
redisClient.metaClass.rpush = {String key, String payload -> throw new Exception("Test Exception")}
when:
queue.start()
queue.pool.metaClass.getResource = {redisClient}
queue.push(new HookRequest())
then:
queue.push(new HookRequest()) == false
thrown Exception
}
def "pop() on blpop exception simple return, nothing to requeue "() {
given:
RedisQueue queue = new RedisQueue()
Jedis redisClient = new MockJedis("test");
queue.redisClientFactory.metaClass.getJedis = {redisClient}
Jedis redisClient = new MockJedis("test")
redisClient.metaClass.blpop = {Integer timeout, String key -> throw new Exception("Test Exception")}
when:
queue.start()
queue.pool.metaClass.getResource = {redisClient}
queue.pop() { }
then:
queue.getSize() == 0
thrown Exception
}
def "pop() on exception while executing closure should requeue"() {
given:
RedisQueue queue = new RedisQueue()
Jedis redisClient = new MockJedis("test");
queue.redisClientFactory.metaClass.getJedis = {redisClient}
Jedis redisClient = new MockJedis("test")
redisClient.metaClass.rpush = {String key, String payload -> redisClient.lpush(key, payload)}
redisClient.metaClass.blpop = {Integer timeout, String key -> [key, redisClient.lpop(key)]}
redisClient.metaClass.blpop = {Integer timeout, String key -> }
when:
queue.start()
queue.pool.metaClass.getResource = {redisClient}
queue.push(new HookRequest())
queue.pop() { throw new Exception("Test Exception") }
then:
thrown Exception
queue.getSize() == 1
}
}

View File

@ -72,8 +72,9 @@ class WhoasFactorySpec extends Specification {
expect:
redisQueue instanceof RedisQueue
redisQueue.hostname == "localhost"
redisQueue.port == 6379
redisQueue.queueConfig.hostname == "localhost"
redisQueue.queueConfig.port == 6379
redisQueue.queueConfig.key == "queue"
}
def "Create RedisQueue with non-default hostname and port config"() {
@ -82,11 +83,11 @@ class WhoasFactorySpec extends Specification {
whoasFactory.queueConfig.type = "com.github.lookout.whoas.RedisQueue"
whoasFactory.queueConfig.hostname = "redis.lookout.com"
whoasFactory.queueConfig.port = 1234
whoasFactory.queueConfig.key = "foo"
RedisQueue redisQueue = whoasFactory.buildQueue()
expect:
redisQueue instanceof RedisQueue
redisQueue.hostname == whoasFactory.queueConfig.hostname
redisQueue.port == whoasFactory.queueConfig.port
redisQueue.queueConfig == whoasFactory.queueConfig
}
}