コード例 #1
0
 @Override
 public void remove(K key, Handler<AsyncResult<V>> handler) {
   execute(cache -> cache.getAndRemove(key), handler);
 }
コード例 #2
0
  /** @throws Exception If test fails. */
  public void testBasicOpsAsync() throws Exception {
    CountDownLatch latch = new CountDownLatch(3);

    CacheEventListener lsnr = new CacheEventListener(latch);

    try {
      IgniteCache<String, String> cache1 = ignite1.cache(null);
      IgniteCache<String, String> cache1Async = cache1.withAsync();
      IgniteCache<String, String> cache2 = ignite2.cache(null);
      IgniteCache<String, String> cache2Async = cache2.withAsync();
      IgniteCache<String, String> cache3 = ignite3.cache(null);
      IgniteCache<String, String> cache3Async = cache3.withAsync();

      ignite1.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED);
      ignite2.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED);
      ignite3.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED);

      cache1Async.get("async1");

      IgniteFuture<String> f1 = cache1Async.future();

      assert f1.get() == null;

      cache1Async.put("async1", "asyncval1");

      cache1Async.future().get();

      cache1Async.get("async1");

      f1 = cache1Async.future();

      String v1 = f1.get();

      assert v1 != null;
      assert "asyncval1".equals(v1);

      assert latch.await(5, SECONDS);

      cache2Async.get("async1");

      IgniteFuture<String> f2 = cache2Async.future();

      cache3Async.get("async1");

      IgniteFuture<String> f3 = cache3Async.future();

      String v2 = f2.get();
      String v3 = f3.get();

      assert v2 != null;
      assert v3 != null;

      assert "asyncval1".equals(v2);
      assert "asyncval1".equals(v3);

      lsnr.setLatch(latch = new CountDownLatch(3));

      cache2Async.getAndRemove("async1");

      f2 = cache2Async.future();

      assert "asyncval1".equals(f2.get());

      assert latch.await(5, SECONDS);

      cache1Async.get("async1");

      f1 = cache1Async.future();

      cache2Async.get("async1");

      f2 = cache2Async.future();

      cache3Async.get("async1");

      f3 = cache3Async.future();

      v1 = f1.get();
      v2 = f2.get();
      v3 = f3.get();

      info("Removed v1: " + v1);
      info("Removed v2: " + v2);
      info("Removed v3: " + v3);

      assert v1 == null;
      assert v2 == null;
      assert v3 == null;
    } finally {
      ignite1.events().stopLocalListen(lsnr);
      ignite2.events().stopLocalListen(lsnr);
      ignite3.events().stopLocalListen(lsnr);
    }
  }