Created
April 2, 2019 12:54
-
-
Save ivankelly/65c999a1a3a280eea7e5b27e0a5a361b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ackage org.apache.bookkeeper.client; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class LongPollTest { | |
public static final Logger log = LoggerFactory.getLogger(LongPollTest.class); | |
public static void main(String[] args) throws Exception { | |
BookKeeper bkc = new BookKeeper("localhost:2181"); | |
log.info("Writing"); | |
LedgerHandle write = bkc.createLedger(1,1,1, BookKeeper.DigestType.CRC32, "foobar".getBytes()); | |
for (int i = 0; i < 100; i++) { | |
write.addEntry("foobar".getBytes()); | |
} | |
log.info("long pollin"); | |
for (int i = 0; i < 100; i++) { | |
Thread t = new Thread(() -> { | |
try { | |
LedgerHandle read = bkc.openLedgerNoRecovery(write.getId(), | |
BookKeeper.DigestType.CRC32, "foobar".getBytes()); | |
long lac = 0; | |
while (true) { | |
lac = read.readLastAddConfirmedAndEntryAsync(lac+1, 1, false).get().getLastAddConfirmed(); | |
} | |
} catch (Throwable ex) { | |
log.error("Caught error", ex); | |
System.exit(-10); | |
} | |
}); | |
t.start(); | |
} | |
while (true) { | |
Thread.sleep(100); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment