use of redis.clients.jedis.JedisPool in project twitter-2-weibo by rjyo.
the class CommandServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
log.info("Web started.");
JedisPool pool = getPool(getServletContext());
DBHelper helper = DBHelperFactory.createHelper(pool);
// clear the queue
helper.clearQueue();
Scheduler scheduler = new Scheduler();
QueueTask task = new QueueTask();
task.setHelper(DBHelperFactory.createHelper(pool));
scheduler.schedule("*/2 * * * *", task);
scheduler.start();
log.info("Cron scheduler started.");
log.info("Worker started.");
// 1 Threads to handle the sync job
new Thread(new SyncWorkerRunnable(DBHelperFactory.createHelper(pool))).start();
}
use of redis.clients.jedis.JedisPool in project twitter-2-weibo by rjyo.
the class WorkerServlet method init.
@Override
public void init(final ServletConfig config) throws ServletException {
super.init(config);
log.info("Worker started.");
JedisPool pool = getPool(getServletContext());
// 3 Threads to handle the sync job
new Thread(new SyncWorkerRunnable(DBHelperFactory.createHelper(pool))).start();
}
use of redis.clients.jedis.JedisPool in project jstorm by alibaba.
the class RedisSinkBolt method prepare.
@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
this.collector = collector;
GenericObjectPoolConfig pconf = new GenericObjectPoolConfig();
pconf.setMaxWaitMillis(2000);
pconf.setMaxTotal(1000);
pconf.setTestOnBorrow(false);
pconf.setTestOnReturn(false);
pconf.setTestWhileIdle(true);
pconf.setMinEvictableIdleTimeMillis(120000);
pconf.setTimeBetweenEvictionRunsMillis(60000);
pconf.setNumTestsPerEvictionRun(-1);
pool = new JedisPool(pconf, redisHost, redisPort, timeout);
}
use of redis.clients.jedis.JedisPool in project dubbo by alibaba.
the class RedisRegistry method doUnregister.
@Override
public void doUnregister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
RpcException exception = null;
boolean success = false;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
Jedis jedis = jedisPool.getResource();
try {
jedis.hdel(key, value);
jedis.publish(key, Constants.UNREGISTER);
success = true;
if (!replicate) {
// 如果服务器端已同步数据,只需写入单台机器
break;
}
} finally {
jedisPool.returnResource(jedis);
}
} catch (Throwable t) {
exception = new RpcException("Failed to unregister service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
use of redis.clients.jedis.JedisPool in project cachecloud by sohutv.
the class JedisPoolTest method testCloseConnectionOnMakeObject.
@Test
public void testCloseConnectionOnMakeObject() {
JedisPoolConfig config = new JedisPoolConfig();
config.setTestOnBorrow(true);
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000, "wrong pass");
Jedis jedis = new Jedis("redis://:foobared@localhost:6379/");
int currentClientCount = getClientCount(jedis.clientList());
try {
pool.getResource();
fail("Should throw exception as password is incorrect.");
} catch (Exception e) {
assertEquals(currentClientCount, getClientCount(jedis.clientList()));
}
}
Aggregations