org.redisson.api.RCountDownLatch Java Examples

The following examples show how to use org.redisson.api.RCountDownLatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissionUtilsTest.java    From Redis_Learning with Apache License 2.0 6 votes vote down vote up
/** 
     * ��Ϣ���еĶ����� 
     * @throws InterruptedException 
     */  
    @Test  
    public void testGetRTopicSub() throws InterruptedException {  
        RTopic<String> rTopic=RedissionUtils.getInstance().getRTopic(redisson, "testTopic");  
//        rTopic.addListener(new MessageListener<String>() {  
//
//			@Override
//			public void onMessage(String arg0, String arg1) {
//				System.out.println("�㷢������:"+arg0);
//			}  
//        });  
        //�ȴ������߷�����Ϣ  
        RCountDownLatch rCountDownLatch=RedissionUtils.getInstance().getRCountDownLatch(redisson, "testCountDownLatch");  
        rCountDownLatch.trySetCount(1);  
        rCountDownLatch.await();  
    }
 
Example #2
Source File: RedissionUtilsTest.java    From Redis_Learning with Apache License 2.0 5 votes vote down vote up
/** 
 * RCountDownLatch ӳ��Ϊredis server��string ���� 
 * string����ֵ 
 * ����--�ȴ������߳��еIJ��������� �ڽ��в��� 
 * �鿴���м�---->keys * 
 * �鿴key������--->type testCountDownLatch 
 * �鿴key��ֵ ---->get testCountDownLatch  
 */  
@Test  
public void testGetRCountDownLatch() throws InterruptedException {  
    RCountDownLatch rCountDownLatch=RedissionUtils.getInstance().getRCountDownLatch(redisson, "testCountDownLatch");  
    System.out.println(rCountDownLatch.getCount());  
    //rCountDownLatch.trySetCount(1l);  
    System.out.println(rCountDownLatch.getCount());  
    rCountDownLatch.await(10, TimeUnit.SECONDS);  
    System.out.println(rCountDownLatch.getCount());  
}
 
Example #3
Source File: RedissionUtilsTest.java    From Redis_Learning with Apache License 2.0 5 votes vote down vote up
/** 
 * ��Ϣ���еķ����� 
 */  
@Test  
public void testGetRTopicPub() {  
    RTopic<String> rTopic=RedissionUtils.getInstance().getRTopic(redisson, "testTopic");  
    System.out.println(rTopic.publish("�����Ƕ�ͯ�ڣ���Ҷ�ͯ�ڿ���"));  
    //��������Ϣ�� �ö����߲��ٵȴ�  
    RCountDownLatch rCountDownLatch=RedissionUtils.getInstance().getRCountDownLatch(redisson, "testCountDownLatch");  
    rCountDownLatch.countDown();  
}
 
Example #4
Source File: RedissonCountDownLatchConcurrentTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleCountDownAwait_SingleInstance() throws InterruptedException {
    final int iterations = Runtime.getRuntime().availableProcessors()*3;

    RedissonClient redisson = BaseTest.createInstance();
    final RCountDownLatch latch = redisson.getCountDownLatch("latch");
    latch.trySetCount(iterations);

    final AtomicInteger counter = new AtomicInteger();
    ExecutorService executor = Executors.newScheduledThreadPool(iterations);
    for (int i = 0; i < iterations; i++) {
        executor.execute(() -> {
            try {
                latch.await();
                Assert.assertEquals(0, latch.getCount());
                Assert.assertEquals(iterations, counter.get());
            } catch (InterruptedException e) {
                Assert.fail();
            }
        });
    }

    ExecutorService countDownExecutor = Executors.newFixedThreadPool(iterations);
    for (int i = 0; i < iterations; i++) {
        countDownExecutor.execute(() -> {
            latch.countDown();
            counter.incrementAndGet();
        });
    }

    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));

    redisson.shutdown();
}
 
