Database Reference
In-Depth Information
public class
RedisSource
extends
AbstractSource
implements
Configurable, EventDrivenSource {
The Configurable interface has a single configure method, which is used to
obtain the Redis hostname, port, and subscription channel. In this case, all
of the configuration parameters have defaults:
String redisHost;
int
redisPort;
String redisChannel;
Jedis jedis;
public void
configure(Context context) {
redisHost = context.getString("redis-host",
"localhost");
redisPort = context.getInteger("redis-port",
6379);
redisChannel = context.getString("redis-channel",
"flume");
}
The
EventDrivenSource
does not actually require any methods be
implemented; it is only used to determine the type of source. Any threads
or even handlers are set up and broken down and are handled in the
start
and
stop
methods. In this case, most of the work is done in the
start
method:
@Override
public synchronized void
start() {
super
.start();
processor = getChannelProcessor();
First, the
ChannelProcessor
is obtained for future use. Recall that the
ChannelProcessor
decides which Channel will be used based on the
Event
. The
ChannelProcessor
is used by the subscription thread that is
established next:
JedisPool pool =
new
JedisPool(
new
JedisPoolConfig(),redisHost,redisPort);
jedis = pool.getResource();