This project has retired. For details please refer to its
Attic page.
TemporaryGroupIndexSessionCleaner xref
1 package org.apache.archiva.webdav.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
27
28 import javax.servlet.http.HttpSessionEvent;
29 import javax.servlet.http.HttpSessionListener;
30 import java.util.HashMap;
31 import java.util.Map;
32
33
34
35
36
37
38
39
40 public class TemporaryGroupIndexSessionCleaner
41 implements HttpSessionListener
42 {
43
44 private Logger log = LoggerFactory.getLogger( getClass() );
45
46 private IndexMerger indexMerger;
47
48 public static final String TEMPORARY_INDEX_SESSION_KEY = TemporaryGroupIndexSessionCleaner.class.getName();
49
50 @Override
51 public void sessionCreated( HttpSessionEvent httpSessionEvent )
52 {
53
54 if ( httpSessionEvent.getSession().getAttribute( TEMPORARY_INDEX_SESSION_KEY ) == null )
55 {
56 httpSessionEvent.getSession().setAttribute( TEMPORARY_INDEX_SESSION_KEY,
57 new HashMap<>() );
58 }
59
60 if ( indexMerger == null )
61 {
62 WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(
63 httpSessionEvent.getSession().getServletContext() );
64 indexMerger = webApplicationContext.getBean( IndexMerger.class );
65 }
66 }
67
68 @Override
69 public void sessionDestroyed( HttpSessionEvent httpSessionEvent )
70 {
71 Map<String, TemporaryGroupIndex> tempFilesPerKey =
72 (Map<String, TemporaryGroupIndex>) httpSessionEvent.getSession().getAttribute(
73 TEMPORARY_INDEX_SESSION_KEY );
74
75 for ( TemporaryGroupIndex temporaryGroupIndex : tempFilesPerKey.values() )
76 {
77 log.info( "cleanup temporaryGroupIndex {} directory {}", temporaryGroupIndex.getIndexId(),
78 temporaryGroupIndex.getDirectory().getAbsolutePath() );
79 getIndexMerger( httpSessionEvent ).cleanTemporaryGroupIndex( temporaryGroupIndex );
80 }
81 }
82
83 private IndexMerger getIndexMerger( HttpSessionEvent httpSessionEvent )
84 {
85 if ( indexMerger == null )
86 {
87 WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(
88 httpSessionEvent.getSession().getServletContext() );
89 indexMerger = webApplicationContext.getBean( IndexMerger.class );
90 }
91 return indexMerger;
92 }
93 }
94