• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.libraries.mobiledatadownload.internal.logging;
17 
18 import com.google.common.base.Optional;
19 import com.google.common.util.concurrent.ListenableFuture;
20 import com.google.mobiledatadownload.internal.MetadataProto.FileGroupLoggingState;
21 import com.google.mobiledatadownload.internal.MetadataProto.SamplingInfo;
22 import java.util.List;
23 
24 /** Interface for keeping track of state necessary for accurate logging. */
25 public interface LoggingStateStore {
26 
27   /**
28    * Gets the number of days since maintenance was last run and updates the timestamp for future
29    * calls.
30    *
31    * @return a future representing the number of days since maintenance was last run. If this method
32    *     hasn't succeeded before, the future will complete with an absent Optional. The future may
33    *     complete with (invalid) negative values. Future will fail with IOException if there was an
34    *     issue reading or updating the value.
35    */
getAndResetDaysSinceLastMaintenance()36   public ListenableFuture<Optional<Integer>> getAndResetDaysSinceLastMaintenance();
37 
38   /**
39    * Increment the data usage stats for the file group. If there exists an entry which matches the
40    * GroupKey, version number and build id, then the data usage from dataUsageIncrements will be
41    * added to that, otherwise a new entry will be created.
42    */
incrementDataUsage(FileGroupLoggingState dataUsageIncrements)43   public ListenableFuture<Void> incrementDataUsage(FileGroupLoggingState dataUsageIncrements);
44 
45   /**
46    * Returns a list of all the data usage increments grouped by GroupKey, build id and version
47    * number.
48    */
getAndResetAllDataUsage()49   public ListenableFuture<List<FileGroupLoggingState>> getAndResetAllDataUsage();
50 
51   /** Resets all LoggingStateStore state. */
clear()52   public ListenableFuture<Void> clear();
53 
54   /**
55    * Gets info necessary for stable sampling. Callers are responsible for ensuring that stable
56    * sampling is enabled.
57    *
58    * <p>If the stable sampling random number hasn't been persisted yet, this will populate it before
59    * returning.
60    */
getStableSamplingInfo()61   public ListenableFuture<SamplingInfo> getStableSamplingInfo();
62 }
63