/** * Add entry to a ledger. * * @throws BookieException.LedgerFencedException if the ledger is fenced */ public void addEntry(ByteBuffer entry, WriteCallback cb, Object ctx, byte[] masterKey) throws IOException, BookieException { long requestNanos = MathUtils.nowInNano(); boolean success = false; try { LedgerDescriptor handle = getLedgerForEntry(entry, masterKey); synchronized (handle) { if (handle.isFenced()) { throw BookieException.create(BookieException.Code.LedgerFencedException); } addEntryInternal(handle, entry, cb, ctx); } success = true; } catch (NoWritableLedgerDirException e) { transitionToReadOnlyMode(); throw new IOException(e); } finally { long elapsedMicros = MathUtils.elapsedMicroSec(requestNanos); if (success) { addEntryStats.registerSuccessfulEvent(elapsedMicros); } else { addEntryStats.registerFailedEvent(elapsedMicros); } } }