Class BaseSyncStatistics<SyncStatisticsT extends BaseSyncStatistics>
- java.lang.Object
-
- com.commercetools.sync.commons.helpers.BaseSyncStatistics<SyncStatisticsT>
-
- Direct Known Subclasses:
CartDiscountSyncStatistics
,CategorySyncStatistics
,CustomerSyncStatistics
,CustomObjectSyncStatistics
,InventorySyncStatistics
,ProductSyncStatistics
,ProductTypeSyncStatistics
,ShoppingListSyncStatistics
,StateSyncStatistics
,TaxCategorySyncStatistics
,TypeSyncStatistics
public abstract class BaseSyncStatistics<SyncStatisticsT extends BaseSyncStatistics> extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description BaseSyncStatistics()
Creates a newBaseSyncStatistics
with initial values0
of created, updated, failed and processed counters, an empty reportMessage and latestBatchHumanReadableProcessingTime.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
calculateProcessingTime()
Calculates the processing time taken by the subtracting the time, when thestartTimer()
method of this instance was called, from the current time in Milliseconds.boolean
equals(java.lang.Object o)
java.util.concurrent.atomic.AtomicInteger
getCreated()
Gets the total number of resources that were created.protected java.lang.String
getDefaultReportMessageForResource(java.lang.String resourceString)
Builds a proper summary message of the statistics report of a givenresourceString
in following format:java.util.concurrent.atomic.AtomicInteger
getFailed()
Gets the total number of resources that failed to sync.java.lang.String
getLatestBatchHumanReadableProcessingTime()
Gets the human readable processing time in the following format @{code "0d, 0h, 0m, 2s, 545ms"}.long
getLatestBatchProcessingTimeInDays()
Gets the number of days it took to process.long
getLatestBatchProcessingTimeInHours()
Gets the number of hours it took to process.long
getLatestBatchProcessingTimeInMillis()
Gets the number of milliseconds it took to process.long
getLatestBatchProcessingTimeInMinutes()
Gets the number of minutes it took to process.long
getLatestBatchProcessingTimeInSeconds()
Gets the number of seconds it took to process.java.util.concurrent.atomic.AtomicInteger
getProcessed()
Gets the total number of resources that were processed/synced.abstract java.lang.String
getReportMessage()
Gets a summary message of the statistics report.java.lang.String
getSyncStatisticsClassName()
Gets the name of the implementation class extending this abstract class.protected abstract SyncStatisticsT
getThis()
java.util.concurrent.atomic.AtomicInteger
getUpdated()
Gets the total number of resources that were updated.int
hashCode()
void
incrementCreated()
Increments the total number of resource that were created.void
incrementCreated(int times)
Increments the total number of resources that were created by the supplied times.void
incrementFailed()
Increments the total number of resources that failed to sync.void
incrementFailed(int times)
Increments the total number of resources that failed to sync by the supplied times.void
incrementProcessed()
Increments the total number of resources that were processed/synced.void
incrementProcessed(int times)
Increments the total number of resources that were processed/synced by the supplied times.void
incrementUpdated()
Increments the total number of resource that were updated.void
incrementUpdated(int times)
Increments the total number of resources that were updated by the supplied times.void
startTimer()
Stores the current time of instantiation in thelatestBatchStartTime
instance variable that will be used later whencalculateProcessingTime()
is called to calculate the total time of processing.
-
-
-
Constructor Detail
-
BaseSyncStatistics
public BaseSyncStatistics()
Creates a newBaseSyncStatistics
with initial values0
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 thelatestBatchStartTime
instance variable that will be used later whencalculateProcessingTime()
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 thestartTimer()
method of this instance was called, from the current time in Milliseconds. It also sets the processing time in all the unitslatestBatchProcessingTimeInDays
,latestBatchProcessingTimeInHours
,latestBatchProcessingTimeInMinutes
,latestBatchProcessingTimeInSeconds
andlatestBatchProcessingTimeInMillis
. 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 variablelatestBatchHumanReadableProcessingTime
.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()
Returnsthis
instance ofT
, which extendsBaseSyncStatistics
. The purpose of this method is to make sure thatthis
is an instance of a class which extendsBaseSyncStatistics
in order to be used in the generic methods of the class. Otherwise, without this method, the methods above would need to castthis 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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getDefaultReportMessageForResource
protected java.lang.String getDefaultReportMessageForResource(@Nonnull java.lang.String resourceString)
Builds a proper summary message of the statistics report of a givenresourceString
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
-
-