Skip to content

Commit 58ff65e

Browse files
committed
Prevent duplicate stats in HA mode
1 parent 29c73b7 commit 58ff65e

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/event/BridgeableEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
)
3131
public abstract class BridgeableEvent extends ApplicationEvent {
3232

33+
public static final String SOURCE_NOT_AVAILABLE = "SOURCE_NOT_AVAILABLE";
34+
3335
public abstract BridgeableEvent withSource(String source);
3436

3537
public BridgeableEvent() {
36-
super("SOURCE_NOT_AVAILABLE");
38+
super(SOURCE_NOT_AVAILABLE);
3739
}
3840

3941
}

src/main/java/eu/openanalytics/containerproxy/stat/impl/AbstractDbCollector.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,36 @@
2626

2727
import java.io.IOException;
2828

29+
import static eu.openanalytics.containerproxy.event.BridgeableEvent.SOURCE_NOT_AVAILABLE;
30+
2931
public abstract class AbstractDbCollector implements IStatCollector {
3032

3133
@EventListener
3234
public void onUserLogoutEvent(UserLogoutEvent event) throws IOException {
33-
writeToDb(event.getTimestamp(), event.getUserId(), "Logout",null);
35+
if (event.getSource().equals(SOURCE_NOT_AVAILABLE)) {
36+
writeToDb(event.getTimestamp(), event.getUserId(), "Logout", null);
37+
}
3438
}
3539

3640
@EventListener
3741
public void onUserLoginEvent(UserLoginEvent event) throws IOException {
38-
writeToDb(event.getTimestamp(), event.getUserId(), "Login", null);
42+
if (event.getSource().equals(SOURCE_NOT_AVAILABLE)) {
43+
writeToDb(event.getTimestamp(), event.getUserId(), "Login", null);
44+
}
3945
}
4046

4147
@EventListener
4248
public void onProxyStartEvent(ProxyStartEvent event) throws IOException {
43-
writeToDb(event.getTimestamp(), event.getUserId(), "ProxyStart", event.getSpecId());
49+
if (event.getSource().equals(SOURCE_NOT_AVAILABLE)) {
50+
writeToDb(event.getTimestamp(), event.getUserId(), "ProxyStart", event.getSpecId());
51+
}
4452
}
4553

4654
@EventListener
4755
public void onProxyStopEvent(ProxyStopEvent event) throws IOException {
48-
writeToDb(event.getTimestamp(), event.getUserId(), "ProxyStop", event.getSpecId());
56+
if (event.getSource().equals(SOURCE_NOT_AVAILABLE)) {
57+
writeToDb(event.getTimestamp(), event.getUserId(), "ProxyStop", event.getSpecId());
58+
}
4959
}
5060

5161
@EventListener

0 commit comments

Comments
 (0)