Example #5
Source File: CountDownLatchExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    ExecutorService executor = Executors.newFixedThreadPool(2);

    final RCountDownLatch latch = redisson.getCountDownLatch("latch1");
    latch.trySetCount(1);

    executor.execute(new Runnable() {

        @Override
        public void run() {
            latch.countDown();
        }
        
    });

    executor.execute(new Runnable() {

        @Override
        public void run() {
            try {
                latch.await(550, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        
    });

    
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);

}
 
Example #6
Source File: RedissonCountDownLatchTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testCount() {
    RCountDownLatch latch = redisson.getCountDownLatch("latch");
    assertThat(latch.getCount()).isEqualTo(0);
}
 
Example #7
Source File: RedissonCountDownLatchTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testTrySetCount() throws Exception {
    RCountDownLatch latch = redisson.getCountDownLatch("latch");
    assertThat(latch.trySetCount(1)).isTrue();
    assertThat(latch.trySetCount(2)).isFalse();
}
 
Example #8
Source File: RedissonCountDownLatchTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteFailed() throws Exception {
    RCountDownLatch latch = redisson.getCountDownLatch("latch");
    Assert.assertFalse(latch.delete());
}
 
Example #9
Source File: RedissonCountDownLatchTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testDelete() throws Exception {
    RCountDownLatch latch = redisson.getCountDownLatch("latch");
    latch.trySetCount(1);
    Assert.assertTrue(latch.delete());
}
 
Example #10
Source File: RedissonCountDownLatchTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testCountDown() throws InterruptedException {
    RCountDownLatch latch = redisson.getCountDownLatch("latch");
    latch.trySetCount(2);
    Assert.assertEquals(2, latch.getCount());
    latch.countDown();
    Assert.assertEquals(1, latch.getCount());
    latch.countDown();
    Assert.assertEquals(0, latch.getCount());
    latch.await();
    latch.countDown();
    Assert.assertEquals(0, latch.getCount());
    latch.await();
    latch.countDown();
    Assert.assertEquals(0, latch.getCount());
    latch.await();

    RCountDownLatch latch1 = redisson.getCountDownLatch("latch1");
    latch1.trySetCount(1);
    latch1.countDown();
    Assert.assertEquals(0, latch.getCount());
    latch1.countDown();
    Assert.assertEquals(0, latch.getCount());
    latch1.await();

    RCountDownLatch latch2 = redisson.getCountDownLatch("latch2");
    latch2.trySetCount(1);
    latch2.countDown();
    latch2.await();
    latch2.await();

    RCountDownLatch latch3 = redisson.getCountDownLatch("latch3");
    Assert.assertEquals(0, latch.getCount());
    latch3.await();

    RCountDownLatch latch4 = redisson.getCountDownLatch("latch4");
    Assert.assertEquals(0, latch.getCount());
    latch4.countDown();
    Assert.assertEquals(0, latch.getCount());
    latch4.await();
}
 
Example #11
Source File: RedissonMap.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(K key) {
    String lockName = getLockByMapKey(key, "countdownlatch");
    return new RedissonCountDownLatch(commandExecutor, lockName);
}
 
Example #12
Source File: RedissonSetMultimapValues.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(V value) {
    return set.getCountDownLatch(value);
}
 
Example #13
Source File: RedissonSet.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(V value) {
    String lockName = getLockByValue(value, "countdownlatch");
    return new RedissonCountDownLatch(commandExecutor, lockName);
}
 
Example #14
Source File: RedissonSetCache.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(V value) {
    String lockName = getLockByValue(value, "countdownlatch");
    return new RedissonCountDownLatch(commandExecutor, lockName);
}
 
Example #15
Source File: RedissonTransactionalMap.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(K key) {
    throw new UnsupportedOperationException("getCountDownLatch method is not supported in transaction");
}
 
Example #16
Source File: RedissonTransactionalSet.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(V value) {
    throw new UnsupportedOperationException("getCountDownLatch method is not supported in transaction");
}
 
Example #17
Source File: RedissonTransactionalMapCache.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(K key) {
    throw new UnsupportedOperationException("getCountDownLatch method is not supported in transaction");
}
 
Example #18
Source File: TracingRMultimap.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(K key) {
  return new TracingRCountDownLatch(map.getCountDownLatch(key), tracingRedissonHelper);
}
 
Example #19
Source File: TracingRMap.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(K key) {
  return new TracingRCountDownLatch(map.getCountDownLatch(key), tracingRedissonHelper);
}
 
Example #20
Source File: TracingRSet.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(V value) {
  return new TracingRCountDownLatch(set.getCountDownLatch(value), tracingRedissonHelper);
}
 
Example #21
Source File: TracingRCountDownLatch.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
public TracingRCountDownLatch(RCountDownLatch latch,
    TracingRedissonHelper tracingRedissonHelper) {
  super(latch, tracingRedissonHelper);
  this.latch = latch;
  this.tracingRedissonHelper = tracingRedissonHelper;
}
 
Example #22
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(String name) {
  return new TracingRCountDownLatch(redissonClient.getCountDownLatch(name),
      tracingRedissonHelper);
}
 
Example #23
Source File: TracingRSetCache.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RCountDownLatch getCountDownLatch(V value) {
  return new TracingRCountDownLatch(cache.getCountDownLatch(value), tracingRedissonHelper);
}
 
Example #24
Source File: RedissionUtils.java    From Redis_Learning with Apache License 2.0 2 votes vote down vote up
/** 
 * ��ȡ������ 
 * @param redisson 
 * @param objectName 
 * @return 
 */  
public RCountDownLatch getRCountDownLatch(RedissonClient redisson,String objectName){  
    RCountDownLatch rCountDownLatch=redisson.getCountDownLatch(objectName);  
    return rCountDownLatch;  
}