I manage to make this to work (still ironing out some
synchronization details), but now I need to find a way to gracefully
shutdown the thread that issues the subscribe command.
I implemented a class that runs in its own thread:
public class SubscriptionHandler extends
JedisPubSub implements Runnable {
This class has a simple run method on which it subscribes to an
initial channel (see explanation below) as follows:
public void run(){
try{
connection.subscribe("control.channel");
} catch(JedisException e){
//Handle exceptions
}
}
To subscribe to additional channels, I added a method:
public void subscribeToChannel(String
channel){
super.subscribe(channel);
}
The control channel can be used to send control commands to this
thread (like, for example, to stop subscriptions), which are then
processed in the onMessage method
public void onMessage(String channel,
String message){
if(channel.equals("control.channel")){
if(command.equals("stop")){
unsubscribe(); //terminate all subscriptions
}
connection.quit();
}
}
My concrete question is, how can I make the subscribe in the run
method to return and allow the thread to finish?
I tried doing a quit on the connection, as shown above, but it
generates an exception:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to
[B
at
redis.clients.jedis.
Connection.getStatusCodeReply(Connection.java:162)
at redis.clients.jedis.Jedis.quit(Jedis.java:77)
Thanks in advance