@Override
public void run() {
long startedAt = System.currentTimeMillis();
while (!stop && !Thread.interrupted()) {
RepositoryModelEvent event = null;
try {
while (!stop && event == null) {
event = eventQueue.poll(1000, TimeUnit.MILLISECONDS);
}
if (stop || event == null || Thread.interrupted()) {
return;
}
// Warn if the queue is getting large, but do not do this just after we started, because
// on initial startup a fake update event is added for every defined index, which would lead
// to this message always being printed on startup when more than 10 indexes are defined.
int queueSize = eventQueue.size();
if (queueSize >= 10 && (System.currentTimeMillis() - startedAt > 5000)) {
log.warn("EventWorker queue getting large, size = " + queueSize);
}
try {
RepositoryDefinition repoDef = repositoryModel.getRepository(event.getRepositoryName());
if (repoDef.getLifecycleState() == RepositoryLifecycleState.CREATE_REQUESTED) {
for (RepositoryMasterHook hook : hooks) {
try {
hook.postCreate(repoDef.getName());
} catch (InterruptedException e) {
return;
} catch (Throwable t) {
log.error("Failure executing a repository post-create hook for "
+ event.getRepositoryName(), t);
}
}
RepositoryDefinition updatedRepoDef = new RepositoryDefinition(repoDef.getName(),
RepositoryLifecycleState.ACTIVE);
repositoryModel.updateRepository(updatedRepoDef);
} else if (repoDef.getLifecycleState() == RepositoryLifecycleState.DELETE_REQUESTED) {
for (RepositoryMasterHook hook : hooks) {
try {
hook.preDelete(repoDef.getName());
} catch (InterruptedException e) {
return;
} catch (Throwable t) {
log.error("Failure executing a repository pre-delete hook for "
+ event.getRepositoryName(), t);
}
}
repositoryModel.deleteDirect(repoDef.getName());
}
} catch (RepositoryNotFoundException e) {