Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,37 @@ private class RedisReceiver[T: ClassTag](keys: Array[String],
redisConfig: RedisConfig,
streamType: Class[T])
extends Receiver[T](storageLevel) {

var jedisConnect: Jedis = null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be multiple different Jedis instances, one for each key. This variable refers only to the last one, so other connections will not be closed with onStop() method.


def onStart() {
val executorPool = ThreadUtils.newFixedThreadPool(keys.length, "BlockLists Streaming")
try {
/* start a executor for each interested List */
keys.foreach{ key =>
executorPool.submit(new MessageHandler(redisConfig.connectionForKey(key), key))
keys.foreach{ key =>{
jedisConnect = redisConfig.connectionForKey(key)
executorPool.submit(new MessageHandler(jedisConnect, key))
}
}
} finally {
executorPool.shutdown()
}
}

def onStop() {
/* quit the connect*/
if (jedisConnect != null) {
jedisConnect.quit()
jedisConnect = null
}
}

private class MessageHandler(conn: Jedis, key: String) extends Runnable {
def run() {
try {
while(!isStopped) {
val response = conn.blpop(2, key)
if (response == null) {
if (response == null || response.isEmpty) {

} else if (classTag[T] == classTag[String]) {
store(response.get(1).asInstanceOf[T])
Expand Down