protected synchronized void updateCursor(ManagedCursorImpl cursor, Position newPosition) throws InterruptedException, ManagedLedgerException { checkFenced(); // First update the metadata store, so that if we don't succeed we have // not changed any other state store.updateConsumer(name, cursor.getName(), newPosition); Position oldPosition = cursor.setAcknowledgedPosition(newPosition); cursors.cursorUpdated(cursor); if (oldPosition.getLedgerId() != newPosition.getLedgerId()) { // Only trigger a trimming when switching to the next ledger trimConsumedLedgersInBackground(); } }
/* * (non-Javadoc) * * @see org.apache.bookkeeper.mledger.ManagedLedger#openCursor(java. * lang.String) */ @Override public synchronized ManagedCursor openCursor(String cursorName) throws InterruptedException, ManagedLedgerException { checkFenced(); ManagedCursor cursor = cursors.get(cursorName); if (cursor == null) { // Create a new one and persist it Position position = new Position(currentLedger.getId(), currentLedger.getLastAddConfirmed()); cursor = new ManagedCursorImpl(this, cursorName, position); store.updateConsumer(name, cursorName, position); cursors.add(cursor); } log.debug("[{}] Opened new cursor: {}", this.name, cursor); return cursor; }