Class BackupStrategyWrapper

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getBackupFileName​(java.lang.String fileName, int backupIndex)
      Get the backup file name for specific index.
      int getMaxBackupIndex()
      Get the max index of backup.
      boolean shouldBackup​(java.io.File file)
      Whether we should backup a specified log file.
      • Methods inherited from class java.lang.Object

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

      • BackupStrategyWrapper

        public BackupStrategyWrapper​(BackupStrategy backupStrategy)
    • Method Detail

      • getMaxBackupIndex

        public int getMaxBackupIndex()
        Description copied from interface: BackupStrategy2
        Get the max index of backup.

        Generally, the max index should be greater than 1, and recommended to be less than 10.

        Imagine the normal log file name is 'log', and max backup index is 'n', as the log grows, a log record would go from 'log' to 'log.bak.1', then to 'log.bak.2', 'log.bak.3', and finally to 'log.bak.n', the greater index, the older log.
        After that, the log record will no longer exist in the file system.

        If you don't want to limit the max index, then return BackupStrategy2.NO_LIMIT.
        With returning BackupStrategy2.NO_LIMIT, When you backing up, the oldest log would be saved to 'log.bak.1', and then 'log.bak.2'...'log.bak.n', the greater index, the newer log.

        Don't return Integer.MAX_VALUE or any value less than 0, otherwise an exception will be thrown.

        Specified by:
        getMaxBackupIndex in interface BackupStrategy2
        Returns:
        the max index of backup
      • getBackupFileName

        public java.lang.String getBackupFileName​(java.lang.String fileName,
                                                  int backupIndex)
        Description copied from interface: BackupStrategy2
        Get the backup file name for specific index.

        Generally, a backup file with normal file name 'log' and index 'n' could simply be 'log.bak.n', you can specify your own naming rules, by overriding this method.

        Make sure to return different backup file name with different backup index, and same backup file name with same index. Otherwise, it will lead to unexpected behavior.

        Specified by:
        getBackupFileName in interface BackupStrategy2
        Parameters:
        fileName - the normal file name, generated by FileNameGenerator.generateFileName(int, long)
        backupIndex - the backup index, which will increase from 1 to BackupStrategy2.getMaxBackupIndex()
        Returns:
        the backup file name
      • shouldBackup

        public boolean shouldBackup​(java.io.File file)
        Description copied from interface: BackupStrategy
        Whether we should backup a specified log file.
        Specified by:
        shouldBackup in interface BackupStrategy
        Parameters:
        file - the log file
        Returns:
        true is we should backup the log file