You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractRepositoryGroup.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package org.apache.archiva.repository;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.repository.storage.RepositoryStorage;
  21. import org.apache.commons.collections4.map.ListOrderedMap;
  22. import java.util.List;
  23. import java.util.Locale;
  24. import java.util.concurrent.locks.ReadWriteLock;
  25. import java.util.concurrent.locks.ReentrantReadWriteLock;
  26. /**
  27. * Abstract repository group implementation.
  28. *
  29. */
  30. public class AbstractRepositoryGroup extends AbstractRepository implements EditableRepositoryGroup {
  31. private ListOrderedMap<String, ManagedRepository> repositories = new ListOrderedMap<>();
  32. private int mergedIndexTTL;
  33. private final ReadWriteLock rwl = new ReentrantReadWriteLock();
  34. private RepositoryCapabilities capabilities;
  35. public AbstractRepositoryGroup(RepositoryType type, String id, String name, RepositoryStorage storage) {
  36. super(type, id, name, storage);
  37. }
  38. public AbstractRepositoryGroup(Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage) {
  39. super(primaryLocale, type, id, name, storage);
  40. }
  41. @Override
  42. public boolean hasIndex() {
  43. return true;
  44. }
  45. @Override
  46. public RepositoryCapabilities getCapabilities() {
  47. return capabilities;
  48. }
  49. @Override
  50. public void clearRepositories() {
  51. rwl.writeLock().lock();
  52. try {
  53. repositories.clear();
  54. } finally {
  55. rwl.writeLock().unlock();
  56. }
  57. }
  58. @Override
  59. public void setRepositories(List<ManagedRepository> newRepositories) {
  60. rwl.writeLock().lock();
  61. try {
  62. repositories.clear();
  63. for(ManagedRepository repo : newRepositories) {
  64. if (repo!=null)
  65. repositories.put(repo.getId(), repo);
  66. }
  67. } finally {
  68. rwl.writeLock().unlock();
  69. }
  70. }
  71. @Override
  72. public void addRepository(ManagedRepository repository) {
  73. rwl.writeLock().lock();
  74. try {
  75. if (repository!=null)
  76. repositories.put(repository.getId(), repository);
  77. } finally {
  78. rwl.writeLock().unlock();
  79. }
  80. }
  81. @Override
  82. public void addRepository(int index, ManagedRepository repository) {
  83. rwl.writeLock().lock();
  84. try {
  85. if (repository!=null)
  86. repositories.put(index, repository.getId(), repository);
  87. } finally {
  88. rwl.writeLock().unlock();
  89. }
  90. }
  91. @Override
  92. public boolean removeRepository(ManagedRepository repository) {
  93. rwl.writeLock().lock();
  94. try {
  95. return repositories.remove(repository.getId(), repository);
  96. } finally {
  97. rwl.writeLock().unlock();
  98. }
  99. }
  100. @Override
  101. public ManagedRepository removeRepository(String repoId) {
  102. rwl.writeLock().lock();
  103. try {
  104. return repositories.remove(repoId);
  105. } finally {
  106. rwl.writeLock().unlock();
  107. }
  108. }
  109. @Override
  110. public void setMergedIndexTTL(int timeInSeconds) {
  111. this.mergedIndexTTL = timeInSeconds;
  112. }
  113. @Override
  114. public List<ManagedRepository> getRepositories() {
  115. rwl.readLock().lock();
  116. try {
  117. return repositories.valueList();
  118. } finally {
  119. rwl.readLock().unlock();
  120. }
  121. }
  122. @Override
  123. public boolean contains(ManagedRepository repository) {
  124. rwl.readLock().lock();
  125. try {
  126. return repositories.containsValue(repository);
  127. } finally {
  128. rwl.readLock().unlock();
  129. }
  130. }
  131. @Override
  132. public boolean contains(String id) {
  133. rwl.readLock().lock();
  134. try {
  135. return repositories.containsKey(id);
  136. } finally {
  137. rwl.readLock().unlock();
  138. }
  139. }
  140. @Override
  141. public int getMergedIndexTTL() {
  142. return mergedIndexTTL;
  143. }
  144. protected void setCapabilities(RepositoryCapabilities capabilities) {
  145. this.capabilities = capabilities;
  146. }
  147. }