Class SaJMXConfiguration

  • All Implemented Interfaces:
    javax.management.DynamicMBean

    public final class SaJMXConfiguration
    extends java.lang.Object
    implements javax.management.DynamicMBean
    A DynamicMBean implementation for the JMX system configuration.
    Author:
    rbo
    • Field Detail

      • ROOT_TAG

        public static final java.lang.String ROOT_TAG
        Root entry for Saperion.
        See Also:
        Constant Field Values
      • SYSTEM_CONFIG

        public static final java.lang.String SYSTEM_CONFIG
        System configuration name.
      • CONFIG_DIR

        public static final java.lang.String CONFIG_DIR
        Configuration directory.
    • Method Detail

      • getInstance

        public static SaJMXConfiguration getInstance()
        Get instance.
        Returns:
        Instance
      • getConfigDir

        public java.lang.String getConfigDir()
      • getAbsoluteConfigPath

        public java.lang.String getAbsoluteConfigPath​(java.lang.String fileName)
        returns an absolute path for the specified file name.
        Parameters:
        fileName - the name of configuration file
        Returns:
        the absolute path.
      • hasSection

        public boolean hasSection​(java.lang.String section)
        Checks, if the given section exists.
        Parameters:
        section - Section name
        Returns:
        True, if exists
      • hasSection

        public boolean hasSection​(SaJMXConstants.ConfigKey key)
        Checks, if the given section exists.
        Parameters:
        key - Section key
        Returns:
        True, if exists
      • addNewProperties

        public void addNewProperties​(java.lang.String name,
                                     SaAbstractJMXProperties props)
        Add new property set.
        Parameters:
        name - Name
        props - Properties
      • registerBean

        public void registerBean​(java.lang.String name,
                                 java.lang.Object bean)
        Register a new bean.
        Parameters:
        name - Name
        bean -
      • registerBean

        public void registerBean​(java.lang.String name,
                                 java.lang.Object bean,
                                 int port)
        Register a new bean.
        Parameters:
        name - Name
        bean -
        port -
      • configureLog4j

        public boolean configureLog4j​(java.lang.String section)
        Configures the Log4J system from the given section.
        Parameters:
        section - Section
        Returns:
        Success
      • isLog4jConfigured

        public boolean isLog4jConfigured()
        Returns:
        log4j configured
      • configureLog4j

        public boolean configureLog4j​(SaJMXConstants.ConfigKey section)
        Configures the Log4J system from the given section key.
        Parameters:
        section - Section key
        Returns:
        Success
      • setConfigType

        public void setConfigType​(SaJMXConstants.ConfigVariant type,
                                  java.lang.String mainFile)
                           throws java.io.FileNotFoundException
        Set the configuration type and main file.
        Parameters:
        type - Configuration type
        mainFile - Main file name
        Throws:
        java.io.FileNotFoundException - File not found.
      • setConfigType

        public void setConfigType​(SaJMXConstants.ConfigVariant type,
                                  java.util.Properties configuration)
        Set the configuration type and properties.
        Parameters:
        type - Configuration type
        configuration - Configuration properties
      • setConfigTypeAndConfigDirectory

        public void setConfigTypeAndConfigDirectory​(SaJMXConstants.ConfigVariant type,
                                                    java.lang.String configurationDir)
                                             throws java.io.FileNotFoundException
        Set the configuration type and configuration directory.
        Parameters:
        type - Configuration type
        configurationDir - Configuration directory
        Throws:
        java.io.FileNotFoundException - File not found.
      • newProperties

        public void newProperties​(java.lang.String name,
                                  java.lang.String configFile)
                           throws java.io.IOException
        Add a new property set to the configuration.
        Parameters:
        name - Configuration name
        configFile - Configuration file name
        Throws:
        java.io.IOException - Exception
      • newProperties

        public void newProperties​(java.lang.String name,
                                  java.lang.String configFile,
                                  boolean isClassPathResource)
                           throws java.io.IOException
        Add a new property set to the configuration.
        Parameters:
        name - Configuration name
        configFile - Configuration file name
        isClassPathResource - true if configFile is a classpath related resource
        Throws:
        java.io.IOException - Exception
      • newLink

        public void newLink​(java.lang.String name,
                            java.lang.String configFile)
                     throws java.io.IOException
        Add a new property set to the configuration.
        Parameters:
        name - Configuration name
        configFile - Configuration file name
        Throws:
        java.io.IOException - Exception
      • newProperties

        public void newProperties​(java.lang.String name,
                                  java.io.InputStream in)
                           throws java.io.IOException
        Add a new stream property set to the configuration.
        Parameters:
        name - Configuration name
        in - Configuration stream
        Throws:
        java.io.IOException - Exception
      • newXMLProperties

        public void newXMLProperties​(java.lang.String name,
                                     java.io.InputStream in)
                              throws java.io.IOException
        Add a new XML property set to the configuration.
        Parameters:
        name - Configuration name
        in - Configuration stream
        Throws:
        java.io.IOException - Exception
      • newXMLProperties

        public void newXMLProperties​(java.lang.String name,
                                     java.lang.String configFile)
                              throws java.io.IOException
        Add a new XML property set to the configuration.
        Parameters:
        name - Configuration name
        configFile - Configuration file name
        Throws:
        java.io.IOException - Exception
      • newBackendProperties

        public void newBackendProperties​(SaRMISystemCommand cmd,
                                         java.util.Properties sysprops)
                                  throws java.rmi.RemoteException
        Adds the backend properties to configuration.
        Parameters:
        cmd - System commands
        sysprops - Properties of section ApplicationServer
        Throws:
        java.rmi.RemoteException - Exception
      • newFeatureProperties

        public void newFeatureProperties​(SaRMISystemCommand cmd)
                                  throws java.rmi.RemoteException
        Adds the backend features to configuration.
        Parameters:
        cmd - System commands
        Throws:
        java.rmi.RemoteException - Exception
      • getProperties

        public java.util.Properties getProperties​(java.lang.String name)
        Reads a property set.
        Parameters:
        name - Name
        Returns:
        Property set or NULL, if set of this name don't exists
      • getProperties

        public java.util.Properties getProperties​(SaJMXConstants.ConfigKey key)
        Reads a property set.
        Parameters:
        key - ConfigKey
        Returns:
        Property set or NULL, if set of this name don't exists
      • setProperties

        public void setProperties​(SaJMXConstants.ConfigKey key,
                                  java.util.Properties props)
        sets a property set to the already existing configuration.
        Parameters:
        key - ConfigKey
        props - Properties
      • getProperty

        public java.lang.String getProperty​(SaJMXConstants.ConfigKey configKey,
                                            java.lang.String key)
        Returns the value for a given key from the given configuration.
        Parameters:
        configKey - Configuration key
        key - Key
        Returns:
        Value
      • hasProperty

        public boolean hasProperty​(SaJMXConstants.ConfigKey configKey,
                                   java.lang.String propertyName)
        Returns true if the property with the given name exists within the given configuration.
        Parameters:
        configKey - Configuration key
        propertyName - property name
        Returns:
        Value
      • getProperty

        public java.lang.String getProperty​(SaJMXConstants.ConfigKey configKey,
                                            java.lang.String key,
                                            java.lang.String defaultValue)
        Returns the value for a given key from the given configuration with default value.
        Parameters:
        configKey - Configuration key
        key - Key
        defaultValue - Default value
        Returns:
        Value
      • getProperty

        public java.lang.String getProperty​(java.lang.String name)
        Reads property in dotted name format.
        Parameters:
        name - Name
        Returns:
        Value
      • getProperty

        public java.lang.String getProperty​(java.lang.String name,
                                            java.lang.String defaultValue)
        Reads property in dotted name format with default value.
        Parameters:
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getIntProperty

        public int getIntProperty​(java.lang.String name,
                                  int defaultValue)
        Reads integer property in dotted name format with default value.
        Parameters:
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getIntProperty

        public int getIntProperty​(SaJMXConstants.ConfigKey configKey,
                                  java.lang.String name,
                                  int defaultValue)
        Reads integer property with default value.
        Parameters:
        configKey - Configuration key
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getDoubleProperty

        public double getDoubleProperty​(java.lang.String name,
                                        double defaultValue)
        Reads double property in dotted name format with default value.
        Parameters:
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getDoubleProperty

        public double getDoubleProperty​(SaJMXConstants.ConfigKey configKey,
                                        java.lang.String name,
                                        double defaultValue)
        Reads double property with default value.
        Parameters:
        configKey - Configuration key
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.String name,
                                          boolean defaultValue)
        Reads boolean property in dotted name format with default value.
        Parameters:
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getBooleanProperty

        public boolean getBooleanProperty​(SaJMXConstants.ConfigKey configKey,
                                          java.lang.String name,
                                          boolean defaultValue)
        Reads boolean property with default value.
        Parameters:
        configKey - Configuration key
        name - Name
        defaultValue - Default value
        Returns:
        Value
      • getFileProperty

        public java.io.File getFileProperty​(SaJMXConstants.ConfigKey configKey,
                                            java.lang.String name)
                                     throws java.io.FileNotFoundException
        Reads file property.
        Parameters:
        configKey - Configuration key
        name - Name
        Returns:
        Value
        Throws:
        java.io.FileNotFoundException - File not found
      • getLinkProperty

        public java.io.File getLinkProperty​(SaJMXConstants.ConfigKey configKey)
                                     throws java.io.FileNotFoundException
        Reads linked file property.
        Parameters:
        configKey - Configuration key
        Returns:
        Value
        Throws:
        java.io.FileNotFoundException - File not found
      • getNumberOfTokens

        public int getNumberOfTokens​(SaJMXConstants.ConfigKey configKey,
                                     java.lang.String propertyName,
                                     java.lang.String delimiter)
        Reads a multivalue property and returns the number of tokens separated by the given delimiter.
        Parameters:
        configKey - configuration key
        propertyName - the name of the property
        delimiter - the delimiter separating the tokens
        Returns:
        number of tokens
      • getTokens

        public java.lang.String[] getTokens​(SaJMXConstants.ConfigKey configKey,
                                            java.lang.String propertyName,
                                            java.lang.String delimiter)
        Reads a multivalue property separated by the given delimiter and returns the values as String[]. Note that all whitespaces are removed.
        Parameters:
        configKey - configuration key
        propertyName - the name of the property
        delimiter - the delimiter separating the tokens
        Returns:
        values as String[]
      • getFirstToken

        public java.lang.String getFirstToken​(java.lang.String value,
                                              java.lang.String delimiter)
        Returns the first token of the given value, separated by the given delimiter. Example: if value = host:port (delimiter is ":") host will be returned.
        Parameters:
        value - given string to split
        delimiter - the delimiter separating the tokens
        Returns:
        first token
      • getSecondIntToken

        public int getSecondIntToken​(java.lang.String value,
                                     java.lang.String delimiter,
                                     int defaultValue)
        Returns the second token of the given value and converts it to int. Both tokens has to be separated by the given delimiter. Example: if value = host:port (delimiter is ":") port will be returned. If a NumberFormatException occurs, the given defaultValue is returned.
        Parameters:
        value - given string to split
        delimiter - the delimiter separating the tokens
        defaultValue - if the second token is undefined or may not be converted to int the defaultValue will be returned.
        Returns:
        second token as int
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String attributeName)
                                      throws javax.management.AttributeNotFoundException,
                                             javax.management.MBeanException,
                                             javax.management.ReflectionException
        Specified by:
        getAttribute in interface javax.management.DynamicMBean
        Throws:
        javax.management.AttributeNotFoundException
        javax.management.MBeanException
        javax.management.ReflectionException
        See Also:
        DynamicMBean.getAttribute(java.lang.String)
      • getAttributes

        public javax.management.AttributeList getAttributes​(java.lang.String[] attributeNames)
        Specified by:
        getAttributes in interface javax.management.DynamicMBean
        See Also:
        DynamicMBean.getAttributes(java.lang.String[])
      • getMBeanInfo

        public javax.management.MBeanInfo getMBeanInfo()
        Specified by:
        getMBeanInfo in interface javax.management.DynamicMBean
        See Also:
        DynamicMBean.getMBeanInfo()
      • invoke

        public java.lang.Object invoke​(java.lang.String actionName,
                                       java.lang.Object[] params,
                                       java.lang.String[] signature)
                                throws javax.management.MBeanException,
                                       javax.management.ReflectionException
        Specified by:
        invoke in interface javax.management.DynamicMBean
        Throws:
        javax.management.MBeanException
        javax.management.ReflectionException
        See Also:
        DynamicMBean.invoke(java.lang.String, java.lang.Object[], java.lang.String[])
      • setAttribute

        public void setAttribute​(javax.management.Attribute attribute)
                          throws javax.management.AttributeNotFoundException,
                                 javax.management.InvalidAttributeValueException,
                                 javax.management.MBeanException,
                                 javax.management.ReflectionException
        Specified by:
        setAttribute in interface javax.management.DynamicMBean
        Throws:
        javax.management.AttributeNotFoundException
        javax.management.InvalidAttributeValueException
        javax.management.MBeanException
        javax.management.ReflectionException
        See Also:
        DynamicMBean.setAttribute(javax.management.Attribute)
      • setAttributes

        public javax.management.AttributeList setAttributes​(javax.management.AttributeList attributes)
        Specified by:
        setAttributes in interface javax.management.DynamicMBean
        See Also:
        DynamicMBean.setAttributes(javax.management.AttributeList)