org.apache.ignite.Ignite.countDownLatch()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(180)

本文整理了Java中org.apache.ignite.Ignite.countDownLatch()方法的一些代码示例,展示了Ignite.countDownLatch()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.countDownLatch()方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:countDownLatch

Ignite.countDownLatch介绍

[英]Gets or creates count down latch. If count down latch is not found in cache and create flag is true, it is created using provided name and count parameter.
[中]获取或创建倒计时闩锁。若在缓存中找不到倒计时锁存器且create标志为true,则使用提供的名称和count参数创建倒计时锁存器。

代码示例

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Nullable @Override public IgniteCountDownLatch countDownLatch(String name,
  int cnt,
  boolean autoDel,
  boolean create)
{
  checkIgnite();
  return g.countDownLatch(name, cnt, autoDel, create);
}

代码示例来源:origin: apache/ignite

/**
 * @param client Ignite client.
 * @param numOfSrvs Number of server nodes.
 * @return Ignite latch.
 */
private IgniteCountDownLatch createLatch1(Ignite client, int numOfSrvs) {
  return client.countDownLatch(
    "testName1", // Latch name.
    numOfSrvs,          // Initial count.
    true,        // Auto remove, when counter has reached zero.
    true         // Create if it does not exist.
  );
}

代码示例来源:origin: apache/ignite

/**
 * @param client Ignite client.
 * @param numOfSrvs Number of server nodes.
 * @return Ignite latch.
 */
private IgniteCountDownLatch createLatch2(Ignite client, int numOfSrvs) {
  return client.countDownLatch(
    "testName2", // Latch name.
    numOfSrvs,          // Initial count.
    true,        // Auto remove, when counter has reached zero.
    true         // Create if it does not exist.
  );
}

代码示例来源:origin: apache/ignite

@Override public Object apply(Ignite ignite) {
    assert ignite.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).count() > 0;
    return null;
  }
});

代码示例来源:origin: apache/ignite

@Override public void apply() {
    log.info("BROADCASTING....");
    ignite.countDownLatch("broadcast", 2, false, true).countDown();
    execCntr.incrementAndGet();
  }
});

代码示例来源:origin: apache/ignite

@Override public void applyx(Ignite ignite) {
    IgniteCountDownLatch l = ignite.countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, true, true);
    for (int i = 0; i < operationsPerTx; i++) {
      l.count();
      long cnt = reads.incrementAndGet();
      if (cnt % READ_LOG_MOD == 0)
        info("Performed " + cnt + " reads.");
    }
  }
};

代码示例来源:origin: apache/ignite

@Override public void applyx(Ignite ignite) {
    IgniteCountDownLatch l = ignite.countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, true, true);
    for (int i = 0; i < operationsPerTx; i++) {
      l.countDown();
      long cnt = writes.incrementAndGet();
      if (cnt % WRITE_LOG_MOD == 0)
        info("Performed " + cnt + " writes.");
    }
  }
};

代码示例来源:origin: apache/ignite

