congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ReadHandle.readAsync
Code IndexAdd Tabnine to your IDE (free)

How to use
readAsync
method
in
org.apache.bookkeeper.client.api.ReadHandle

Best Java code snippets using org.apache.bookkeeper.client.api.ReadHandle.readAsync (Showing top 12 results out of 315)

origin: apache/pulsar

@Override
public CompletableFuture<LedgerEntries> readAsync(long firstEntry, long lastEntry) {
  return readHandle.readAsync(firstEntry, lastEntry);
}
origin: apache/pulsar

@Override
public void asyncReadEntry(ReadHandle lh, long firstEntry, long lastEntry, boolean isSlowestReader,
    final ReadEntriesCallback callback, Object ctx) {
  lh.readAsync(firstEntry, lastEntry).whenComplete(
      (ledgerEntries, exception) -> {
        if (exception != null) {
          callback.readEntriesFailed(createManagedLedgerException(exception), ctx);
          return;
        }
        List<Entry> entries = Lists.newArrayList();
        long totalSize = 0;
        try {
          for (LedgerEntry e : ledgerEntries) {
            // Insert the entries at the end of the list (they will be unsorted for now)
            EntryImpl entry = EntryImpl.create(e);
            entries.add(entry);
            totalSize += entry.getLength();
          }
        } finally {
          ledgerEntries.close();
        }
        mlFactoryMBean.recordCacheMiss(entries.size(), totalSize);
        ml.mbean.addReadEntriesSample(entries.size(), totalSize);
        callback.readEntriesComplete(entries, null);
      });
}
origin: apache/pulsar

private static ReadHandle getLedgerHandle() {
  final ReadHandle lh = mock(ReadHandle.class);
  final LedgerEntry ledgerEntry = mock(LedgerEntry.class, Mockito.CALLS_REAL_METHODS);
  doReturn(Unpooled.wrappedBuffer(new byte[10])).when(ledgerEntry).getEntryBuffer();
  doReturn((long) 10).when(ledgerEntry).getLength();
  doAnswer((invocation) -> {
      Object[] args = invocation.getArguments();
      long firstEntry = (Long) args[0];
      long lastEntry = (Long) args[1];
      Vector<LedgerEntry> entries = new Vector<LedgerEntry>();
      for (int i = 0; i <= (lastEntry - firstEntry); i++) {
        entries.add(ledgerEntry);
      }
      LedgerEntries ledgerEntries = mock(LedgerEntries.class);
      doAnswer((invocation2) -> entries.iterator()).when(ledgerEntries).iterator();
      return CompletableFuture.completedFuture(ledgerEntries);
    }).when(lh).readAsync(anyLong(), anyLong());
  return lh;
}
origin: apache/pulsar

@Test(timeOut = 5000)
void testReadWithError() throws Exception {
  final ReadHandle lh = getLedgerHandle();
  when(lh.getId()).thenReturn((long) 0);
  doAnswer((invocation) -> {
      CompletableFuture<LedgerEntries> future = new CompletableFuture<>();
      future.completeExceptionally(new BKNoSuchLedgerExistsException());
      return future;
    }).when(lh).readAsync(anyLong(), anyLong());
  EntryCacheManager cacheManager = factory.getEntryCacheManager();
  EntryCache entryCache = cacheManager.getEntryCache(ml);
  byte[] data = new byte[10];
  entryCache.insert(EntryImpl.create(0, 2, data));
  final CountDownLatch counter = new CountDownLatch(1);
  entryCache.asyncReadEntry(lh, 0, 9, false, new ReadEntriesCallback() {
    public void readEntriesComplete(List<Entry> entries, Object ctx) {
      Assert.fail("should not complete");
    }
    public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
      counter.countDown();
    }
  }, null);
  counter.await();
}
origin: apache/pulsar

