void notifyCursors() { while (true) { final ManagedCursorImpl waitingCursor = waitingCursors.poll(); if (waitingCursor == null) { break; } executor.execute(safeRun(() -> waitingCursor.notifyEntriesAvailable())); } }
void checkReadCompletion() { if (entries.size() < count && cursor.hasMoreEntries()) { // We still have more entries to read from the next ledger, schedule a new async operation if (nextReadPosition.getLedgerId() != readPosition.getLedgerId()) { cursor.ledger.startReadOperationOnLedger(nextReadPosition); } // Schedule next read in a different thread cursor.ledger.getExecutor().execute(safeRun(() -> { readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition); cursor.ledger.asyncReadEntries(OpReadEntry.this); })); } else { // The reading was already completed, release resources and trigger callback try { cursor.readOperationCompleted(); } finally { cursor.ledger.getExecutor().executeOrdered(cursor.ledger.getName(), safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle(); })); } } }
void checkReadCompletion() { if (entries.size() < count && cursor.hasMoreEntries()) { // We still have more entries to read from the next ledger, schedule a new async operation if (nextReadPosition.getLedgerId() != readPosition.getLedgerId()) { cursor.ledger.startReadOperationOnLedger(nextReadPosition); } // Schedule next read in a different thread cursor.ledger.getExecutor().execute(safeRun(() -> { readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition); cursor.ledger.asyncReadEntries(OpReadEntry.this); })); } else { // The reading was already completed, release resources and trigger callback try { cursor.readOperationCompleted(); } finally { cursor.ledger.getExecutor().executeOrdered(cursor.ledger.getName(), safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle(); })); } } }
ledger.getExecutor().execute(safeRun(() -> { ledger.mbean.endCursorLedgerCreateOp(); if (rc != BKException.Code.OK) {
cursor.ledger.getExecutor().execute(safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle();
public void asyncInvalidate(String path) { backgroundExecutor.execute(() -> invalidate(path)); }
void notifyCursors() { while (true) { final ManagedCursorImpl waitingCursor = waitingCursors.poll(); if (waitingCursor == null) { break; } executor.execute(safeRun(() -> waitingCursor.notifyEntriesAvailable())); } }
@Override public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType, int zkSessionTimeoutMillis) { CompletableFuture<ZooKeeper> future = new CompletableFuture<>(); executor.execute(safeRun(() -> { try { ZooKeeper zk = ZooKeeperClient.newBuilder().connectString(serverList) .sessionTimeoutMs(zkSessionTimeoutMillis) .connectRetryPolicy(new BoundExponentialBackoffRetryPolicy(zkSessionTimeoutMillis, zkSessionTimeoutMillis, 0)) .build(); if (zk.getState() == States.CONNECTEDREADONLY && sessionType != SessionType.AllowReadOnly) { future.completeExceptionally(new IllegalStateException("Cannot use a read-only session")); } log.info("ZooKeeper session established: {}", zk); future.complete(zk); } catch (IOException | KeeperException | InterruptedException exception) { log.error("Failed to establish ZooKeeper session: {}", exception.getMessage()); future.completeExceptionally(exception); } }, throwable -> { future.completeExceptionally(throwable); })); return future; } }
@Override public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessionType, int zkSessionTimeoutMillis) { CompletableFuture<ZooKeeper> future = new CompletableFuture<>(); executor.execute(safeRun(() -> { try { ZooKeeper zk = BkZooKeeperClient.newBuilder().connectString(serverList) .sessionTimeoutMs(zkSessionTimeoutMillis) .connectRetryPolicy(new BoundExponentialBackoffRetryPolicy(zkSessionTimeoutMillis, zkSessionTimeoutMillis, 0)) .allowReadOnlyMode(sessionType == SessionType.AllowReadOnly).build(); if (zk.getState() == States.CONNECTEDREADONLY && sessionType != SessionType.AllowReadOnly) { future.completeExceptionally(new IllegalStateException("Cannot use a read-only session")); } log.info("ZooKeeper session established: {}", zk); future.complete(zk); } catch (IOException | KeeperException | InterruptedException exception) { log.error("Failed to establish ZooKeeper session: {}", exception.getMessage()); future.completeExceptionally(exception); } }, throwable -> { future.completeExceptionally(throwable); })); return future; }
.execute(() -> splitAndOwnBundleOnceAndRetry(bundle, unload, counter, unloadFuture)); } else {
ledger.getExecutor().execute(safeRun(() -> { ledger.mbean.endCursorLedgerCreateOp(); if (rc != BKException.Code.OK) {
cursor.ledger.getExecutor().execute(safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle();