borgbutler-core/src/main/java/de/micromata/borgbutler/data/Repository.java
@@ -11,6 +11,8 @@ import org.slf4j.LoggerFactory; import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.SortedSet; import java.util.TreeSet; @@ -69,15 +71,18 @@ /** * Might be null. */ @Getter @Setter private SortedSet<Archive> archives; public Repository add(Archive archive) { synchronized (this) { if (this.archives == null) { this.archives = new TreeSet<>(); } } synchronized (this.archives) { this.archives.add(archive); } return this; } @@ -86,11 +91,13 @@ log.warn("Can't get archive '" + idOrName + "' from repository '" + name + "'. Archives not yet loaded or don't exist."); return null; } synchronized (this.archives) { for (Archive archive : archives) { if (StringUtils.equals(idOrName, archive.getId()) || StringUtils.equals(idOrName, archive.getName())) { return archive; } } } log.warn("Archive '" + idOrName + "' not found in repository '" + name + "'."); return null; } @@ -103,4 +110,13 @@ public boolean isArchivesLoaded() { return CollectionUtils.isNotEmpty(archives); } public Collection<Archive> getArchives() { if (this.archives == null) { return null; } synchronized (this.archives) { return Collections.unmodifiableSet(this.archives); } } } borgbutler-core/src/main/java/de/micromata/borgbutler/jobs/JobQueue.java
@@ -1,7 +1,6 @@ package de.micromata.borgbutler.jobs; import lombok.Getter; import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +22,10 @@ } public List<AbstractJob<T>> getDoneJobs() { synchronized (doneJobs) { return Collections.unmodifiableList(doneJobs); } } /** * Appends the job if not alread in the queue. Starts the execution if no execution thread is already running. @@ -41,31 +42,22 @@ } } queue.add(job.setStatus(AbstractJob.Status.QUEUED)); } job.setFuture(executorService.submit(new CallableTask(job))); return job; } } public AbstractJob getQueuedJob(Object id) { synchronized (queue) { for (AbstractJob job : queue) { if (Objects.equals(job.getId(), id)) { return job; } } } return null; } void waitForQueue(int seconds) { int counter = seconds / 10; while (CollectionUtils.isNotEmpty(queue) && counter > 0) { try { Thread.sleep(100); } catch (InterruptedException ex) { log.error(ex.getMessage(), ex); } } } private void organizeQueue() { synchronized (queue) { if (queue.isEmpty()) { @@ -76,8 +68,11 @@ AbstractJob<T> job = it.next(); if (job.isFinished()) { it.remove(); synchronized (doneJobs) { doneJobs.add(0, job); } } synchronized (doneJobs) { while (doneJobs.size() > MAX_DONE_JOBS_SIZE) { doneJobs.remove(doneJobs.size() - 1); } @@ -85,6 +80,9 @@ } } } private class CallableTask implements Callable<JobResult<T>> { private AbstractJob<T> job; borgbutler-core/src/test/java/de/micromata/borgbutler/cache/CacheTest.java
@@ -48,7 +48,7 @@ repoConfig = repoConfigs.get(0); Repository rerepositoryoList = ButlerCache.getInstance().getRepositoryArchives(repoConfig.getRepo()); if (rerepositoryoList != null && CollectionUtils.isNotEmpty(rerepositoryoList.getArchives())) { archive = rerepositoryoList.getArchives().first(); archive = rerepositoryoList.getArchives().iterator().next(); } } {