-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathNotificationProcessorImp.java
More file actions
60 lines (50 loc) · 2.51 KB
/
NotificationProcessorImp.java
File metadata and controls
60 lines (50 loc) · 2.51 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package io.split.engine.sse;
import com.google.common.annotations.VisibleForTesting;
import io.split.engine.sse.dtos.GenericNotificationData;
import io.split.engine.sse.dtos.IncomingNotification;
import io.split.engine.sse.dtos.SplitKillNotification;
import io.split.engine.sse.dtos.StatusNotification;
import io.split.engine.sse.dtos.SegmentQueueDto;
import io.split.engine.sse.workers.FeatureFlagsWorker;
import io.split.engine.sse.workers.Worker;
import static com.google.common.base.Preconditions.checkNotNull;
public class NotificationProcessorImp implements NotificationProcessor {
private final FeatureFlagsWorker _featureFlagsWorker;
private final Worker<SegmentQueueDto> _segmentWorker;
private final PushStatusTracker _pushStatusTracker;
@VisibleForTesting
/* package private */ NotificationProcessorImp(FeatureFlagsWorker featureFlagsWorker,
Worker<SegmentQueueDto> segmentWorker,
PushStatusTracker pushStatusTracker) {
_featureFlagsWorker = checkNotNull(featureFlagsWorker);
_segmentWorker = checkNotNull(segmentWorker);
_pushStatusTracker = checkNotNull(pushStatusTracker);
}
public static NotificationProcessorImp build(FeatureFlagsWorker featureFlagsWorker, Worker<SegmentQueueDto> segmentWorker,
PushStatusTracker pushStatusTracker) {
return new NotificationProcessorImp(featureFlagsWorker, segmentWorker, pushStatusTracker);
}
public void processUpdates(IncomingNotification notification) {
_featureFlagsWorker.addToQueue(notification);
}
@Override
public void process(IncomingNotification notification) {
notification.handler(this);
}
@Override
public void processSplitKill(SplitKillNotification splitKillNotification) {
_featureFlagsWorker.kill(splitKillNotification);
_featureFlagsWorker.addToQueue(new SplitKillNotification(GenericNotificationData.builder()
.changeNumber(splitKillNotification.getChangeNumber())
.channel(splitKillNotification.getChannel())
.build()));
}
@Override
public void processSegmentUpdate(long changeNumber, String segmentName) {
_segmentWorker.addToQueue(new SegmentQueueDto(segmentName, changeNumber));
}
@Override
public void processStatus(StatusNotification statusNotification) {
statusNotification.handlerStatus(_pushStatusTracker);
}
}