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.

DefaultArchivaRuntimeConfigurationService.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package org.apache.archiva.rest.services;
  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.admin.model.RepositoryAdminException;
  21. import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
  22. import org.apache.archiva.admin.model.beans.CacheConfiguration;
  23. import org.apache.archiva.admin.model.beans.FileLockConfiguration;
  24. import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
  25. import org.apache.archiva.common.filelock.FileLockManager;
  26. import org.apache.archiva.redback.components.cache.Cache;
  27. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  28. import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
  29. import org.springframework.stereotype.Service;
  30. import javax.inject.Inject;
  31. import javax.inject.Named;
  32. /**
  33. * @author Olivier Lamy
  34. * @since 1.4-M4
  35. */
  36. @Service( "archivaRuntimeConfigurationService#rest" )
  37. public class DefaultArchivaRuntimeConfigurationService
  38. extends AbstractRestService
  39. implements ArchivaRuntimeConfigurationService
  40. {
  41. @Inject
  42. private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
  43. @Inject
  44. @Named( value = "cache#url-failures-cache" )
  45. private Cache usersCache;
  46. @Inject
  47. @Named( value = "fileLockManager#default" )
  48. private FileLockManager fileLockManager;
  49. @Override
  50. public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
  51. throws ArchivaRestServiceException
  52. {
  53. try
  54. {
  55. return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration();
  56. }
  57. catch ( RepositoryAdminException e )
  58. {
  59. throw new ArchivaRestServiceException( e.getMessage(), e );
  60. }
  61. }
  62. @Override
  63. public Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
  64. throws ArchivaRestServiceException
  65. {
  66. try
  67. {
  68. archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
  69. CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration();
  70. if ( cacheConfiguration != null )
  71. {
  72. usersCache.setTimeToLiveSeconds( cacheConfiguration.getTimeToLiveSeconds() );
  73. usersCache.setTimeToIdleSeconds( cacheConfiguration.getTimeToIdleSeconds() );
  74. usersCache.setMaxElementsOnDisk( cacheConfiguration.getMaxElementsOnDisk() );
  75. usersCache.setMaxElementsInMemory( cacheConfiguration.getMaxElementsInMemory() );
  76. }
  77. FileLockConfiguration fileLockConfiguration = archivaRuntimeConfiguration.getFileLockConfiguration();
  78. if ( fileLockConfiguration != null )
  79. {
  80. fileLockManager.setTimeout( fileLockConfiguration.getLockingTimeout() );
  81. fileLockManager.setSkipLocking( fileLockConfiguration.isSkipLocking() );
  82. }
  83. }
  84. catch ( RepositoryAdminException e )
  85. {
  86. throw new ArchivaRestServiceException( e.getMessage(), e );
  87. }
  88. return Boolean.TRUE;
  89. }
  90. }