%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
net.sf.infrared.collector.impl.persistence.PersistTask |
|
|
1 | /* |
|
2 | * Copyright 2005 Tavant Technologies and Contributors |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | * |
|
16 | * |
|
17 | * |
|
18 | * Original Author: binil.thomas (Tavant Technologies) |
|
19 | * Contributor(s): subin.p; |
|
20 | * |
|
21 | */ |
|
22 | package net.sf.infrared.collector.impl.persistence; |
|
23 | ||
24 | import java.util.List; |
|
25 | import java.util.TimerTask; |
|
26 | ||
27 | import net.sf.infrared.base.model.ApplicationStatistics; |
|
28 | import net.sf.infrared.base.model.StatisticsSnapshot; |
|
29 | import net.sf.infrared.base.util.LoggingFactory; |
|
30 | import net.sf.infrared.collector.StatisticsRepository; |
|
31 | import org.apache.log4j.Logger; |
|
32 | ||
33 | public class PersistTask extends TimerTask { |
|
34 | 0 | private static final Logger log = LoggingFactory.getLogger(PersistTask.class); |
35 | ||
36 | private StatisticsRepository statsRepository; |
|
37 | ||
38 | private SpringContext ctx; |
|
39 | ||
40 | 0 | public PersistTask(StatisticsRepository statsRepository) { |
41 | 0 | this.statsRepository = statsRepository; |
42 | 0 | this.ctx = new SpringContext(); |
43 | 0 | } |
44 | ||
45 | public void run() { |
|
46 | 0 | List statsListToPersist = statsRepository.getStatisticsToPersist(); |
47 | 0 | ApplicationStatistics[] statsArrayToPersist = (ApplicationStatistics[]) statsListToPersist |
48 | .toArray(new ApplicationStatistics[] {}); |
|
49 | 0 | ctx.getDao().saveStatistics(statsArrayToPersist); |
50 | ||
51 | 0 | statsRepository.clearStatsSinceLastPersist(); |
52 | 0 | if (log.isDebugEnabled()) { |
53 | 0 | log.debug("Persisted " + statsArrayToPersist.length + " statistics"); |
54 | } |
|
55 | 0 | } |
56 | public void shutdown() { |
|
57 | 0 | if(ctx != null) { |
58 | 0 | ctx.shutdown(); |
59 | } |
|
60 | 0 | } |
61 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |