Mercurial > dive4elements > gnv-client
annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/cache/CacheCleaner.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | ebeb56428409 |
children |
rev | line source |
---|---|
1127
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
1 /* |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
3 * |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
7 */ |
ebeb56428409
Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
897
diff
changeset
|
8 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 * |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 package de.intevation.gnv.geobackend.base.query.cache; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 import java.sql.Date; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import java.util.Collection; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 import java.util.Iterator; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 import org.apache.log4j.Logger; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.gnv.geobackend.base.Result; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.gnv.geobackend.base.query.DefaultQueryExceutor; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 import de.intevation.gnv.geobackend.util.DateUtils; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 * Thread that looks every n - Minutes if an Cache has to be cleanedup. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 * You can configure the Timeout in Seconds using the Systemproperty |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 * |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 public class CacheCleaner extends Thread { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
36 * the logger, used to log exceptions and additonaly information |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 private static Logger log = Logger.getLogger(CacheCleaner.class); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
39 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
40 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
41 * The Systemproperty-identifier for the Configuration of the TimeInterval |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
42 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 public static final String CACHE_CLEANER_INTERVAL = "caching.cleaner.interval"; |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
44 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 * The Time To wait between two Cleanups. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 private long timeout = 1000 * 60; // 1 Minute |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
49 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 * The Border which has to be used to Query the updated Tables. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 private long lowerBorderTime = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
55 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 * The Id to Lookup the SQL-Statement for fetchung the Names of the |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 * updated Tables. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
58 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 private String queryID = "updated_tables"; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
62 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 public CacheCleaner() { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
66 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
69 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
71 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
72 public CacheCleaner(Runnable arg0) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
73 super(arg0); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
74 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
75 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
76 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
77 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
78 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
79 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
80 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
81 public CacheCleaner(String arg0) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
82 super(arg0); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
83 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
84 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
85 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
86 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
87 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
88 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
89 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
90 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
91 public CacheCleaner(ThreadGroup arg0, Runnable arg1) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
92 super(arg0, arg1); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
93 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
94 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
95 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
96 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
97 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
98 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
99 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
100 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
101 public CacheCleaner(ThreadGroup arg0, String arg1) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
102 super(arg0, arg1); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
103 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
104 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
105 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
106 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
107 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
108 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
109 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
110 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
111 public CacheCleaner(Runnable arg0, String arg1) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
112 super(arg0, arg1); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
113 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
114 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
115 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
116 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
117 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
118 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
119 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
120 * @param arg2 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
121 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
122 public CacheCleaner(ThreadGroup arg0, Runnable arg1, String arg2) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
123 super(arg0, arg1, arg2); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
124 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
125 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
126 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
127 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
128 * Constructor |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
129 * @param arg0 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
130 * @param arg1 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
131 * @param arg2 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
132 * @param arg3 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
133 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
134 public CacheCleaner(ThreadGroup arg0, Runnable arg1, String arg2, long arg3) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
135 super(arg0, arg1, arg2, arg3); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
136 this.setUp(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
137 } |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
138 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
139 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
140 * Sets up the members of the CacheCleaner. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
141 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
142 protected void setUp(){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
143 String intervalValue = System.getProperty(CACHE_CLEANER_INTERVAL); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
144 if (intervalValue != null){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
145 log.info("Set Interval to "+intervalValue+" Seconds"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
146 try { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
147 this.timeout = Long.parseLong(intervalValue) * 1000; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
148 } catch (NumberFormatException e) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
149 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
150 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
151 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
152 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
153 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
154 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
155 * This Method can be used do run the Main-Mechanism of the Thread e.g |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
156 * from a Unittest. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
157 * @return |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
158 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
159 public boolean test(){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
160 log.debug("CacheCleaner.test"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
161 this.cleanup(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
162 return true; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
163 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
164 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
165 @Override |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
166 public void run() { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
167 log.debug("CacheCleaner.run"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
168 long requiredTime = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
169 this.lowerBorderTime = System.currentTimeMillis(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
170 while (true){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
171 long startTime = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
172 try { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
173 long nextTimeout = timeout-requiredTime; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
174 if (nextTimeout > 0){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
175 Thread.sleep(nextTimeout); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
176 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
177 startTime = System.currentTimeMillis(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
178 log.debug("Sleep "+nextTimeout+"ms cleanup Cache now"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
179 this.cleanup(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
180 } catch (InterruptedException e) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
181 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
182 } catch (Exception e){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
183 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
184 } catch (Throwable t){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
185 log.error(t,t); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
186 }finally{ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
187 requiredTime = System.currentTimeMillis() - startTime; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
188 log.debug("CleanUp required "+requiredTime); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
189 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
190 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
191 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
192 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
193 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
194 * Method that do the Cleanup-Work |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
195 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
196 protected void cleanup(){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
197 log.debug("CacheCleaner.cleanup"); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
198 try { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
199 // We have to go this Way to avoid using the Cache for this Query. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
200 String[] tableNames = this.getUpdatedTableNames(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
201 if (tableNames != null){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
202 QueryExecutorFactory.getInstance() |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
203 .getQueryExecutor().clearCache(tableNames); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
204 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
205 } catch (QueryException e) { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
206 log.error(e,e); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
207 } |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
208 |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
209 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
210 |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
211 /** |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
212 * Returns the Names of the Tables which have been updated. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
213 * @return the Names of the Tables which have been updated. |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
214 * @throws QueryException |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
215 */ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
216 protected String[] getUpdatedTableNames()throws QueryException { |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
217 String[] tableNames = null; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
218 QueryExecutor queryExecutor = new DefaultQueryExceutor(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
219 Date date = new Date(this.lowerBorderTime); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
220 this.lowerBorderTime = System.currentTimeMillis(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
221 log.debug("New Lookup at "+DateUtils.getPatternedDateAmer(new Date(lowerBorderTime))); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
222 String queryDate = DateUtils.getPatternedDateAmer(date); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
223 Collection<Result> result = queryExecutor. |
897
02cd2935b5fa
Removed trailing whitespace.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
895
diff
changeset
|
224 executeQuery(queryID, |
895
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
225 new String[]{queryDate}); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
226 if (result != null && !result.isEmpty()){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
227 tableNames = new String[result.size()]; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
228 Iterator<Result> it = result.iterator(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
229 int i = 0; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
230 while (it.hasNext()){ |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
231 tableNames[i++] = it.next().getString(0).toUpperCase(); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
232 log.debug("Table that was updated: "+tableNames[i-1]); |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
233 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
234 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
235 return tableNames; |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
236 } |
eb777022b628
Integrated a CacheCleaner that will cleanup the SQL-Cache if necessary
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
237 } |