Class ReadOnlyLedgerHandle

    • Constructor Detail

      • ReadOnlyLedgerHandle

        ReadOnlyLedgerHandle​(ClientContext clientCtx,
                             long ledgerId,
                             Versioned<LedgerMetadata> metadata,
                             BookKeeper.DigestType digestType,
                             byte[] password,
                             boolean watch)
                      throws java.security.GeneralSecurityException,
                             java.lang.NumberFormatException
        Throws:
        java.security.GeneralSecurityException
        java.lang.NumberFormatException
    • Method Detail

      • close

        public void close()
                   throws java.lang.InterruptedException,
                          BKException
        Description copied from class: LedgerHandle
        Synchronous close the write handle, any adds in flight will return errors.

        Closing a ledger will ensure that all clients agree on what the last entry of the ledger is. Once the ledger has been closed, all reads from the ledger will return the same set of entries.

        The close operation can error if it finds conflicting metadata when it tries to write to the metadata store. On close, the metadata state is set to closed and lastEntry and length of the ledger are fixed in the metadata. A conflict occurs if the metadata in the metadata store has a different value for the lastEntry or length. If another process has updated the metadata, setting it to closed, but have fixed the lastEntry and length to the same values as this process is trying to write, the operation completes successfully.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface Handle
        Specified by:
        close in interface WriteHandle
        Overrides:
        close in class LedgerHandle
        Throws:
        java.lang.InterruptedException
        BKException
        See Also:
        Handle.closeAsync()
      • asyncClose

        public void asyncClose​(AsyncCallback.CloseCallback cb,
                               java.lang.Object ctx)
        Description copied from class: LedgerHandle
        Asynchronous close, any adds in flight will return errors.

        Closing a ledger will ensure that all clients agree on what the last entry of the ledger is. This ensures that, once the ledger has been closed, all reads from the ledger will return the same set of entries.

        Overrides:
        asyncClose in class LedgerHandle
        Parameters:
        cb - callback implementation
        ctx - control object
      • addEntry

        public long addEntry​(byte[] data)
                      throws java.lang.InterruptedException,
                             BKException
        Description copied from class: LedgerHandle
        Add entry synchronously to an open ledger.
        Overrides:
        addEntry in class LedgerHandle
        Parameters:
        data - array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriately
        Returns:
        the entryId of the new inserted entry
        Throws:
        java.lang.InterruptedException
        BKException
      • addEntry

        public long addEntry​(byte[] data,
                             int offset,
                             int length)
                      throws java.lang.InterruptedException,
                             BKException
        Description copied from class: LedgerHandle
        Add entry synchronously to an open ledger.
        Overrides:
        addEntry in class LedgerHandle
        Parameters:
        data - array of bytes to be written to the ledger do not reuse the buffer, bk-client will release it appropriately
        offset - offset from which to take bytes from data
        length - number of bytes to take from data
        Returns:
        the entryId of the new inserted entry
        Throws:
        java.lang.InterruptedException
        BKException
      • asyncAddEntry

        public void asyncAddEntry​(byte[] data,
                                  AsyncCallback.AddCallback cb,
                                  java.lang.Object ctx)
        Description copied from class: LedgerHandle
        Add entry asynchronously to an open ledger.
        Overrides:
        asyncAddEntry in class LedgerHandle
        Parameters:
        data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately
        cb - object implementing callbackinterface
        ctx - some control object
      • asyncAddEntry

        public void asyncAddEntry​(byte[] data,
                                  int offset,
                                  int length,
                                  AsyncCallback.AddCallback cb,
                                  java.lang.Object ctx)
        Description copied from class: LedgerHandle
        Add entry asynchronously to an open ledger, using an offset and range.
        Overrides:
        asyncAddEntry in class LedgerHandle
        Parameters:
        data - array of bytes to be written do not reuse the buffer, bk-client will release it appropriately
        offset - offset from which to take bytes from data
        length - number of bytes to take from data
        cb - object implementing callbackinterface
        ctx - some control object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • handleBookieFailure

        void handleBookieFailure​(java.util.Map<java.lang.Integer,​BookieId> failedBookies)
        For a read only ledger handle, this method will only ever be called during recovery, when we are reading forward from LAC and writing back those entries. As such, unlike with LedgerHandle, we do not want to persist changes to the metadata as they occur, but rather, we want to defer the persistence until recovery has completed, and do it all on the close.
        Overrides:
        handleBookieFailure in class LedgerHandle
      • getCurrentEnsemble

        java.util.List<BookieId> getCurrentEnsemble()
        Description copied from class: LedgerHandle
        Get the current ensemble from the ensemble list. The current ensemble is the last ensemble in the list. The ledger handle uses this ensemble when triggering operations which work on the end of the ledger, such as adding new entries or reading the last add confirmed.

        This method is also used by ReadOnlyLedgerHandle during recovery, and when tailing a ledger.

        Generally, this method should only be called by LedgerHandle and not by the operations themselves, to avoid adding more dependencies between the classes. There are too many already.

        Overrides:
        getCurrentEnsemble in class LedgerHandle