Class ScriptUtil
- java.lang.Object
-
- com.github.toolarium.system.command.process.util.ScriptUtil
-
public final class ScriptUtil extends java.lang.Object
Script util
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROCESS_LOCK_FILENAME
The process lock filename
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeScriptFile(ISystemCommandExecuterPlatformSupport systemCommandExecuterPlatformSupport, java.nio.file.Path file)
Close the script filejava.nio.file.Path
createLockFile(java.nio.file.Path basePath, java.lang.String id)
Create lock filejava.nio.file.Path
createPidFile(java.nio.file.Path scriptPath, java.lang.String filename, java.lang.Long pid)
Create a pid filevoid
createScriptFile(ISystemCommandExecuterPlatformSupport systemCommandExecuterPlatformSupport, java.nio.file.Path file)
Create the script filejava.io.File
createTempFile(java.nio.file.Path basePath, java.lang.String filename)
Prepare the temp path and the script filestatic ScriptUtil
getInstance()
Get the instanceboolean
hasNoRunningProcesses(java.nio.file.Path directory)
Verify if the directory has no running processesboolean
hasReachedThresholdValue(long timestamp, long threshold)
Verify if the threshold is reachedboolean
isRunningProcess(java.io.File pidFile)
Verify if the process is runningjava.lang.String
prepareCommandList(java.util.List<java.lang.String> list)
Prepare command litjava.lang.String
prepareIdFromName(java.lang.String directory)
Prepare id from namejava.lang.String
prepareString(java.lang.String ch, int length)
Prepare stringjava.nio.file.Path
prepareTempPathAndScript(java.nio.file.Path basePath, java.lang.String filename, ISystemCommandExecuterPlatformSupport systemCommandExecuterPlatformSupport)
Prepare the temp path and the script filejava.lang.Long
readPidFile(java.nio.file.Path file)
Read a pid filejava.util.List<java.nio.file.Path>
selectInvalidProcessDirectories(java.nio.file.Path basePath, long newFolderThreshold, long lockFolderThreshold)
Select invalid process directories
-
-
-
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 pathfilename
- the filenamepid
- 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 pathid
- 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 pathfilename
- the filanemsystemCommandExecuterPlatformSupport
- 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 pathfilename
- 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 supportfile
- 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 supportfile
- 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 stringlength
- 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 pathnewFolderThreshold
- the new folder thresholdlockFolderThreshold
- 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 timestampthreshold
- 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
-
-