f18dea93b02a49d3d0dc60905da3057c1e0da710
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / config / NotificationCleanupConfig.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  *
7  * 
8  * Modifications Copyright © 2018 IBM.
9  * ===================================================================
10  *
11  * Unless otherwise specified, all software contained herein is licensed
12  * under the Apache License, Version 2.0 (the "License");
13  * you may not use this software except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *             http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  * Unless otherwise specified, all documentation contained herein is licensed
25  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
26  * you may not use this documentation except in compliance with the License.
27  * You may obtain a copy of the License at
28  *
29  *             https://creativecommons.org/licenses/by/4.0/
30  *
31  * Unless required by applicable law or agreed to in writing, documentation
32  * distributed under the License is distributed on an "AS IS" BASIS,
33  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34  * See the License for the specific language governing permissions and
35  * limitations under the License.
36  *
37  * ============LICENSE_END============================================
38  *
39  * 
40  */
41 package org.onap.portalapp.config;
42
43 import org.springframework.context.ApplicationContext;
44 import org.springframework.context.ApplicationContextAware;
45 import org.springframework.context.annotation.Bean;
46 import org.springframework.context.annotation.Configuration;
47
48 import javax.annotation.PostConstruct;
49 import java.util.Timer;
50 import java.util.TimerTask;
51
52 @Configuration
53 public class NotificationCleanupConfig implements ApplicationContextAware {
54         
55         // Once every 10 minutes should be adequate
56         public static final int CLEANUP_PERIOD_MINUTES = 10;
57         
58         private static ApplicationContext applicationContext;
59
60         public void setApplicationContext(ApplicationContext context) {
61                 applicationContext = context;
62         }
63
64         public static ApplicationContext getApplicationContext() {
65                 return applicationContext;
66
67         }
68
69         @PostConstruct
70         public void StartSchedular() {
71                 TimerTask task = new NotificationCleanup();
72                 Timer timer = new Timer();
73                 timer.schedule(task, 1000, (long) CLEANUP_PERIOD_MINUTES * 60 * 1000);
74         }
75
76         @Bean
77         public NotificationCleanupConfig getConfig() {
78                 return new NotificationCleanupConfig();
79         }
80
81 }