当前位置: 首页>>代码示例>>Java>>正文


Java Pool类代码示例

本文整理汇总了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());
}
 
开发者ID:mp911de,项目名称:logstash-gelf,代码行数:27,代码来源:RedisGelfSenderProvider.java

示例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();
    }
  });
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:31,代码来源:AbstractJedisFacade.java

示例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);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:21,代码来源:RedisTaskManager.java

示例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();
        }
    }
}
 
开发者ID:idealo,项目名称:logback-redis,代码行数:19,代码来源:JedisPoolFactory.java

示例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);
    }
}
 
开发者ID:PhantomThief,项目名称:jedis-helper,代码行数:17,代码来源:JedisHelper.java

示例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);
}
 
开发者ID:lithiumtech,项目名称:rdbi,代码行数:19,代码来源:HandleTest.java

示例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;
}
 
开发者ID:pister,项目名称:wint,代码行数:18,代码来源:SentinelRedisClient.java

示例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;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:9,代码来源:BaseRedis.java

示例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)");
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:15,代码来源:JedisRuleSet.java

示例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);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:16,代码来源:RedisShardedCacheClient.java

示例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());
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:14,代码来源:RedisCache.java

示例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);
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:15,代码来源:RedisStarterTest.java

示例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;
}
 
开发者ID:alibaba,项目名称:jetcache,代码行数:9,代码来源:JedisPoolFactory.java

示例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();
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-redis-client,代码行数:13,代码来源:TracingJedis.java

示例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);
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:9,代码来源:TestJedisPoolFacade.java


注:本文中的redis.clients.util.Pool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。