lh.readAsync(firstEntry, lastEntry).whenCompleteAsync(
    (ledgerEntries, exception) -> {
      if (exception != null) {
origin: apache/pulsar

@Test(timeOut = 5000)
void testRead() throws Exception {
  ReadHandle lh = getLedgerHandle();
  when(lh.getId()).thenReturn((long) 0);
  EntryCacheManager cacheManager = factory.getEntryCacheManager();
  EntryCache entryCache = cacheManager.getEntryCache(ml);
  byte[] data = new byte[10];
  for (int i = 0; i < 10; i++) {
    entryCache.insert(EntryImpl.create(0, i, data));
  }
  final CountDownLatch counter = new CountDownLatch(1);
  entryCache.asyncReadEntry(lh, 0, 9, false, new ReadEntriesCallback() {
    public void readEntriesComplete(List<Entry> entries, Object ctx) {
      assertEquals(entries.size(), 10);
      entries.forEach(e -> e.release());
      counter.countDown();
    }
    public void readEntriesFailed(ManagedLedgerException exception, Object ctx) {
      Assert.fail("should not have failed");
    }
  }, null);
  counter.await();
  // Verify no entries were read from bookkeeper
  verify(lh, never()).readAsync(anyLong(), anyLong());
}
origin: apache/pulsar

doReturn(entriesFuture).when(ledgerHandle).readAsync(PositionImpl.earliest.getLedgerId(),
    PositionImpl.earliest.getEntryId());
origin: apache/pulsar

  callback.readEntryComplete(cachedEntry, ctx);
} else {
  lh.readAsync(position.getEntryId(), position.getEntryId()).whenCompleteAsync(
      (ledgerEntries, exception) -> {
        if (exception != null) {
origin: org.apache.bookkeeper/bookkeeper-server

/**
 * Read a sequence of entries synchronously.
 *
 * @param firstEntry
 *          id of first entry of sequence
 * @param lastEntry
 *          id of last entry of sequence, inclusive
 * @return the result of the operation
 */
default LedgerEntries read(long firstEntry, long lastEntry) throws BKException, InterruptedException {
  return FutureUtils.<LedgerEntries, BKException>result(readAsync(firstEntry, lastEntry),
                             BKException.HANDLER);
}
origin: org.apache.pulsar/managed-ledger-original

@Override
public void asyncReadEntry(ReadHandle lh, long firstEntry, long lastEntry, boolean isSlowestReader,
    final ReadEntriesCallback callback, Object ctx) {
  lh.readAsync(firstEntry, lastEntry).whenComplete(
      (ledgerEntries, exception) -> {
        if (exception != null) {
          callback.readEntriesFailed(createManagedLedgerException(exception), ctx);
          return;
        }
        List<Entry> entries = Lists.newArrayList();
        long totalSize = 0;
        try {
          for (LedgerEntry e : ledgerEntries) {
            // Insert the entries at the end of the list (they will be unsorted for now)
            EntryImpl entry = EntryImpl.create(e);
            entries.add(entry);
            totalSize += entry.getLength();
          }
        } finally {
          ledgerEntries.close();
        }
        mlFactoryMBean.recordCacheMiss(entries.size(), totalSize);
        ml.mbean.addReadEntriesSample(entries.size(), totalSize);
        callback.readEntriesComplete(entries, null);
      });
}
origin: org.apache.pulsar/managed-ledger-original

lh.readAsync(firstEntry, lastEntry).whenCompleteAsync(
    (ledgerEntries, exception) -> {
      if (exception != null) {
origin: org.apache.pulsar/managed-ledger-original

  callback.readEntryComplete(cachedEntry, ctx);
} else {
  lh.readAsync(position.getEntryId(), position.getEntryId()).whenCompleteAsync(
      (ledgerEntries, exception) -> {
        if (exception != null) {
org.apache.bookkeeper.client.apiReadHandlereadAsync

Javadoc

Read a sequence of entries asynchronously.

Popular methods of ReadHandle

  • readLastAddConfirmedAsync
    Obtains asynchronously the last confirmed write from a quorum of bookies. This call obtains the the
  • getId
  • getLastAddConfirmed
    Get the last confirmed entry id on this ledger. It reads the local state of the ledger handle, which
  • readLastAddConfirmedAndEntryAsync
    Asynchronous read specific entry and the latest last add confirmed. If the next entryId is less than
  • readUnconfirmedAsync
    Read a sequence of entries asynchronously, allowing to read after the LastAddConfirmed range. This i
  • tryReadLastAddConfirmedAsync
    Obtains asynchronously the last confirmed write from a quorum of bookies but it doesn't wait all the
  • getLedgerMetadata
  • getLength
    Returns the length of the data written in this ledger so much, in bytes.
  • isClosed
    Returns whether the ledger is sealed or not.A ledger is sealed when either the client explicitly clo
  • read
    Read a sequence of entries synchronously.

Popular in Java

  • Making http post requests using okhttp
  • compareTo (BigDecimal)
  • startActivity (Activity)
  • setScale (BigDecimal)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now