aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components/CleanUp.java
blob: d0f3e44a8c80ee2b1d14cb5f13167b0afe62ef0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.juick.components;

import com.juick.components.service.TokenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import java.util.ArrayList;

/**
 * Created by vitalyster on 22.11.2016.
 */
@Component
public class CleanUp {

    private static Logger logger = LoggerFactory.getLogger(CleanUp.class);

    @Inject
    TokenService tokenService;

    @Inject
    Notifications push;

    @Scheduled(fixedRate = 600000)
    public void cleanupTokens() {
        logger.debug("initializing GCM tokens cleanup: {} tokens", push.getInvalidGCMTokens().size());
        tokenService.deleteTokens("gcm", new ArrayList<>(push.getInvalidGCMTokens()));
        push.cleanupGCMTokens();
        logger.debug("initializing MPNS tokens cleanup: {} tokens", push.getInvalidMPNSTokens().size());
        tokenService.deleteTokens("mpns", new ArrayList<>(push.getInvalidMPNSTokens()));
        push.cleanupMPNSTokens();
        logger.debug("initializing APNS tokens cleanup: {} tokens", push.getInvalidAPNSTokens().size());
        tokenService.deleteTokens("apns", new ArrayList<>(push.getInvalidAPNSTokens()));
        push.cleanupMPNSTokens();
    }
}