@Override public void onSuccess(AsyncLogReader reader) { acquiredLatch.countDown(); reader.asyncClose(); } @Override
private void closeReader() { if (null != reader) { reader.asyncClose().onFailure(new AbstractFunction1<Throwable, BoxedUnit>() { @Override public BoxedUnit apply(Throwable cause) { LOG.warn("Exception on closing reader {} : ", readerName, cause); return BoxedUnit.UNIT; } }); } }
@Override public Future<Void> applyE(AsyncLogReader reader) throws IOException { return reader.asyncClose().map(new AbstractFunction1<Void, Void>() { @Override public Void apply(Void result) { latch.countDown(); return null; } }); } });
private static void readLoop(final DistributedLogManager dlm, final DLSN dlsn) throws Exception { final CountDownLatch keepAliveLatch = new CountDownLatch(1); System.out.println("Wait for records starting from " + dlsn); final AsyncLogReader reader = FutureUtils.result(dlm.openAsyncLogReader(dlsn)); final FutureEventListener<LogRecordWithDLSN> readListener = new FutureEventListener<LogRecordWithDLSN>() { @Override public void onFailure(Throwable cause) { System.err.println("Encountered error on reading records from stream " + dlm.getStreamName()); cause.printStackTrace(System.err); keepAliveLatch.countDown(); } @Override public void onSuccess(LogRecordWithDLSN record) { System.out.println("Received record " + record.getDlsn()); System.out.println("\"\"\""); System.out.println(new String(record.getPayload(), UTF_8)); System.out.println("\"\"\""); reader.readNext().addEventListener(this); } }; reader.readNext().addEventListener(readListener); keepAliveLatch.await(); FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS)); }
private static void readLoop(final DistributedLogManager dlm, final DLSN dlsn, final AtomicReference<DLSN> lastDLSN) throws Exception { final CountDownLatch keepAliveLatch = new CountDownLatch(1); System.out.println("Wait for records starting from " + dlsn); final AsyncLogReader reader = FutureUtils.result(dlm.openAsyncLogReader(dlsn)); final FutureEventListener<LogRecordWithDLSN> readListener = new FutureEventListener<LogRecordWithDLSN>() { @Override public void onFailure(Throwable cause) { System.err.println("Encountered error on reading records from stream " + dlm.getStreamName()); cause.printStackTrace(System.err); keepAliveLatch.countDown(); } @Override public void onSuccess(LogRecordWithDLSN record) { System.out.println("Received record " + record.getDlsn()); System.out.println("\"\"\""); System.out.println(new String(record.getPayload(), UTF_8)); System.out.println("\"\"\""); lastDLSN.set(record.getDlsn()); reader.readNext().addEventListener(this); } }; reader.readNext().addEventListener(readListener); keepAliveLatch.await(); FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS)); }
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
FutureUtils.result(logReaders[idx].asyncClose()); } catch (IOException e) { LOG.warn("Failed on closing stream reader {} : ", streamName, e);
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
@Override public void close() throws IOException { this.running = false; for (AsyncLogReader reader : logReaders) { if (null != reader) { FutureUtils.result(reader.asyncClose()); } } for (DistributedLogManager dlm : dlms) { if (null != dlm) { dlm.close(); } } namespace.close(); SchedulerUtils.shutdownScheduler(executorService, 2, TimeUnit.MINUTES); SchedulerUtils.shutdownScheduler(callbackExecutor, 2, TimeUnit.MINUTES); if (this.dlc != null) { this.dlc.close(); } for (DLZkServerSet serverSet: serverSets) { serverSet.close(); } }
reader.asyncClose(); dlm.close();
private static void readLoop(final DistributedLogManager dlm, final DLSN dlsn, final AtomicReference<DLSN> lastDLSN) throws Exception { final CountDownLatch keepAliveLatch = new CountDownLatch(1); System.out.println("Wait for records starting from " + dlsn); final AsyncLogReader reader = FutureUtils.result(dlm.openAsyncLogReader(dlsn)); final FutureEventListener<LogRecordWithDLSN> readListener = new FutureEventListener<LogRecordWithDLSN>() { @Override public void onFailure(Throwable cause) { System.err.println("Encountered error on reading records from stream " + dlm.getStreamName()); cause.printStackTrace(System.err); keepAliveLatch.countDown(); } @Override public void onSuccess(LogRecordWithDLSN record) { System.out.println("Received record " + record.getDlsn()); System.out.println("\"\"\""); System.out.println(new String(record.getPayload(), UTF_8)); System.out.println("\"\"\""); lastDLSN.set(record.getDlsn()); reader.readNext().addEventListener(this); } }; reader.readNext().addEventListener(readListener); keepAliveLatch.await(); FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS)); }
FutureUtils.result(reader.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));