Class SystemTool


  • public class SystemTool
    extends java.lang.Object

    System toolbox

    • Constructor Summary

      Constructors 
      Constructor Description
      SystemTool()  
    • Method Summary

      Modifier and Type Method Description
      static java.lang.String applyPatch​(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String patch, boolean log)
      Apply a path thru IO service
      static SystemTool.SystemInfo cacheInfo()  
      static SystemTool.SystemInfo cacheInfo​(SystemTool.SystemInfo info)  
      static java.lang.String cleanSrcAndBinDirs()
      Purge sources and binaries directories
      static void clearCacheToURL​(java.lang.String url, java.lang.String user, boolean invalidate, boolean notify, java.lang.String login, java.lang.String pwd)
      Clear cache thru IO service
      static void clearCacheToURL​(java.lang.String url, java.lang.String login, java.lang.String pwd)
      Clear cache and invalidate sessions thru IO service
      static java.lang.String clearExportDir()
      Purge export directory
      static java.lang.String clearRecycleBin()
      Purge all deleted files in DBDoc
      static java.lang.String clearTempDir()
      Purge temporary directory
      static void compileResources()
      Rebuild JS+CSS resources (less and minification)
      static void compileThemes()
      Rebuild themes with less sources
      static int countSessionsToURL​(java.lang.String url, java.lang.String user, boolean unique, java.lang.String login, java.lang.String pwd)
      Count authenticated users thru IO service
      static void cronMonitoring​(java.lang.String column, java.lang.String value)
      Change cron of monitoring
      static java.lang.String deleteModuleToURL​(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module)
      Delete a module definition thru IO service
      static SystemTool.SystemInfo diskInfo()  
      static SystemTool.SystemInfo diskInfo​(SystemTool.SystemInfo info)  
      static SystemTool.SystemInfo docInfo()  
      static SystemTool.SystemInfo docInfo​(SystemTool.SystemInfo info)  
      static java.lang.String dumpHeap()
      Dump the java heap
      static java.lang.String eraseDeadDoc()
      Deprecated.
      Use synchronizeDocuments instead
      static SystemTool.ExecResult exec​(java.lang.String cmd, java.util.List<java.lang.String> args, java.lang.String dir)
      Exec a system command
      static SystemTool.ExecResult execScript​(byte[] script, java.lang.String interpreter, java.util.List<java.lang.String> args, boolean keepDir)
      Exec a system script using specified script interpreter (e.g.
      static SystemTool.ExecResult execScript​(java.lang.String script, java.lang.String interpreter, java.util.List<java.lang.String> args, boolean keepDir)
      Exec a system script using specified script interpreter (e.g.
      static void forceGC()
      Full Garbage collection of unused JVM objects
      static java.lang.Thread[] getAllThreads()
      Get all JVM threads
      static SystemTool.ClassCount getClassCount()
      Get classes count
      static java.lang.String getCronExpr​(int sec)
      Get cron expression with a simple interval (seconds, minutes or hours)
      static int getCronInterval​(java.lang.String name, int def)
      Get a cron simple interval: detects seconds, minutes or hours frequency in the Cron expression
      static SystemTool.SystemInfo getInfo()
      Dump some system informations: JVM, Cache, DBDoc, Disk
      static SystemTool.SystemInfo getInfo​(boolean jvm, boolean cache, boolean doc, boolean disk)
      Dump some system informations: JVM, Cache, DBDoc, Disk
      static byte[] getModuleFromURL​(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module)
      Get a module definition thru IO service or simple HTTP call
      static java.lang.String getPID()
      Get the JVM process id
      static double getSystemLoadAverage()
      CPU usage
      static java.lang.Thread getThread​(long id, java.lang.String name)
      Look for a thread
      static SystemTool.ThreadTimes getThreadTimes()
      Get threads CPU times
      static void initMavenRepository()
      Initialize Maven repository
      static java.lang.String installModuleToURL​(java.lang.String url, java.lang.String login, java.lang.String pwd, java.lang.String module, java.lang.String xml, boolean log)
      Set a module definition thru IO service
      static boolean isCronStarted()
      Check cron status using admin rights
      static boolean isLinux()
      Is Linux?
      static boolean isMac()
      Is Mac?
      static boolean isUnix()
      Is UNIX?
      static boolean isWindows()
      Is Windows?
      static SystemTool.SystemInfo jvmMemory()  
      static SystemTool.SystemInfo jvmMemory​(SystemTool.SystemInfo info)  
      static java.util.Map<java.lang.String,​java.lang.management.MemoryUsage> memoryUsage​(boolean peak)
      Get all memories metrics using MemoryPoolMXBean
      static java.lang.management.MemoryUsage memoryUsage​(java.lang.String name, boolean peak)
      Get memory metrics using MemoryPoolMXBean
      static java.lang.String monitoring​(boolean start)
      Stop/Start monitoring
      static int objectGC​(boolean full)
      Internal garbage collection of unused Simplicite objects (Object, Grant and Processes)
      static java.lang.String rebuildIndex()
      Rebuild document indexes
      static java.lang.String rebuildObjectIndex()
      Rebuild object indexes
      static boolean resetCache​(boolean memory, boolean core, boolean invalidateSessions, boolean notify, int preCompile)
      Clears the system cache and update the LAST_CLEAR_CACHE to notify other servers
      static boolean resetCache​(java.lang.String login, boolean invalidateSessions, boolean notify)
      Clears the cache for one user and update the usr_logout to notify other servers
      static boolean resetCache​(java.lang.String object, java.lang.String instance)
      Deprecated.
      use resetCacheObject
      static void resetCacheAction​(Grant g, java.lang.String action)
      Clears specified action cache
      static void resetCacheConstraints​(java.lang.String obj)
      Clears specified constraints cache
      static boolean resetCacheDisp​(Grant g, java.lang.String disp)
      Clears specified disposition cache
      static void resetCacheDomain​(Grant g, java.lang.String domain)
      Clears specified domain cache
      static void resetCacheField​(java.lang.String field)
      Clears specified field cache
      static void resetCacheFieldArea​(java.lang.String area)
      Clears specified field area cache
      static void resetCacheFieldType​(java.lang.String type)
      Clears specified field type cache
      static void resetCacheFunction​(java.lang.String obj, java.lang.String action, java.lang.String view, Grant g)  
      static void resetCacheGroups​(Grant g)  
      static boolean resetCacheList​(java.lang.String lovName)
      Clears specified List of values and all related objects
      static boolean resetCacheObject​(java.lang.String object, java.lang.String instance)
      Clears specified business object from all user's cache
      static void resetCacheProcess​(Grant g, java.lang.String pcs)
      Clears specified process cache
      static void resetCacheResource​(Grant g, java.lang.String object, java.lang.String rowId)
      Clears specified resource cache
      static void resetCacheSysParam​(java.lang.String code, java.lang.String value, Grant g)
      Clears system parameter cache
      static void resetCacheTemplate​(Grant g, java.lang.String name)  
      static void resetCacheText()
      Clears TEXT List of values
      static void resetCacheTheme​(Grant g, java.lang.String theme)
      Clears specified theme
      static void resetCacheView​(Grant g, java.lang.String view)
      Clears specified view cache
      static boolean restartCron​(boolean lock, boolean notify)
      Stop and restart the cron manager using admin rights (notify other servers)
      static void restartCronToURL​(java.lang.String url, boolean notify, java.lang.String login, java.lang.String pwd)
      Restart cron thru IO service
      static boolean startCron​(boolean lock)
      Start the cron table using admin rights
      static boolean stopCron​(boolean unlock)
      Stop the cron manager using admin rights
      static java.lang.String synchronizeDocs()
      Purge all unsynchronized DBDoc
      static SystemTool.ThreadInfos threadDump​(long id, int maxDepth)
      Get thread dump
      static java.util.List<SystemTool.ThreadInfos> threadInfos​(int maxDepth, boolean sort, boolean filter)
      Get threads info
      static boolean useClientMonitoring()
      Use client monitoring ?
      static boolean useServerMonitoring()
      Use server monitoring ?
      • Methods inherited from class java.lang.Object

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

      • SystemTool

        public SystemTool()
    • Method Detail

      • forceGC

        public static void forceGC()
        Full Garbage collection of unused JVM objects
      • objectGC

        public static int objectGC​(boolean full)
        Internal garbage collection of unused Simplicite objects (Object, Grant and Processes)
        Parameters:
        full - true to remove object from cache, false to remove only the dynamic data (keep objects definitions)
        Returns:
        Number of cleared objects
      • clearRecycleBin

        public static java.lang.String clearRecycleBin()
        Purge all deleted files in DBDoc
      • clearExportDir

        public static java.lang.String clearExportDir()
        Purge export directory
      • clearTempDir

        public static java.lang.String clearTempDir()
        Purge temporary directory
      • cleanSrcAndBinDirs

        public static java.lang.String cleanSrcAndBinDirs()
        Purge sources and binaries directories
      • eraseDeadDoc

        @Deprecated
        public static java.lang.String eraseDeadDoc()
        Deprecated.
        Use synchronizeDocuments instead
      • synchronizeDocs

        public static java.lang.String synchronizeDocs()
        Purge all unsynchronized DBDoc
      • rebuildIndex

        public static java.lang.String rebuildIndex()
        Rebuild document indexes
      • rebuildObjectIndex

        public static java.lang.String rebuildObjectIndex()
        Rebuild object indexes
      • resetCache

        public static boolean resetCache​(boolean memory,
                                         boolean core,
                                         boolean invalidateSessions,
                                         boolean notify,
                                         int preCompile)
        Clears the system cache and update the LAST_CLEAR_CACHE to notify other servers
        Parameters:
        memory - true to clear the cache memory
        core - true clear the core definitions
        invalidateSessions - true to disconnect everybody
        notify - notify other servers ?
        preCompile - pre-compile objects and processes ? (0=no, 1=sync, 2=async)
      • resetCache

        public static boolean resetCache​(java.lang.String login,
                                         boolean invalidateSessions,
                                         boolean notify)
        Clears the cache for one user and update the usr_logout to notify other servers
        Parameters:
        login - user login
        invalidateSessions - true to disconnect user sessions
        notify - notify other servers ?
      • resetCache

        @Deprecated
        public static boolean resetCache​(java.lang.String object,
                                         java.lang.String instance)
        Deprecated.
        use resetCacheObject
      • resetCacheObject

        public static boolean resetCacheObject​(java.lang.String object,
                                               java.lang.String instance)
        Clears specified business object from all user's cache
        Parameters:
        object - Object name
        instance - Object instance (null means all instances of the object)
      • resetCacheSysParam

        public static void resetCacheSysParam​(java.lang.String code,
                                              java.lang.String value,
                                              Grant g)
        Clears system parameter cache
        Parameters:
        code - Parameter name
        value - Parameter value
        g - Optional user rights to reload
      • resetCacheList

        public static boolean resetCacheList​(java.lang.String lovName)
        Clears specified List of values and all related objects
        Parameters:
        lovName - List name
      • resetCacheText

        public static void resetCacheText()
        Clears TEXT List of values
      • resetCacheDisp

        public static boolean resetCacheDisp​(Grant g,
                                             java.lang.String disp)
        Clears specified disposition cache
        Parameters:
        g - User rights
        disp - Disposition name
      • resetCacheResource

        public static void resetCacheResource​(Grant g,
                                              java.lang.String object,
                                              java.lang.String rowId)
        Clears specified resource cache
        Parameters:
        g - User rights
        object - Object name or Disposition
        rowId - Object row ID
      • resetCacheProcess

        public static void resetCacheProcess​(Grant g,
                                             java.lang.String pcs)
        Clears specified process cache
        Parameters:
        g - User rights
        pcs - Process/Workflow name
      • resetCacheView

        public static void resetCacheView​(Grant g,
                                          java.lang.String view)
        Clears specified view cache
        Parameters:
        g - User rights
        view - View name
      • resetCacheTheme

        public static void resetCacheTheme​(Grant g,
                                           java.lang.String theme)
        Clears specified theme
        Parameters:
        g - User rights
        theme - Theme name
      • compileThemes

        public static void compileThemes()
        Rebuild themes with less sources
      • compileResources

        public static void compileResources()
        Rebuild JS+CSS resources (less and minification)
      • initMavenRepository

        public static void initMavenRepository()
        Initialize Maven repository
      • resetCacheAction

        public static void resetCacheAction​(Grant g,
                                            java.lang.String action)
        Clears specified action cache
        Parameters:
        g - User rights
        action - Action name
      • resetCacheDomain

        public static void resetCacheDomain​(Grant g,
                                            java.lang.String domain)
        Clears specified domain cache
        Parameters:
        g - User rights
        domain - Domain name
      • resetCacheConstraints

        public static void resetCacheConstraints​(java.lang.String obj)
        Clears specified constraints cache
        Parameters:
        obj - Object name
      • resetCacheField

        public static void resetCacheField​(java.lang.String field)
        Clears specified field cache
        Parameters:
        field - Field name
      • resetCacheFieldType

        public static void resetCacheFieldType​(java.lang.String type)
        Clears specified field type cache
        Parameters:
        type - Field type
      • resetCacheFieldArea

        public static void resetCacheFieldArea​(java.lang.String area)
        Clears specified field area cache
        Parameters:
        area - Area name
      • resetCacheFunction

        public static void resetCacheFunction​(java.lang.String obj,
                                              java.lang.String action,
                                              java.lang.String view,
                                              Grant g)
      • resetCacheGroups

        public static void resetCacheGroups​(Grant g)
      • resetCacheTemplate

        public static void resetCacheTemplate​(Grant g,
                                              java.lang.String name)
      • isCronStarted

        public static boolean isCronStarted()
        Check cron status using admin rights
        Returns:
        true if cron is started with scheduled jobs
      • startCron

        public static boolean startCron​(boolean lock)
        Start the cron table using admin rights
        Parameters:
        lock - true to unlock anyway and to lock with this platform
        Returns:
        true if cron has been restarted
      • stopCron

        public static boolean stopCron​(boolean unlock)
        Stop the cron manager using admin rights
        Parameters:
        unlock - true to unlock if the cron has been launched by this platform
        Returns:
        true if cron is stopped
      • restartCron

        public static boolean restartCron​(boolean lock,
                                          boolean notify)
        Stop and restart the cron manager using admin rights (notify other servers)
        Parameters:
        lock - true to unlock anyway and to lock with this platform
        notify - notify other servers ?
        Returns:
        true if cron has been restarted
      • getInfo

        public static SystemTool.SystemInfo getInfo​(boolean jvm,
                                                    boolean cache,
                                                    boolean doc,
                                                    boolean disk)
        Dump some system informations: JVM, Cache, DBDoc, Disk
        Parameters:
        jvm - Process JVM info ?
        cache - Process cache info ?
        doc - Process documents info ?
        disk - Process disk info ?
        Returns:
        Platform informations
      • getInfo

        public static SystemTool.SystemInfo getInfo()
        Dump some system informations: JVM, Cache, DBDoc, Disk
        Returns:
        Platform informations
      • useServerMonitoring

        public static boolean useServerMonitoring()
        Use server monitoring ?
      • monitoring

        public static java.lang.String monitoring​(boolean start)
        Stop/Start monitoring
      • useClientMonitoring

        public static boolean useClientMonitoring()
        Use client monitoring ?
      • cronMonitoring

        public static void cronMonitoring​(java.lang.String column,
                                          java.lang.String value)
        Change cron of monitoring
      • memoryUsage

        public static java.lang.management.MemoryUsage memoryUsage​(java.lang.String name,
                                                                   boolean peak)
        Get memory metrics using MemoryPoolMXBean
        Parameters:
        name - Perm gen, Code Cache, Eden Space, Survivor Space, Old Gen
        peak - True to get peak or current usage
      • memoryUsage

        public static java.util.Map<java.lang.String,​java.lang.management.MemoryUsage> memoryUsage​(boolean peak)
        Get all memories metrics using MemoryPoolMXBean
        Parameters:
        peak - True to get peak or current usage
      • threadInfos

        public static java.util.List<SystemTool.ThreadInfos> threadInfos​(int maxDepth,
                                                                         boolean sort,
                                                                         boolean filter)
        Get threads info
        Parameters:
        maxDepth - Stack trace size (0=no stack)
        sort - To sort result by times (desc)
        filter - Only return thread executing Simplicite
        Returns:
        Array if JMX is supported
      • getAllThreads

        public static java.lang.Thread[] getAllThreads()
        Get all JVM threads
      • getThread

        public static java.lang.Thread getThread​(long id,
                                                 java.lang.String name)
        Look for a thread
        Parameters:
        id - id in name is unknown
        name - name if id is unknown
        Returns:
        null if not found
      • threadDump

        public static SystemTool.ThreadInfos threadDump​(long id,
                                                        int maxDepth)
        Get thread dump
        Parameters:
        id - Thread id
        maxDepth - Stack trace size
        Returns:
        Thread info with Stack
      • dumpHeap

        public static java.lang.String dumpHeap()
        Dump the java heap
        Returns:
        path to the bin file
      • getPID

        public static java.lang.String getPID()
        Get the JVM process id
        Returns:
        PID or null
      • getSystemLoadAverage

        public static double getSystemLoadAverage()
        CPU usage
        Returns:
        System load average
      • getClassCount

        public static SystemTool.ClassCount getClassCount()
        Get classes count
        Returns:
        Number of classes
      • getCronInterval

        public static int getCronInterval​(java.lang.String name,
                                          int def)

        Get a cron simple interval: detects seconds, minutes or hours frequency in the Cron expression

        Example: '0/30 * * * * ?' = 30 seconds
        Example: '0 3/20 * * * ?' = 20*60 = 1200 seconds
        Example: '0 15 1/2 * * ?' = 2*60*60 = 7200 seconds

        Parameters:
        name - crontab name
        def - default interval
        Returns:
        Interval in seconds
      • getCronExpr

        public static java.lang.String getCronExpr​(int sec)
        Get cron expression with a simple interval (seconds, minutes or hours)
        Parameters:
        sec - polling interval in seconds
      • getModuleFromURL

        public static byte[] getModuleFromURL​(java.lang.String url,
                                              java.lang.String login,
                                              java.lang.String pwd,
                                              java.lang.String module)
                                       throws java.lang.Exception
        Get a module definition thru IO service or simple HTTP call
        Parameters:
        url - Platform URL
        login - Login
        pwd - Password
        module - Module name
        Returns:
        XML
        Throws:
        java.lang.Exception
      • installModuleToURL

        public static java.lang.String installModuleToURL​(java.lang.String url,
                                                          java.lang.String login,
                                                          java.lang.String pwd,
                                                          java.lang.String module,
                                                          java.lang.String xml,
                                                          boolean log)
                                                   throws java.lang.Exception
        Set a module definition thru IO service
        Parameters:
        url - Platform URL
        login - Login
        pwd - Password
        module - Module name
        xml - Module XML
        log - Full import log
        Returns:
        result
        Throws:
        java.lang.Exception
      • deleteModuleToURL

        public static java.lang.String deleteModuleToURL​(java.lang.String url,
                                                         java.lang.String login,
                                                         java.lang.String pwd,
                                                         java.lang.String module)
                                                  throws java.lang.Exception
        Delete a module definition thru IO service
        Parameters:
        url - Platform URL
        login - Login
        pwd - Password
        module - Module name
        Returns:
        result
        Throws:
        java.lang.Exception
      • applyPatch

        public static java.lang.String applyPatch​(java.lang.String url,
                                                  java.lang.String login,
                                                  java.lang.String pwd,
                                                  java.lang.String patch,
                                                  boolean log)
                                           throws java.lang.Exception
        Apply a path thru IO service
        Parameters:
        url - Platform URL
        login - Login
        pwd - Password
        patch - Patch XML
        log - Full import log
        Returns:
        Import result
        Throws:
        java.lang.Exception
      • clearCacheToURL

        public static void clearCacheToURL​(java.lang.String url,
                                           java.lang.String login,
                                           java.lang.String pwd)
                                    throws java.lang.Exception
        Clear cache and invalidate sessions thru IO service
        Parameters:
        url - Platform URL
        login - Login
        pwd - Password
        Throws:
        java.lang.Exception
      • clearCacheToURL

        public static void clearCacheToURL​(java.lang.String url,
                                           java.lang.String user,
                                           boolean invalidate,
                                           boolean notify,
                                           java.lang.String login,
                                           java.lang.String pwd)
                                    throws java.lang.Exception
        Clear cache thru IO service
        Parameters:
        url - Platform URL
        user - Optional user to clear
        invalidate - Invalidate sessions ?
        notify - notify other servers ?
        login - Login
        pwd - Password
        Throws:
        java.lang.Exception
      • restartCronToURL

        public static void restartCronToURL​(java.lang.String url,
                                            boolean notify,
                                            java.lang.String login,
                                            java.lang.String pwd)
                                     throws java.lang.Exception
        Restart cron thru IO service
        Parameters:
        url - Platform URL
        login - Login
        pwd - Password
        Throws:
        java.lang.Exception
      • countSessionsToURL

        public static int countSessionsToURL​(java.lang.String url,
                                             java.lang.String user,
                                             boolean unique,
                                             java.lang.String login,
                                             java.lang.String pwd)
                                      throws java.lang.Exception
        Count authenticated users thru IO service
        Parameters:
        url - Platform URL
        user - specific login or all if null
        unique - distinct users or all authenticated sessions
        login - Login
        pwd - Password
        Returns:
        sessions count
        Throws:
        java.lang.Exception
      • isWindows

        public static boolean isWindows()
        Is Windows?
      • isLinux

        public static boolean isLinux()
        Is Linux?
      • isUnix

        public static boolean isUnix()
        Is UNIX?
      • isMac

        public static boolean isMac()
        Is Mac?
      • exec

        public static SystemTool.ExecResult exec​(java.lang.String cmd,
                                                 java.util.List<java.lang.String> args,
                                                 java.lang.String dir)
        Exec a system command
        Parameters:
        cmd - Command
        args - Arguments list
        dir - Execution directory
        Returns:
        System command output and error
      • execScript

        public static SystemTool.ExecResult execScript​(byte[] script,
                                                       java.lang.String interpreter,
                                                       java.util.List<java.lang.String> args,
                                                       boolean keepDir)
        Exec a system script using specified script interpreter (e.g. bash, node, python, ...)
        Parameters:
        script - Script as byte array (string e.g. read from a resource document, ...)
        interpreter - Intepreter path (e.g. /bin/bash or /usr/local/bin/node, /usr/bin/python, ...), can be left empty for directly executable scripts
        args - Arguments list
        keepDir - Keep execution dir after execution?
        Returns:
        System script execution output and error
      • execScript

        public static SystemTool.ExecResult execScript​(java.lang.String script,
                                                       java.lang.String interpreter,
                                                       java.util.List<java.lang.String> args,
                                                       boolean keepDir)
        Exec a system script using specified script interpreter (e.g. bash, node, python, ...)
        Parameters:
        script - Script as string (string e.g. read from a field value ...)
        interpreter - Intepreter path (e.g. /bin/bash or /usr/local/bin/node, /usr/bin/python, ...), can be left empty for directly executable scripts
        args - Arguments list
        keepDir - Keep execution dir after execution?
        Returns:
        System script execution output and error