1   /* Copyright 2019 CS Systèmes d'Information
2    * All rights reserved.
3    */
4   package org.orekit.gnss.metric.ntrip;
5   
6   import org.orekit.gnss.metric.messages.ParsedMessage;
7   
8   import java.util.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  
12  
13  /** {@link RTCMMessageObserver Message observer} that simply logs messages counts.
14   * @author Luc Maisonobe
15   */
16  public class LoggingObserver implements MessageObserver {
17  
18      /** Count by message type. */
19      private final Map<Integer, Integer> typesCounts;
20  
21      /** Count by mount point. */
22      private final Map<String, Integer> mountPointsCounts;
23  
24      /** Simple constructor.
25       */
26      public LoggingObserver() {
27          typesCounts       = new HashMap<>();
28          mountPointsCounts = new HashMap<>();
29      }
30  
31      /** {@inheritDoc} */
32      @Override
33      public void messageAvailable(final String mountPoint, final ParsedMessage message) {
34  
35          // log per message type
36          final Integer tc = typesCounts.get(message.getTypeCode());
37          if (tc == null) {
38              typesCounts.put(message.getTypeCode(), 1);
39          } else {
40              typesCounts.put(message.getTypeCode(), tc + 1);
41          }
42  
43          // log per mount point
44          final Integer mpc = mountPointsCounts.get(mountPoint);
45          if (mpc == null) {
46              mountPointsCounts.put(mountPoint, 1);
47          } else {
48              mountPointsCounts.put(mountPoint, mpc + 1);
49          }
50  
51      }
52  
53      /** Get the message count by message type.
54       * @return read-only view of a message type → count map
55       */
56      public Map<Integer, Integer> getCountByMessageType() {
57          return Collections.unmodifiableMap(typesCounts);
58      }
59  
60      /** Get the message count by mount point.
61       * @return read-only view of a mount point → count map
62       */
63      public Map<String, Integer> getCountByMountPoint() {
64          return Collections.unmodifiableMap(mountPointsCounts);
65      }
66  
67  }