Interface UsageSnapshot

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    
    public interface UsageSnapshot
     implements AutoCloseable
                        

    This is the interface that defines the behavior of a usage snapshot object.

    A snapshot object is created and used by the Usage Uploader when uploading usage data to the remote server. It contains a collection of UsageRecords reported by a UsageReporter, grouped under a Target ID, and persisted in UsageStore.

    The records collected in a snapshot is using the creation date of the snapshot as the cut-off date, that is, all Usage Records persisted up to the cut-off date will be included in the snapshot.

    Usage:
    In the Usage Uploader,
    1. Instantiates a concrete implementation of this interface. The implementation is responsible for
       retrieving usage records from usage store.
    2. Iterates through the usage records in the snapshot via next and converts the usage
       records to the data format required by the server.
    3. After the uploader completed the upload successfully, cleans up the persisted usage records in
       this snapshot from the usage store via removeRecords;
    4. Cleans up other implementation specific resources/states associated with the snapshot
       via close.
    
    Example:
    
    
        // In the upload method.
        ....
        try ( // Try-with statement will invoke snapshot.close() transparently at the end.
            MyUsageSnapshotImpl snapshot = new MyUsageSnapshotImpl(targetID)
        ) {
            UsageRecord record;
            while ((record = snapshot.next()) != null) {
                ...
                // Converts the record to the format required by the server.
                ...
            }
    
            // Upload to the server.
            ...
    
            // Upload successfully, now remove those records from the usage store.
            snapshot.removeRecords();
        } catch (SomeException ex) {
            ...
        }
    
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract UsageRecord next() Gets the next Usage Record in the snapshot.
      abstract void removeRecords() Deletes all the usage records from the underlying usage store.
      abstract int getRecordCount() Retrieves number of records in the snapshot.
      abstract String getTargetId() The target ID associated with this snapshot.
      • Methods inherited from class java.lang.AutoCloseable

        close
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • next

        @Nullable() abstract UsageRecord next()

        Gets the next Usage Record in the snapshot.

      • removeRecords

         abstract void removeRecords()

        Deletes all the usage records from the underlying usage store.

        This needs to be called after the usage records in the snapshot have been uploaded successfully to the remote server and before the close method is called.

      • getRecordCount

         abstract int getRecordCount()

        Retrieves number of records in the snapshot.

      • getTargetId

        @NonNull() abstract String getTargetId()

        The target ID associated with this snapshot.