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.9KB

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