Class ScriptUtil


  • public final class ScriptUtil
    extends java.lang.Object
    Script util
    • Field Detail

      • PROCESS_LOCK_FILENAME

        public static final java.lang.String PROCESS_LOCK_FILENAME
        The process lock filename
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static ScriptUtil getInstance()
        Get the instance
        Returns:
        the instance
      • createPidFile

        public java.nio.file.Path createPidFile​(java.nio.file.Path scriptPath,
                                                java.lang.String filename,
                                                java.lang.Long pid)
        Create a pid file
        Parameters:
        scriptPath - the script path
        filename - the filename
        pid - the pid
        Returns:
        the pidfile path
      • readPidFile

        public java.lang.Long readPidFile​(java.nio.file.Path file)
        Read a pid file
        Parameters:
        file - the file
        Returns:
        the read and parsed pid
      • createLockFile

        public java.nio.file.Path createLockFile​(java.nio.file.Path basePath,
                                                 java.lang.String id)
                                          throws java.io.IOException
        Create lock file
        Parameters:
        basePath - the base path
        id - the id
        Returns:
        the lock file
        Throws:
        java.io.IOException - In case of an I/O error
      • hasNoRunningProcesses

        public boolean hasNoRunningProcesses​(java.nio.file.Path directory)
        Verify if the directory has no running processes
        Parameters:
        directory - the directory
        Returns:
        true if it has no running processes
      • isRunningProcess

        public boolean isRunningProcess​(java.io.File pidFile)
        Verify if the process is running
        Parameters:
        pidFile - the pid file
        Returns:
        true if the pid file is valid and the process is still running
      • prepareTempPathAndScript

        public java.nio.file.Path prepareTempPathAndScript​(java.nio.file.Path basePath,
                                                           java.lang.String filename,
                                                           ISystemCommandExecuterPlatformSupport systemCommandExecuterPlatformSupport)
                                                    throws java.io.IOException
        Prepare the temp path and the script file
        Parameters:
        basePath - the base path
        filename - the filanem
        systemCommandExecuterPlatformSupport - the system command executer platform support
        Returns:
        the temp script file
        Throws:
        java.io.IOException - In case of an I/O issue
      • createTempFile

        public java.io.File createTempFile​(java.nio.file.Path basePath,
                                           java.lang.String filename)
                                    throws java.io.IOException
        Prepare the temp path and the script file
        Parameters:
        basePath - the base path
        filename - the filename
        Returns:
        the temp file
        Throws:
        java.io.IOException - In case of an I/O issue
      • createScriptFile

        public void createScriptFile​(ISystemCommandExecuterPlatformSupport systemCommandExecuterPlatformSupport,
                                     java.nio.file.Path file)
                              throws java.io.IOException
        Create the script file
        Parameters:
        systemCommandExecuterPlatformSupport - the system command executer platform support
        file - the file
        Throws:
        java.io.IOException - In case of an I/O issue
      • closeScriptFile

        public void closeScriptFile​(ISystemCommandExecuterPlatformSupport systemCommandExecuterPlatformSupport,
                                    java.nio.file.Path file)
                             throws java.io.IOException
        Close the script file
        Parameters:
        systemCommandExecuterPlatformSupport - the system command executer platform support
        file - the file
        Throws:
        java.io.IOException - In case of an I/O issue
      • prepareCommandList

        public java.lang.String prepareCommandList​(java.util.List<java.lang.String> list)
        Prepare command lit
        Parameters:
        list - the list
        Returns:
        the prepared command
      • prepareString

        public java.lang.String prepareString​(java.lang.String ch,
                                              int length)
        Prepare string
        Parameters:
        ch - the fill string
        length - the max length
        Returns:
        the prepared string
      • selectInvalidProcessDirectories

        public java.util.List<java.nio.file.Path> selectInvalidProcessDirectories​(java.nio.file.Path basePath,
                                                                                  long newFolderThreshold,
                                                                                  long lockFolderThreshold)
                                                                           throws java.io.IOException
        Select invalid process directories
        Parameters:
        basePath - the base path
        newFolderThreshold - the new folder threshold
        lockFolderThreshold - the lock folder threshold
        Returns:
        the file list
        Throws:
        java.io.IOException - In case of an I/O error
      • hasReachedThresholdValue

        public boolean hasReachedThresholdValue​(long timestamp,
                                                long threshold)
        Verify if the threshold is reached
        Parameters:
        timestamp - the timestamp
        threshold - the threshold
        Returns:
        true if the threshold has reached
      • prepareIdFromName

        public java.lang.String prepareIdFromName​(java.lang.String directory)
        Prepare id from name
        Parameters:
        directory - the directory
        Returns:
        the id