Class ServerIdentity

  • All Implemented Interfaces:
    ServerIdentityInterface

    public final class ServerIdentity
    extends java.lang.Object
    implements ServerIdentityInterface
    Server Identity containing ServerName, ServerRole, Global PlatformId
    This is a private Common.

    By default this class is initialized with default values:
    • ServerName: hostname or UnknownHostname if not found
    • ServerRole: UnknownRole
    • ServerId: partial MAC ADDRESS as integer
    • SiteId : 0

    One should initialize its server instance by calling:
     ServerIdentity serverIdentity = ServerIdentity.getInstance();
     serverIdentity.setName(name).setRole(role).setPlatformId(platformId);
     or
     ServerIdentity.getInstance().setFromMap(map);
     or
     ServerIdentity.getInstance().setFromPropertyFile(file);
     
    Where name, role and platformID comes from a configuration file for instance.

    Role could be a multiple, noted as role1_role2_role3.
    Usage:
     ServerIdentity serverIdentity = ServerIdentity.getInstance();
     String name = serverIdentity.getName();
     String role = serverIdentity.getRole();
     int platformId = serverIdentity.getPlatformId();
     
    Main usages are for:
    • GUID for PlatformId
    • Logger and Logbook: for all


    NOTE for developers:
    • Do not add LOGGER there
    • Do not modify directly serverId attribute . Use setServerId
    • Do not modify directly siteId attribute . Use setSiteId
    • Method Detail

      • getJsonIdentity

        public final java.lang.String getJsonIdentity()
        Returns:
        the Json representation of the ServerIdentity
      • getInstance

        public static final ServerIdentity getInstance()
        Returns:
        the current instance of ServerIdentity
      • setFromPropertyFile

        public final ServerIdentity setFromPropertyFile​(java.io.File propertiesFile)
                                                 throws java.io.FileNotFoundException
        Assign the ServerIdentity from a Property file where Key are elements from MAP_KEYNAME.
        Other keys are ignored. Illegal values are ignored.
        Parameters:
        propertiesFile - file
        Returns:
        this
        Throws:
        java.io.FileNotFoundException - if the property file is not found
      • setFromYamlFile

        public final ServerIdentity setFromYamlFile​(java.io.File yamlFile)
                                             throws java.io.FileNotFoundException
        Assign the ServerIdentity from a Yaml file where Key are elements from MAP_KEYNAME.
        Other keys are ignored. Illegal values are ignored.
        Parameters:
        yamlFile - file
        Returns:
        this
        Throws:
        java.io.FileNotFoundException - if the Yaml file is not found
      • setFromMap

        public final ServerIdentity setFromMap​(java.util.Map<java.lang.String,​java.lang.Object> map)
        Assign the ServerIdentity from a Map where Key are elements from MAP_KEYNAME.
        Other keys are ignored. Illegal values are ignored.
        Parameters:
        map - the map from which the values are to be set
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - map null
      • setName

        public final ServerIdentity setName​(java.lang.String name)
        Parameters:
        name - the name of the Server to set
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - name null
      • setRole

        public final ServerIdentity setRole​(java.lang.String role)
        Parameters:
        role - the role of the Server to set
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - role
      • setServerId

        public final ServerIdentity setServerId​(int serverId)
        The PlatformId is a unique name per site (each of the 3 sites of Vitam should have a different id).
        Parameters:
        serverId - the platformId of the Vitam Platform to set
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - platformId < 0
      • setSiteId

        public final ServerIdentity setSiteId​(int siteId)
        Set the SideID
        Parameters:
        siteId - the siteId to set
        Returns:
        this