1 package org.apache.archiva.webdav.util;
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.indexer.merger.IndexMerger;
22 import org.apache.archiva.indexer.merger.TemporaryGroupIndex;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.web.context.WebApplicationContext;
26 import org.springframework.web.context.support.WebApplicationContextUtils;
28 import javax.servlet.http.HttpSessionEvent;
29 import javax.servlet.http.HttpSessionListener;
30 import java.util.HashMap;
34 * this http session listener will delete repository group index requested by a user
35 * at this end of the http session
37 * @author Olivier Lamy
40 public class TemporaryGroupIndexSessionCleaner
41 implements HttpSessionListener
44 private Logger log = LoggerFactory.getLogger( getClass() );
46 private IndexMerger indexMerger;
48 public static final String TEMPORARY_INDEX_SESSION_KEY = TemporaryGroupIndexSessionCleaner.class.getName();
50 public void sessionCreated( HttpSessionEvent httpSessionEvent )
52 // ensure the map is here to avoid NPE
53 httpSessionEvent.getSession().setAttribute( TEMPORARY_INDEX_SESSION_KEY,
54 new HashMap<String, TemporaryGroupIndex>() );
55 WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(
56 httpSessionEvent.getSession().getServletContext() );
57 indexMerger = webApplicationContext.getBean( IndexMerger.class );
60 public void sessionDestroyed( HttpSessionEvent httpSessionEvent )
62 Map<String, TemporaryGroupIndex> tempFilesPerKey =
63 (Map<String, TemporaryGroupIndex>) httpSessionEvent.getSession().getAttribute(
64 TEMPORARY_INDEX_SESSION_KEY );
66 for ( TemporaryGroupIndex temporaryGroupIndex : tempFilesPerKey.values() )
68 log.info( "cleanup temporaryGroupIndex {} directory {}", temporaryGroupIndex.getIndexId(),
69 temporaryGroupIndex.getDirectory().getAbsolutePath() );
70 indexMerger.cleanTemporaryGroupIndex( temporaryGroupIndex );