@Override public void get(final K k, Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableIterable<V> it = map.get(k); if (it == null) { it = new ChoosableSet<>(0); } fut.complete(it); }, taskQueue, asyncResultHandler); }
@Override public void add(final K k, final V v, Handler<AsyncResult<Void>> completionHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableSet<V> vals = map.get(k); if (vals == null) { vals = new ChoosableSet<>(1); ChoosableSet<V> prevVals = map.putIfAbsent(k, vals); if (prevVals != null) { vals = prevVals; } } vals.add(v); fut.complete(); }, taskQueue, completionHandler); }
@Override public void removeAllMatching(Predicate<V> p, Handler<AsyncResult<Void>> completionHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { Iterator<Entry<K, ChoosableSet<V>>> mapIter = map.entrySet().iterator(); while (mapIter.hasNext()) { Entry<K, ChoosableSet<V>> entry = mapIter.next(); ChoosableSet<V> vals = entry.getValue(); Iterator<V> iter = vals.iterator(); while (iter.hasNext()) { V val = iter.next(); if (p.test(val)) { iter.remove(); } } if (vals.isEmpty()) { mapIter.remove(); } } fut.complete(); }, taskQueue, completionHandler); } }
@Override public void remove(final K k, final V v, Handler<AsyncResult<Boolean>> completionHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableSet<V> vals = map.get(k); boolean found = false; if (vals != null) { boolean removed = vals.remove(v); if (removed) { if (vals.isEmpty()) { map.remove(k); } found = true; } } fut.complete(found); }, taskQueue, completionHandler); }
for (int j = 0;j < queues.length;j++) { int jval = j; context.executeBlocking(fut -> { if (ival == 0) { current[jval].set(Thread.currentThread());
@Override public void get(final K k, Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableIterable<V> it = map.get(k); if (it == null) { it = new ChoosableSet<>(0); } fut.complete(it); }, taskQueue, asyncResultHandler); }
@Override public void removeAllMatching(Predicate<V> p, Handler<AsyncResult<Void>> completionHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { Iterator<Entry<K, ChoosableSet<V>>> mapIter = map.entrySet().iterator(); while (mapIter.hasNext()) { Entry<K, ChoosableSet<V>> entry = mapIter.next(); ChoosableSet<V> vals = entry.getValue(); Iterator<V> iter = vals.iterator(); while (iter.hasNext()) { V val = iter.next(); if (p.test(val)) { iter.remove(); } } if (vals.isEmpty()) { mapIter.remove(); } } fut.complete(); }, taskQueue, completionHandler); } }
@Override public void add(final K k, final V v, Handler<AsyncResult<Void>> completionHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableSet<V> vals = map.get(k); if (vals == null) { vals = new ChoosableSet<>(1); ChoosableSet<V> prevVals = map.putIfAbsent(k, vals); if (prevVals != null) { vals = prevVals; } } vals.add(v); fut.complete(); }, taskQueue, completionHandler); }
@Override public void remove(final K k, final V v, Handler<AsyncResult<Boolean>> completionHandler) { ContextInternal ctx = vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableSet<V> vals = map.get(k); boolean found = false; if (vals != null) { boolean removed = vals.remove(v); if (removed) { if (vals.isEmpty()) { map.remove(k); } found = true; } } fut.complete(found); }, taskQueue, completionHandler); }
for (int j = 0;j < queues.length;j++) { int jval = j; context.executeBlocking(fut -> { if (ival == 0) { current[jval].set(Thread.currentThread());
@Override public SQLConnection setTransactionIsolation(TransactionIsolation isolation, Handler<AsyncResult<Void>> handler) { ctx.executeBlocking((Future<Void> f) -> { try { conn.setTransactionIsolation(isolation.getType()); f.complete(null); } catch (SQLException e) { f.fail(e); } }, statementsQueue, handler); return this; }
private void close(AutoCloseable closeable, AtomicBoolean lock, Handler<AsyncResult<Void>> handler) { if (lock.compareAndSet(false, true)) { ctx.executeBlocking(f -> { try { closeable.close(); f.complete(); } catch (Exception e) { f.fail(e); } }, statementsQueue, handler); } else { if (handler != null) { handler.handle(Future.succeededFuture()); } } } }
@Override public SQLConnection getTransactionIsolation(Handler<AsyncResult<TransactionIsolation>> handler) { ctx.executeBlocking((Future<TransactionIsolation> f) -> { try { TransactionIsolation txIsolation = TransactionIsolation.from(conn.getTransactionIsolation()); if (txIsolation != null) { f.complete(txIsolation); } else { f.fail("Unknown isolation level"); } } catch (SQLException e) { f.fail(e); } }, statementsQueue, handler); return this; }
private <T, R> void execute(Function<IgniteCache<K, Set<V>>, IgniteFuture<T>> cacheOp, Function<T, R> mapper, Handler<AsyncResult<R>> handler) { vertx.getOrCreateContext().executeBlocking(f -> { IgniteFuture<T> future = cacheOp.apply(cache); f.complete(mapper.apply(future.get())); }, taskQueue, handler); } }
@Override public void get(final K k, final Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) { final ContextInternal ctx = FakeClusterManager.this.vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableIterable<V> it = this.map.get(k); if (it == null) { it = new ChoosableSet<>(0); } fut.complete(it); }, this.taskQueue, asyncResultHandler); }
@Override public void get(final K k, final Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) { final ContextInternal ctx = FakeClusterManager.this.vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableIterable<V> it = this.map.get(k); if (it == null) { it = new ChoosableSet<>(0); } fut.complete(it); }, this.taskQueue, asyncResultHandler); }
private <T, R> void execute(Function<IgniteCache<K, Set<V>>, IgniteFuture<T>> cacheOp, Function<T, R> mapper, Handler<AsyncResult<R>> handler) { vertx.getOrCreateContext().executeBlocking(f -> { IgniteFuture<T> future = cacheOp.apply(cache); f.complete(mapper.apply(future.get())); }, taskQueue, handler); } }
@Override public void add(final K k, final V v, final Handler<AsyncResult<Void>> completionHandler) { final ContextInternal ctx = FakeClusterManager.this.vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableSet<V> vals = this.map.get(k); if (vals == null) { vals = new ChoosableSet<>(1); final ChoosableSet<V> prevVals = this.map.putIfAbsent(k, vals); if (prevVals != null) { vals = prevVals; } } vals.add(v); fut.complete(); }, this.taskQueue, completionHandler); }
@Override public void remove(final K k, final V v, final Handler<AsyncResult<Boolean>> completionHandler) { final ContextInternal ctx = FakeClusterManager.this.vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { final ChoosableSet<V> vals = this.map.get(k); boolean found = false; if (vals != null) { final boolean removed = vals.remove(v); if (removed) { if (vals.isEmpty()) { this.map.remove(k); } found = true; } } fut.complete(found); }, this.taskQueue, completionHandler); }
@Override public void add(final K k, final V v, final Handler<AsyncResult<Void>> completionHandler) { final ContextInternal ctx = FakeClusterManager.this.vertx.getOrCreateContext(); ctx.executeBlocking(fut -> { ChoosableSet<V> vals = this.map.get(k); if (vals == null) { vals = new ChoosableSet<>(1); final ChoosableSet<V> prevVals = this.map.putIfAbsent(k, vals); if (prevVals != null) { vals = prevVals; } } vals.add(v); fut.complete(); }, this.taskQueue, completionHandler); }