Class BaseSyncStatistics<SyncStatisticsT extends BaseSyncStatistics>

    • Constructor Detail

      • BaseSyncStatistics

        public BaseSyncStatistics()
        Creates a new BaseSyncStatistics with initial values 0 of created, updated, failed and processed counters, an empty reportMessage and latestBatchHumanReadableProcessingTime.
    • Method Detail

      • startTimer

        public void startTimer()
        Stores the current time of instantiation in the latestBatchStartTime instance variable that will be used later when calculateProcessingTime() is called to calculate the total time of processing.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

      • getUpdated

        public java.util.concurrent.atomic.AtomicInteger getUpdated()
        Gets the total number of resources that were updated.
        Returns:
        total number of resources that were updated.
      • incrementUpdated

        public void incrementUpdated()
        Increments the total number of resource that were updated.
      • incrementUpdated

        public void incrementUpdated​(int times)
        Increments the total number of resources that were updated by the supplied times.
        Parameters:
        times - the total number of times to increment.
      • getCreated

        public java.util.concurrent.atomic.AtomicInteger getCreated()
        Gets the total number of resources that were created.
        Returns:
        total number of resources that were created.
      • incrementCreated

        public void incrementCreated()
        Increments the total number of resource that were created.
      • incrementCreated

        public void incrementCreated​(int times)
        Increments the total number of resources that were created by the supplied times.
        Parameters:
        times - the total number of times to increment.
      • getProcessed

        public java.util.concurrent.atomic.AtomicInteger getProcessed()
        Gets the total number of resources that were processed/synced.
        Returns:
        total number of resources that were processed/synced.
      • incrementProcessed

        public void incrementProcessed()
        Increments the total number of resources that were processed/synced.
      • incrementProcessed

        public void incrementProcessed​(int times)
        Increments the total number of resources that were processed/synced by the supplied times.
        Parameters:
        times - the total number of times to increment.
      • getFailed

        public java.util.concurrent.atomic.AtomicInteger getFailed()
        Gets the total number of resources that failed to sync.
        Returns:
        total number of resources that failed to sync.
      • incrementFailed

        public void incrementFailed()
        Increments the total number of resources that failed to sync.
      • incrementFailed

        public void incrementFailed​(int times)
        Increments the total number of resources that failed to sync by the supplied times.
        Parameters:
        times - the total number of times to increment.
      • calculateProcessingTime

        public void calculateProcessingTime()
        Calculates the processing time taken by the subtracting the time, when the startTimer() method of this instance was called, from the current time in Milliseconds. It also sets the processing time in all the units latestBatchProcessingTimeInDays, latestBatchProcessingTimeInHours, latestBatchProcessingTimeInMinutes, latestBatchProcessingTimeInSeconds and latestBatchProcessingTimeInMillis. It also builds a human readable processing time, as string, in the following format @{code "0d, 0h, 0m, 2s, 545ms"} and stores it in the publicly exposed variable latestBatchHumanReadableProcessingTime.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

      • getLatestBatchHumanReadableProcessingTime

        public java.lang.String getLatestBatchHumanReadableProcessingTime()
        Gets the human readable processing time in the following format @{code "0d, 0h, 0m, 2s, 545ms"}.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        the human readable processing time in the following format @{code "0d, 0h, 0m, 2s, 545ms"}
      • getLatestBatchProcessingTimeInDays

        public long getLatestBatchProcessingTimeInDays()
        Gets the number of days it took to process.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        number of days taken to process.
      • getLatestBatchProcessingTimeInHours

        public long getLatestBatchProcessingTimeInHours()
        Gets the number of hours it took to process.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        number of hours taken to process.
      • getLatestBatchProcessingTimeInMinutes

        public long getLatestBatchProcessingTimeInMinutes()
        Gets the number of minutes it took to process.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        number of minutes taken to process.
      • getLatestBatchProcessingTimeInSeconds

        public long getLatestBatchProcessingTimeInSeconds()
        Gets the number of seconds it took to process.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        number of seconds taken to process.
      • getLatestBatchProcessingTimeInMillis

        public long getLatestBatchProcessingTimeInMillis()
        Gets the number of milliseconds it took to process.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        number of milliseconds taken to process.
      • getReportMessage

        public abstract java.lang.String getReportMessage()
        Gets a summary message of the statistics report.

        Note: This method isn't thread-safe and shouldn't be used in a concurrent context.

        Returns:
        a summary message of the statistics report.
      • getSyncStatisticsClassName

        public java.lang.String getSyncStatisticsClassName()
        Gets the name of the implementation class extending this abstract class. This name is then serialized into JSON and stored in the custom object of the last sync statistics. Later we could use this name to deserialize the custom object into the correct implementation class.
        Returns:
        name of the implementation class extending this abstract class.
      • getThis

        protected abstract SyncStatisticsT getThis()
        Returns this instance of T, which extends BaseSyncStatistics. The purpose of this method is to make sure that this is an instance of a class which extends BaseSyncStatistics in order to be used in the generic methods of the class. Otherwise, without this method, the methods above would need to cast this to T which could lead to a runtime error of the class was extended in a wrong way.
        Returns:
        an instance of the class that overrides this method.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getDefaultReportMessageForResource

        protected java.lang.String getDefaultReportMessageForResource​(@Nonnull
                                                                      java.lang.String resourceString)
        Builds a proper summary message of the statistics report of a given resourceString in following format:

        "Summary: 2 resources were processed in total (2 created, 2 updated and 0 failed to sync)."

        Parameters:
        resourceString - a string representing the resource
        Returns:
        a summary message of the statistics report