@Override public void apply() {
    log.info("UNICASTING....");
    ignite.countDownLatch("unicast", 1, false, true).countDown();
    execCntr.incrementAndGet();
  }
});

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testLatchVolatility() throws Exception {
  Ignite ignite = startGrids(4);
  ignite.active(true);
  IgniteCountDownLatch latch = ignite.countDownLatch("test", 10, false, true);
  assert latch != null;
  stopAllGrids();
  ignite = startGrids(4);
  ignite.active(true);
  latch = ignite.countDownLatch("test", 10, false, false);
  assert latch == null;
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception Thrown in case of failure.
 */
@Test
public void testAnonymousBroadcast() throws Exception {
  Ignite g = grid(0);
  assert g.cluster().nodes().size() == NODES_CNT;
  execCntr.set(0);
  g.compute().broadcast(new CARemote() {
    @Override public void apply() {
      log.info("BROADCASTING....");
      ignite.countDownLatch("broadcast", 2, false, true).countDown();
      execCntr.incrementAndGet();
    }
  });
  assertTrue(g.countDownLatch("broadcast", 2, false, true).await(2000));
  assertEquals(1, execCntr.get());
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception Thrown in case of failure.
 */
@Test
public void testAnonymousUnicast() throws Exception {
  Ignite g = grid(0);
  assert g.cluster().nodes().size() == NODES_CNT;
  execCntr.set(0);
  ClusterNode rmt = F.first(g.cluster().forRemotes().nodes());
  compute(g.cluster().forNode(rmt)).run(new CARemote() {
    @Override public void apply() {
      log.info("UNICASTING....");
      ignite.countDownLatch("unicast", 1, false, true).countDown();
      execCntr.incrementAndGet();
    }
  });
  assertTrue(g.countDownLatch("unicast", 1, false, true).await(2000));
  assertEquals(0, execCntr.get());
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testCountDownLatchTopologyChange() throws Exception {
  try (IgniteCountDownLatch latch = grid(0).countDownLatch(STRUCTURE_NAME, 20, true, true)) {
    try {
      Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
      assertEquals(20, g.countDownLatch(STRUCTURE_NAME, 20, true, false).count());
      g.countDownLatch(STRUCTURE_NAME, 20, true, false).countDown(10);
      stopGrid(NEW_IGNITE_INSTANCE_NAME);
      assertEquals(10, grid(0).countDownLatch(STRUCTURE_NAME, 20, true, false).count());
    }
    finally {
      grid(0).countDownLatch(STRUCTURE_NAME, 20, true, false).countDownAll();
    }
  }
}

代码示例来源:origin: apache/ignite

/**
 *
 * @throws Exception Thrown in case of failure.
 */
@Test
public void testAnonymousUnicastRequest() throws Exception {
  Ignite g = grid(0);
  assert g.cluster().nodes().size() == NODES_CNT;
  execCntr.set(0);
  ClusterNode rmt = F.first(g.cluster().forRemotes().nodes());
  final ClusterNode loc = g.cluster().localNode();
  compute(g.cluster().forNode(rmt)).run(new CARemote() {
    @Override public void apply() {
      message(grid(1).cluster().forNode(loc)).localListen(null, new IgniteBiPredicate<UUID, String>() {
        @Override public boolean apply(UUID uuid, String s) {
          log.info("Received test message [nodeId: " + uuid + ", s=" + s + ']');
          ignite.countDownLatch("messagesPending", 1, false, true).countDown();
          execCntr.incrementAndGet();
          return false;
        }
      });
    }
  });
  message(g.cluster().forNode(rmt)).send(null, "TESTING...");
  assertTrue(g.countDownLatch("messagesPending", 1, false, true).await(2000));
  assertEquals(0, execCntr.get());
}

代码示例来源:origin: apache/ignite

final IgniteAtomicReference<Integer> atomicRef = client.atomicReference("atomicRef", 1, true);
final IgniteAtomicStamped<Integer, Integer> atomicStamped = client.atomicStamped("atomicStamped", 1, 1, true);
final IgniteCountDownLatch latch = client.countDownLatch("latch", 1, true, true);
final IgniteAtomicSequence seq = client.atomicSequence("seq", 1L, true);

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testLatchReconnect() throws Exception {
  Ignite client = grid(serverCount());
  assertTrue(client.cluster().localNode().isClient());
  Ignite srv = ignite(0);
  IgniteCountDownLatch clientLatch = client.countDownLatch("latch1", 3, false, true);
  assertEquals(3, clientLatch.count());
  final IgniteCountDownLatch srvLatch = srv.countDownLatch("latch1", 3, false, false);
  assertEquals(3, srvLatch.count());
  reconnectClientNode(client, srv, new Runnable() {
    @Override public void run() {
      srvLatch.countDown();
    }
  });
  assertEquals(2, srvLatch.count());
  assertEquals(2, clientLatch.count());
  srvLatch.countDown();
  assertEquals(1, srvLatch.count());
  assertEquals(1, clientLatch.count());
  clientLatch.countDown();
  assertEquals(0, srvLatch.count());
  assertEquals(0, clientLatch.count());
  assertTrue(srvLatch.await(1000));
  assertTrue(clientLatch.await(1000));
}

代码示例来源:origin: apache/ignite

/**
 * Tests distributed count down latch.
 *
 * @param topWorker Topology change worker.
 * @throws Exception If failed.
 */
private void doTestCountDownLatch(ConstantTopologyChangeWorker topWorker) throws Exception {
  try (IgniteCountDownLatch s = grid(0).countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, true)) {
    try {
      IgniteInternalFuture<?> fut = topWorker.startChangingTopology(
        new IgniteClosure<Ignite, Object>() {
          @Override public Object apply(Ignite ignite) {
            assert ignite.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).count() > 0;
            return null;
          }
        });
      int val = s.count();
      while (!fut.isDone()) {
        assertEquals(val, s.count());
        assertEquals(--val, s.countDown());
      }
      fut.get();
      for (Ignite g : G.allGrids())
        assertEquals(val, g.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, true).count());
    }
    finally {
      grid(0).countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).countDownAll();
    }
  }
}

代码示例来源:origin: apache/ignite

Ignite ig3 = primary(2);
IgniteCountDownLatch latchExp1 = ig1.countDownLatch(latchName, 5, false, true);
assertTrue(ig3.active());
final IgniteCountDownLatch latchAct1 = ig1.countDownLatch(latchName, 0, false, false);
final IgniteCountDownLatch latchAct2 = ig2.countDownLatch(latchName, 0, false, false);
final IgniteCountDownLatch latchAct3 = ig3.countDownLatch(latchName, 0, false, false);

代码示例来源:origin: apache/ignite

/**
 * Implementation of ignite data structures internally uses special system caches, need make sure
 * that transaction on these system caches do not intersect with transactions started by user.
 *
 * @throws Exception If failed.
 */
@Test
public void testIsolation() throws Exception {
  Ignite ignite = grid(0);
  CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
  cfg.setName("myCache");
  cfg.setAtomicityMode(TRANSACTIONAL);
  cfg.setWriteSynchronizationMode(FULL_SYNC);
  IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg);
  try {
    IgniteCountDownLatch latch = ignite.countDownLatch("latch1", 10, false, true);
    assertNotNull(latch);
    try (Transaction tx = ignite.transactions().txStart()) {
      cache.put(1, 1);
      assertEquals(8, latch.countDown(2));
      tx.rollback();
    }
    assertEquals(0, cache.size());
    assertEquals(7, latch.countDown(1));
  }
  finally {
    ignite.destroyCache(cfg.getName());
  }
}

代码示例来源:origin: org.apache.ignite/ignite-spring

/** {@inheritDoc} */
@Nullable @Override public IgniteCountDownLatch countDownLatch(String name,
  int cnt,
  boolean autoDel,
  boolean create)
{
  checkIgnite();
  return g.countDownLatch(name, cnt, autoDel, create);
}

相关文章