This project has retired. For details please refer to its Attic page.
DefaultArchivaRuntimeConfigurationService xref
View Javadoc
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  
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.redback.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;
31  
32  import javax.inject.Inject;
33  import javax.inject.Named;
34  
35  /**
36   * @author Olivier Lamy
37   * @since 1.4-M4
38   */
39  @Service( "archivaRuntimeConfigurationService#rest" )
40  public class DefaultArchivaRuntimeConfigurationService
41      extends AbstractRestService
42      implements ArchivaRuntimeConfigurationService
43  {
44      @Inject
45      private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
46  
47      @Inject
48      @Named( value = "cache#url-failures-cache" )
49      private Cache usersCache;
50  
51      @Inject
52      @Named( value = "fileLockManager#default" )
53      private FileLockManager fileLockManager;
54  
55      @Override
56      public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
57          throws ArchivaRestServiceException
58      {
59          try
60          {
61              return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration();
62          }
63          catch ( RepositoryAdminException e )
64          {
65              throw new ArchivaRestServiceException( e.getMessage(), e );
66          }
67      }
68  
69      @Override
70      public Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
71          throws ArchivaRestServiceException
72      {
73          try
74          {
75              archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
76              CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration();
77              if ( cacheConfiguration != null )
78              {
79                  usersCache.setTimeToLiveSeconds( cacheConfiguration.getTimeToLiveSeconds() );
80                  usersCache.setTimeToIdleSeconds( cacheConfiguration.getTimeToIdleSeconds() );
81                  usersCache.setMaxElementsOnDisk( cacheConfiguration.getMaxElementsOnDisk() );
82                  usersCache.setMaxElementsInMemory( cacheConfiguration.getMaxElementsInMemory() );
83              }
84  
85              FileLockConfiguration fileLockConfiguration = archivaRuntimeConfiguration.getFileLockConfiguration();
86              if ( fileLockConfiguration != null )
87              {
88                  fileLockManager.setTimeout( fileLockConfiguration.getLockingTimeout() );
89                  fileLockManager.setSkipLocking( fileLockConfiguration.isSkipLocking() );
90              }
91  
92  
93          }
94          catch ( RepositoryAdminException e )
95          {
96              throw new ArchivaRestServiceException( e.getMessage(), e );
97          }
98          return Boolean.TRUE;
99      }
100 }