1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.examples.indexing;
20
21 import javax.annotation.PreDestroy;
22 import javax.inject.Singleton;
23
24 import java.io.IOException;
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.stereotype.Component;
31
32
33
34
35
36
37 @Singleton
38 @Component
39 public class RepositoryIndexManager {
40
41 private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryIndexManager.class);
42
43
44
45
46
47 private Map<String, RepositoryIndexer> indexes = new LinkedHashMap<>();
48
49 public RepositoryIndexManager() {
50
51 }
52
53
54
55
56
57
58
59 @PreDestroy
60 private void close() {
61 for (String repositoryId : indexes.keySet()) {
62 try {
63 final RepositoryIndexer repositoryIndexer = indexes.get(repositoryId);
64
65 LOGGER.debug("Closing indexer for " + repositoryIndexer.getRepositoryId() + "...");
66
67 repositoryIndexer.close();
68
69 LOGGER.debug("Closed indexer for " + repositoryIndexer.getRepositoryId() + ".");
70 } catch (IOException e) {
71 LOGGER.error(e.getMessage(), e);
72 }
73 }
74 }
75
76 public Map<String, RepositoryIndexer> getIndexes() {
77 return indexes;
78 }
79
80 public void setIndexes(Map<String, RepositoryIndexer> indexes) {
81 this.indexes = indexes;
82 }
83
84 public RepositoryIndexer getRepositoryIndex(String repositoryId) {
85 return indexes.get(repositoryId);
86 }
87
88 public RepositoryIndexer addRepositoryIndex(String repositoryId, RepositoryIndexer value) {
89 return indexes.put(repositoryId, value);
90 }
91
92 public RepositoryIndexer removeRepositoryIndex(String repositoryId) {
93 return indexes.remove(repositoryId);
94 }
95 }