/** * Extract an exception code from an BKException, or default to unexpected exception if throwable * is not a BKException. * * @see #getExceptionCode(Throwable,int) */ public static int getExceptionCode(Throwable t) { return getExceptionCode(t, Code.UnexpectedConditionException); } }
/** * Extract an exception code from an BKException, or use a default if it's another type. * The throwable is null, assume that no exception took place and return * {@link BKException.Code.OK}. */ public static int getExceptionCode(Throwable t, int defaultCode) { if (t == null) { return BKException.Code.OK; } else if (t instanceof BKException) { return ((BKException) t).getCode(); } else if (t.getCause() != null) { return getExceptionCode(t.getCause(), defaultCode); } else { return defaultCode; } }
} else if (BKException.getExceptionCode(exception) == BKException.Code.NoSuchLedgerExistsException) { ledgerId, BKException.getExceptionCode(exception)); scheduler.schedule(this, MS_CONNECT_BACKOFF_MS, TimeUnit.MILLISECONDS);
} else if (BKException.getExceptionCode(exception) == BKException.Code.NoSuchLedgerExistsException) { ledgerId, BKException.getExceptionCode(exception)); scheduler.schedule(this, ZK_CONNECT_BACKOFF_MS, TimeUnit.MILLISECONDS);
@Override public void process(Long ledgerId, AsyncCallback.VoidCallback iterCallback) { ledgerManager.readLedgerMetadata(ledgerId).whenComplete( (metadata, exception) -> { if (exception == null) { for (Map.Entry<Long, ? extends List<BookieSocketAddress>> ensemble : metadata.getValue().getAllEnsembles().entrySet()) { for (BookieSocketAddress bookie : ensemble.getValue()) { putLedger(bookie2ledgersMap, bookie.toString(), ledgerId); } } iterCallback.processResult(BKException.Code.OK, null, null); } else if (BKException.getExceptionCode(exception) == BKException.Code.NoSuchLedgerExistsException) { LOG.info("Ignoring replication of already deleted ledger {}", ledgerId); iterCallback.processResult(BKException.Code.OK, null, null); } else { LOG.warn("Unable to read the ledger: {} information", ledgerId); iterCallback.processResult(BKException.getExceptionCode(exception), null, null); } }); } };
@Override public void process(final Long lid, final AsyncCallback.VoidCallback cb) { bkc.getLedgerManager().readLedgerMetadata(lid) .whenComplete((metadata, exception) -> { if (BKException.getExceptionCode(exception) == BKException.Code.NoSuchLedgerExistsException) { // the ledger was deleted during this iteration. cb.processResult(BKException.Code.OK, null, null); return; } else if (exception != null) { cb.processResult(BKException.getExceptionCode(exception), null, null); return; } Set<BookieSocketAddress> bookiesInLedger = LedgerMetadataUtils.getBookiesInThisLedger(metadata.getValue()); Sets.SetView<BookieSocketAddress> intersection = Sets.intersection(bookiesInLedger, bookies); if (!intersection.isEmpty()) { ledgers.put(lid, metadata.getValue()); } cb.processResult(BKException.Code.OK, null, null); }); } }, new AsyncCallback.VoidCallback() {
/** * Check asynchronously whether the ledger with identifier <i>lId</i> * has been closed. * * @param lId ledger identifier * @param cb callback method */ public void asyncIsClosed(long lId, final IsClosedCallback cb, final Object ctx){ ledgerManager.readLedgerMetadata(lId).whenComplete((metadata, exception) -> { if (exception == null) { cb.isClosedComplete(BKException.Code.OK, metadata.getValue().isClosed(), ctx); } else { cb.isClosedComplete(BKException.getExceptionCode(exception), false, ctx); } }); }
BKException.getExceptionCode(ex, BKException.Code.UnexpectedConditionException), null, null);
/** * Inititates the ledger open operation. */ public void initiate() { startTime = MathUtils.nowInNano(); /** * Asynchronously read the ledger metadata node. */ bk.getLedgerManager().readLedgerMetadata(ledgerId) .whenComplete((metadata, exception) -> { if (exception != null) { openComplete(BKException.getExceptionCode(exception), null); } else { openWithMetadata(metadata); } }); }
if (ex != null) { LOG.warn("{}[attempt:{}] Exception changing ensemble", logContext, attempts.get(), ex); handleUnrecoverableErrorDuringAdd(BKException.getExceptionCode(ex, WriteException)); } else if (metadata.getValue().isClosed()) { if (LOG.isDebugEnabled()) {
if (exception != null) { if (this.generateLedgerId && (BKException.getExceptionCode(exception) == BKException.Code.LedgerExistException)) { createComplete(BKException.getExceptionCode(exception), null);
/** * Initiates the operation. */ public void initiate() { // Asynchronously delete the ledger from meta manager // When this completes, it will invoke the callback method below. bk.getLedgerManager().removeLedgerMetadata(ledgerId, Version.ANY) .whenCompleteAsync((ignore, exception) -> { if (exception != null) { deleteOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS); } else { deleteOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS); } cb.deleteComplete(BKException.getExceptionCode(exception), this.ctx); }, bk.getMainWorkerPool().chooseThread(ledgerId)); }
if (ex != null) { cb.operationComplete( BKException.getExceptionCode(ex, BKException.Code.UnexpectedConditionException), null); } else { cb.operationComplete(BKException.Code.OK, null);
if (ex != null) { cb.closeComplete( BKException.getExceptionCode(ex, BKException.Code.UnexpectedConditionException), LedgerHandle.this, ctx); } else {