Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Redis / Java / Lettuce - how to access context objects

$
0
0

I'm working with Redis pub/subscribe pattern, adding a Listener for the subscriber, from a class (myClass). From the listener thread I need to access the variables/objects of the thread that is setting up the listener in order to process the messages. Is it possible? or do I need to change the approach?

This portion of code shows the Listener setup and from where I need to access myClass variables.

import io.lettuce.core.*;import io.lettuce.core.api.StatefulRedisConnection;import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;import io.lettuce.core.pubsub.RedisPubSubListener;import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;public class myClass implements IStrategy {    private IEngine engine = IEngine.getEngine();    private int tagCounter = 0;    private double[] ma1 = new double[Instrument.values().length];    private IConsole console;    public void mySubscription(String channel){        RedisClient redisClient = RedisClient.create("redis://password@<myip>:6379/0");        StatefulRedisPubSubConnection<String, String> connection = redisClient.connectPubSub();        connection.addListener(new RedisPubSubListener<String, String>() {            @Override            public void message(String channel, String message) {                // I need to access myClass instance objects here            }.....

Disclaimer: From 1 to 10 my Java skill is 2.

Thanks


Viewing all articles
Browse latest Browse all 2204

Trending Articles