本文整理汇总了Java中redis.clients.util.Pool类的典型用法代码示例。如果您正苦于以下问题:Java Pool类的具体用法?Java Pool怎么用?Java Pool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pool类属于redis.clients.util包,在下文中一共展示了Pool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import redis.clients.util.Pool; //导入依赖的package包/类
@Override
public GelfSender create(GelfSenderConfiguration configuration) throws IOException {
String graylogHost = configuration.getHost();
URI hostUri = URI.create(graylogHost);
int port = hostUri.getPort();
if (port <= 0) {
port = configuration.getPort();
}
if (port <= 0) {
port = Protocol.DEFAULT_PORT;
}
if (hostUri.getFragment() == null || hostUri.getFragment().trim().equals("")) {
throw new IllegalArgumentException("Redis URI must specify fragment");
}
if (hostUri.getHost() == null) {
throw new IllegalArgumentException("Redis URI must specify host");
}
Pool<Jedis> pool = RedisSenderPoolProvider.getJedisPool(hostUri, port);
return new GelfREDISSender(pool, hostUri.getFragment(), configuration.getErrorReporter());
}
示例2: addMetrics
import redis.clients.util.Pool; //导入依赖的package包/类
/**
* Helper method that registers metrics for a jedis pool.
*
* @param jedisPool
* the pool which is monitored
* @param metrics
* the registry to use for metrics
*/
static void addMetrics(final Pool<Jedis> jedisPool, MetricRegistry metrics) {
final String host = jedisPool.getResource().getClient().getHost();
String prefix = name(RedisConfiguration.METRIC_PREFIX, "redis", host);
metrics.register(name(prefix, "active"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return jedisPool.getNumActive();
}
});
metrics.register(name(prefix, "idle"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return jedisPool.getNumIdle();
}
});
metrics.register(name(prefix, "waiting"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return jedisPool.getNumWaiters();
}
});
}
示例3: RedisTaskManager
import redis.clients.util.Pool; //导入依赖的package包/类
public RedisTaskManager(EngineID engineId, GraknConfig config, Pool<Jedis> jedisPool,
int threads, EngineGraknTxFactory factory,
MetricRegistry metricRegistry, PostProcessor postProcessor) {
Consumer<Task> consumer = new RedisTaskQueueConsumer(this, engineId, config,
metricRegistry, factory,
postProcessor);
LOG.info("Running queue consumer with {} execution threads", threads);
this.redisq = new RedisqBuilder<Task>()
.setJedisPool(jedisPool)
.setName(QUEUE_NAME)
.setConsumer(consumer)
.setMetricRegistry(metricRegistry)
.setThreadPoolSize(threads)
.setDelay(config.getProperty(GraknConfigKey.TASK_DELAY))
.setDocumentClass(Task.class)
.createRedisq();
this.taskStorage = RedisTaskStorage.create(redisq, metricRegistry);
}
示例4: createPool
import redis.clients.util.Pool; //导入依赖的package包/类
public Pool<Jedis> createPool() {
final RedisConnectionConfig.RedisScheme scheme = connectionConfig.getScheme();
if (scheme == null) {
throw createExceptionForNotSupportedScheme();
}
switch (scheme) {
case NODE: {
return createJedisPool();
}
case SENTINEL: {
return createJedisSentinelPool();
}
default: {
throw createExceptionForNotSupportedScheme();
}
}
}
示例5: getJedis
import redis.clients.util.Pool; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private J getJedis(Object pool) {
if (pool instanceof Pool) {
long borrowedTime = currentTimeMillis();
try {
J resource = ((Pool<J>) pool).getResource();
firePoolListener(pool, borrowedTime, null);
return resource;
} catch (Throwable e) {
firePoolListener(pool, borrowedTime, e);
throw e;
}
} else {
throw new IllegalArgumentException("invalid pool:" + pool);
}
}
示例6: testReturnBrokenResource
import redis.clients.util.Pool; //导入依赖的package包/类
@Test
public void testReturnBrokenResource() {
final Pool<Jedis> fakePool = mock(Pool.class);
doThrow(new JedisConnectionException("boogaboogahey")).when(fakePool).returnResource(any(Jedis.class));
final Jedis fakeJedis = mock(Jedis.class);
final JedisWrapperDoNotUse fakeWrapper = mock(JedisWrapperDoNotUse.class);
when(fakeWrapper.__rdbi_isJedisBusted__()).thenReturn(false);
// mocks that return mocks.... forgive me....
final ProxyFactory fakeProxyFactory = mock(ProxyFactory.class);
when(fakeProxyFactory.attachJedis(any(Jedis.class))).thenReturn(fakeWrapper);
final Handle testHandle = new Handle(fakePool, fakeJedis, fakeProxyFactory);
testHandle.close();
verify(fakePool).returnResource(fakeJedis);
verify(fakePool).returnBrokenResource(fakeJedis);
}
示例7: getPool
import redis.clients.util.Pool; //导入依赖的package包/类
@Override
protected Pool<Jedis> getPool(JedisPoolConfig jedisPoolConfig, String serverAddress) {
String[] hosts = serverAddress.split(";");
String host0 = hosts[0];
String[] masterNameAndHost0 = host0.split("@");
String masterName;
if (masterNameAndHost0.length < 2) {
masterName = DEFAULT_MASTER_NAME;
} else {
masterName = masterNameAndHost0[0];
hosts[0] = masterNameAndHost0[1];
}
Set<String> sentinels = new HashSet<String>(Arrays.asList(hosts));
JedisSentinelPool jedisSentinelPool = new JedisSentinelPool(masterName, sentinels, jedisPoolConfig, timeout);
return jedisSentinelPool;
}
示例8: BaseRedis
import redis.clients.util.Pool; //导入依赖的package包/类
public BaseRedis(String setName, String hmName, Pool<T> jedisPool) {
super();
this.setName = setName;
this.setNameBs = setName.getBytes();
this.hmName = hmName;
this.hmNameBs = hmName.getBytes();
this.jedisPool = jedisPool;
}
示例9: interceptJedisPool
import redis.clients.util.Pool; //导入依赖的package包/类
private void interceptJedisPool() {
addRule(Pool.class, "getResource", "AT ENTRY", "onPoolGetStart($0)");
addRule(Pool.class, "getResource", "AT EXIT", "onPoolGetEnd($0)");
addRule(Pool.class, "getResource", "AT EXCEPTION EXIT", "onPoolGetError($0)");
addRule(Pool.class, "returnResource", "AT ENTRY", "onPoolReleaseStart($0)");
addRule(Pool.class, "returnBrokenResource", "AT ENTRY", "onPoolReleaseStart($0)");
addRule(Pool.class, "returnResourceObject", "AT ENTRY", "onPoolReleaseStart($0)");
addRule(Pool.class, "returnResource", "AT EXIT", "onPoolReleaseEnd($0)");
addRule(Pool.class, "returnBrokenResource", "AT EXIT", "onPoolReleaseEnd($0)");
addRule(Pool.class, "returnResourceObject", "AT EXIT", "onPoolReleaseEnd($0)");
addRule(Pool.class, "returnResource", "AT EXCEPTION EXIT", "onPoolReleaseError($0)");
addRule(Pool.class, "returnBrokenResource", "AT EXCEPTION EXIT", "onPoolReleaseError($0)");
addRule(Pool.class, "returnResourceObject", "AT EXCEPTION EXIT", "onPoolReleaseError($0)");
}
示例10: initPool
import redis.clients.util.Pool; //导入依赖的package包/类
@Override
public Pool<ShardedJedis> initPool() throws Exception {
if (Check.isNullOrEmpty(getServers())) {
throw new IllegalArgumentException("未指定redis服务器地址");
}
String[] hosts = getServers().trim().split("\\|");
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
for (String host : hosts) {
String[] ss = host.split(":");
//升级 redis 构造变化
JedisShardInfo shard = new JedisShardInfo(ss[0], Integer.parseInt(ss[1]), connectTimeout, socketTimeout, 1);
shards.add(shard);
}
return new ShardedJedisPool(getPoolConfig(), shards, Hashing.MURMUR_HASH);
}
示例11: unwrap
import redis.clients.util.Pool; //导入依赖的package包/类
@Override
public <T> T unwrap(Class<T> clazz) {
if (clazz.equals(Pool.class)) {
return (T) pool;
}
if (clazz.equals(JedisPool.class)) {
return (T) pool;
}
if (clazz.equals(JedisSentinelPool.class)) {
return (T) pool;
}
throw new IllegalArgumentException(clazz.getName());
}
示例12: tests
import redis.clients.util.Pool; //导入依赖的package包/类
@Test
public void tests() throws Exception {
System.setProperty("spring.profiles.active", "redis");
context = SpringApplication.run(RedisStarterTest.class);
doTest();
A bean = context.getBean(A.class);
bean.test();
Pool<Jedis> t1 = (Pool<Jedis>) context.getBean("defaultPool");
Pool<Jedis> t2 = (Pool<Jedis>) context.getBean("A1Pool");
Assert.assertNotNull(t1);
Assert.assertNotNull(t2);
Assert.assertNotSame(t1, t2);
}
示例13: getObject
import redis.clients.util.Pool; //导入依赖的package包/类
@Override
public Pool<Jedis> getObject() throws Exception {
if (!inited) {
jedisPool = (Pool<Jedis>) autoConfigureBeans.getCustomContainer().get("jedisPool." + key);
inited = true;
}
return jedisPool;
}
示例14: setDataSource
import redis.clients.util.Pool; //导入依赖的package包/类
@Override
public void setDataSource(Pool<Jedis> jedisPool) {
Span span = helper.buildSpan("setDataSource");
try {
super.setDataSource(jedisPool);
} catch (Exception e) {
onError(e, span);
throw e;
} finally {
span.finish();
}
}
示例15: setup
import redis.clients.util.Pool; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() {
jedis = mock(Jedis.class);
pool = mock(Pool.class);
when(pool.getResource()).thenReturn(jedis);
rf = new JedisPoolFacade(pool);
}