use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException in project bookkeeper by apache.
the class AbstractStateStoreWithJournal method getLastDLSN.
private CompletableFuture<DLSN> getLastDLSN(StateStoreSpec spec) {
synchronized (this) {
if (null != closeFuture) {
return FutureUtils.exception(new StateStoreClosedException(name()));
}
}
try {
logManager = logNamespace.openLog(spec.getStream());
} catch (IOException e) {
return FutureUtils.exception(e);
}
CompletableFuture<DLSN> future = FutureUtils.createFuture();
logManager.getLastDLSNAsync().whenCompleteAsync(new FutureEventListener<DLSN>() {
@Override
public void onSuccess(DLSN dlsn) {
future.complete(dlsn);
}
@Override
public void onFailure(Throwable throwable) {
if (throwable instanceof LogEmptyException || throwable instanceof LogNotFoundException) {
FutureUtils.proxyTo(writeCatchUpMarker(), future);
} else {
future.completeExceptionally(throwable);
}
}
});
return future;
}
use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException in project bookkeeper by apache.
the class AbstractStateStoreWithJournal method initializeJournalWriter.
private CompletableFuture<DLSN> initializeJournalWriter(StateStoreSpec spec) {
synchronized (this) {
if (null != closeFuture) {
return FutureUtils.exception(new StateStoreClosedException(name()));
}
}
try {
logManager = logNamespace.openLog(spec.getStream());
} catch (IOException e) {
return FutureUtils.exception(e);
}
return logManager.openAsyncLogWriter().thenComposeAsync(w -> {
synchronized (this) {
writer = w;
nextRevision = writer.getLastTxId();
if (nextRevision < 0) {
nextRevision = 0L;
}
log.info("Initialized the journal writer for mvcc store {} : last revision = {}", name(), nextRevision);
}
return writeCommandBuf(newCatchupMarker());
}, writeIOScheduler);
}
use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException in project bookkeeper by apache.
the class AbstractStateStoreWithJournal method executeIO.
private <T> CompletableFuture<T> executeIO(ScheduledExecutorService scheduler, Callable<T> callable) {
synchronized (this) {
if (null != closeFuture) {
return FutureUtils.exception(new StateStoreClosedException(name()));
}
}
CompletableFuture<T> future = FutureUtils.createFuture();
scheduler.submit(() -> {
try {
T value = callable.call();
future.complete(value);
} catch (Exception e) {
future.completeExceptionally(e);
}
});
return future;
}
Aggregations