1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
23 import org.apache.archiva.admin.model.beans.CacheConfiguration;
24 import org.apache.archiva.admin.model.beans.FileLockConfiguration;
25 import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
26 import org.apache.archiva.common.filelock.FileLockManager;
27 import org.apache.archiva.components.cache.Cache;
28 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
29 import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
30 import org.springframework.stereotype.Service;
32 import javax.inject.Inject;
33 import javax.inject.Named;
36 * @author Olivier Lamy
39 @Service( "archivaRuntimeConfigurationService#rest" )
40 public class DefaultArchivaRuntimeConfigurationService
41 extends AbstractRestService
42 implements ArchivaRuntimeConfigurationService
45 private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
48 @Named( value = "cache#url-failures-cache" )
49 private Cache usersCache;
52 @Named( value = "fileLockManager#default" )
53 private FileLockManager fileLockManager;
56 public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
57 throws ArchivaRestServiceException
61 return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration();
63 catch ( RepositoryAdminException e )
65 throw new ArchivaRestServiceException( e.getMessage(), e );
70 public Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
71 throws ArchivaRestServiceException
75 archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
76 CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration();
77 if ( cacheConfiguration != null )
79 usersCache.setTimeToLiveSeconds( cacheConfiguration.getTimeToLiveSeconds() );
80 usersCache.setTimeToIdleSeconds( cacheConfiguration.getTimeToIdleSeconds() );
81 usersCache.setMaxElementsOnDisk( cacheConfiguration.getMaxElementsOnDisk() );
82 usersCache.setMaxElementsInMemory( cacheConfiguration.getMaxElementsInMemory() );
85 FileLockConfiguration fileLockConfiguration = archivaRuntimeConfiguration.getFileLockConfiguration();
86 if ( fileLockConfiguration != null )
88 fileLockManager.setTimeout( fileLockConfiguration.getLockingTimeout() );
89 fileLockManager.setSkipLocking( fileLockConfiguration.isSkipLocking() );
94 catch ( RepositoryAdminException e )
96 throw new ArchivaRestServiceException( e.getMessage(), e );