Source:
<code>public synchronized void start() { setDaemon(true); if (LOG.isDebugEnabled()) { LOG.debug("I'm starting a bookie with journal directories {}", journalDirectories.stream().map(File::getName).collect(Collectors.joining(", "))); } ledgerMonitor.start(); if (indexDirsManager != ledgerDirsManager) { idxMonitor.start(); } try { readJournal(); } catch (IOException ioe) { LOG.error("Exception while replaying journals, shutting down", ioe); shutdown(ExitCode.BOOKIE_EXCEPTION); return; } catch (BookieException be) { LOG.error("Exception while replaying journals, shutting down", be); shutdown(ExitCode.BOOKIE_EXCEPTION); return; } try { syncThread.requestFlush().get(); } catch (InterruptedException e) { LOG.warn("Interrupting the fully flush after replaying journals : ", e); Thread.currentThread().interrupt(); } catch (ExecutionException e) { LOG.error("Error on executing a fully flush after replaying journals."); shutdown(ExitCode.BOOKIE_EXCEPTION); } LOG.info("Finished reading journal, starting bookie"); super.start(); ledgerDirsManager.addLedgerDirsListener(getLedgerDirsListener()); if (indexDirsManager != ledgerDirsManager) { indexDirsManager.addLedgerDirsListener(getLedgerDirsListener()); } ledgerStorage.start(); if (ledgerStorage instanceof SortedLedgerStorage){ <START> ((SortedLedgerStorage) ledgerStorage).addSortedLedgerStorageListener(getSortedLedgerStorageListener()); <END> } if (forceReadOnly.get()) { this.bookieStatus.setToReadOnlyMode(); } else if (conf.isPersistBookieStatusEnabled()) { this.bookieStatus.readFromDirectories(ledgerDirsManager.getAllLedgerDirs()); } running = true; try { registerBookie(true).get(); } catch (Exception e) { LOG.error("Couldn't register bookie with zookeeper, shutting down : ", e); shutdown(ExitCode.ZK_REG_FAIL); } }</code><technical_language>This is good, is bad practice instanceof in this case. a common interface</technical_language>

Target:
public synchronized void start() { setDaemon(true); if (LOG.isDebugEnabled()) { LOG.debug("I'm starting a bookie with journal directories {}", journalDirectories.stream().map(File::getName).collect(Collectors.joining(", "))); } ledgerMonitor.start(); if (indexDirsManager != ledgerDirsManager) { idxMonitor.start(); } try { readJournal(); } catch (IOException ioe) { LOG.error("Exception while replaying journals, shutting down", ioe); shutdown(ExitCode.BOOKIE_EXCEPTION); return; } catch (BookieException be) { LOG.error("Exception while replaying journals, shutting down", be); shutdown(ExitCode.BOOKIE_EXCEPTION); return; } try { syncThread.requestFlush().get(); } catch (InterruptedException e) { LOG.warn("Interrupting the fully flush after replaying journals : ", e); Thread.currentThread().interrupt(); } catch (ExecutionException e) { LOG.error("Error on executing a fully flush after replaying journals."); shutdown(ExitCode.BOOKIE_EXCEPTION); } LOG.info("Finished reading journal, starting bookie"); super.start(); ledgerDirsManager.addLedgerDirsListener(getLedgerDirsListener()); if (indexDirsManager != ledgerDirsManager) { indexDirsManager.addLedgerDirsListener(getLedgerDirsListener()); } ledgerStorage.start(); stateManager.initState(); try { stateManager.registerBookie(true).get(); } catch (Exception e) { LOG.error("Couldn't register bookie with zookeeper, shutting down : ", e); shutdown(ExitCode.ZK_REG_FAIL); } }