listeners()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
dl 0
loc 15
ccs 0
cts 6
cp 0
crap 12
rs 9.85
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
fr.quatrevieux.araknemu.realm.AuthBanIpSynchronizer.$Listener$.on(AuthStopped) 0 3 ?
fr.quatrevieux.araknemu.realm.AuthBanIpSynchronizer.$Listener$.event() 0 3 ?
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.realm;
21
22
import fr.quatrevieux.araknemu.common.account.banishment.AbstractBanIpSynchronizer;
23
import fr.quatrevieux.araknemu.common.account.banishment.BanIpService;
24
import fr.quatrevieux.araknemu.core.InitializableService;
25
import fr.quatrevieux.araknemu.core.event.EventsSubscriber;
26
import fr.quatrevieux.araknemu.core.event.Listener;
27
import fr.quatrevieux.araknemu.core.network.session.Session;
28
import fr.quatrevieux.araknemu.realm.authentication.AuthenticationAccount;
29
import fr.quatrevieux.araknemu.realm.event.AuthStopped;
30
import org.apache.logging.log4j.Logger;
31
32
import java.time.Duration;
33
import java.util.Collection;
34
import java.util.function.Supplier;
35
36
/**
37
 * Synchronize ban ip table for authentication service
38
 */
39
public final class AuthBanIpSynchronizer extends AbstractBanIpSynchronizer implements EventsSubscriber, InitializableService {
40
    public AuthBanIpSynchronizer(BanIpService<AuthenticationAccount> service, Supplier<Collection<? extends Session>> sessionsSupplier, Logger logger, Duration refreshDelay) {
41 1
        super(service, sessionsSupplier, logger, refreshDelay);
42 1
    }
43
44
    @Override
45
    public void init(Logger logger) {
46
        startPulling();
47
    }
48
49
    @Override
50
    public Listener[] listeners() {
51
        return new Listener[] {
52
            new Listener<AuthStopped>() {
53
                @Override
54
                public void on(AuthStopped event) {
55
                    stopPulling();
56
                }
57
58
                @Override
59
                public Class<AuthStopped> event() {
60
                    return AuthStopped.class;
61
                }
62
            },
63
            ipBannedListener(),
64
        };
65
    }
66
}
67