Заготовка под отправку счетчиков
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.serega6531.packmate.model.pojo.Counter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CountingService {
|
||||
|
||||
private Map<Integer, Counter> servicesPackets = new HashMap<>();
|
||||
private Map<Integer, Counter> servicesStreams = new HashMap<>();
|
||||
|
||||
private Counter totalPackets = new Counter();
|
||||
private Counter totalStreams = new Counter();
|
||||
|
||||
void countStream(int serviceId, int packets) {
|
||||
getCounter(servicesPackets, serviceId).increment(packets);
|
||||
getCounter(servicesStreams, serviceId).increment();
|
||||
|
||||
totalPackets.increment(packets);
|
||||
totalStreams.increment();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 * * ? * *")
|
||||
public void sendCounters() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
private Counter getCounter(Map<Integer, Counter> counters, int serviceId) {
|
||||
return counters.computeIfAbsent(serviceId, c -> new Counter());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,13 +22,13 @@ import java.util.stream.Collectors;
|
||||
public class PatternService {
|
||||
|
||||
private final PatternRepository repository;
|
||||
private final StreamSubscriptionService subscriptionService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
|
||||
private final Map<Integer, Pattern> patterns = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
public PatternService(PatternRepository repository,
|
||||
StreamSubscriptionService subscriptionService) {
|
||||
SubscriptionService subscriptionService) {
|
||||
this.repository = repository;
|
||||
this.subscriptionService = subscriptionService;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Optional;
|
||||
public class ServicesService {
|
||||
|
||||
private final ServiceRepository repository;
|
||||
private final StreamSubscriptionService subscriptionService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
|
||||
private final InetAddress localIp;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ServicesService {
|
||||
|
||||
@Autowired
|
||||
public ServicesService(ServiceRepository repository,
|
||||
StreamSubscriptionService subscriptionService,
|
||||
SubscriptionService subscriptionService,
|
||||
@Value("${local-ip}") String localIpString) throws UnknownHostException {
|
||||
this.repository = repository;
|
||||
this.subscriptionService = subscriptionService;
|
||||
|
||||
@@ -30,7 +30,8 @@ public class StreamService {
|
||||
private final StreamRepository repository;
|
||||
private final PatternService patternService;
|
||||
private final ServicesService servicesService;
|
||||
private final StreamSubscriptionService subscriptionService;
|
||||
private final CountingService countingService;
|
||||
private final SubscriptionService subscriptionService;
|
||||
|
||||
private final boolean ignoreEmptyPackets;
|
||||
|
||||
@@ -40,11 +41,13 @@ public class StreamService {
|
||||
public StreamService(StreamRepository repository,
|
||||
PatternService patternService,
|
||||
ServicesService servicesService,
|
||||
StreamSubscriptionService subscriptionService,
|
||||
CountingService countingService,
|
||||
SubscriptionService subscriptionService,
|
||||
@Value("${ignore-empty-packets}") boolean ignoreEmptyPackets) {
|
||||
this.repository = repository;
|
||||
this.patternService = patternService;
|
||||
this.servicesService = servicesService;
|
||||
this.countingService = countingService;
|
||||
this.subscriptionService = subscriptionService;
|
||||
this.ignoreEmptyPackets = ignoreEmptyPackets;
|
||||
}
|
||||
@@ -88,6 +91,8 @@ public class StreamService {
|
||||
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
||||
stream.setService(service.getPort());
|
||||
|
||||
countingService.countStream(service.getPort(), packets.size());
|
||||
|
||||
new StreamOptimizer(service, packets).optimizeStream();
|
||||
processUserAgent(packets, stream);
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@ import java.util.Objects;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class StreamSubscriptionService {
|
||||
public class SubscriptionService {
|
||||
|
||||
private final List<WebSocketSession> subscribers = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public StreamSubscriptionService(ObjectMapper mapper) {
|
||||
public SubscriptionService(ObjectMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user