Class ServerIdentity

java.lang.Object
fr.gouv.vitam.common.ServerIdentity
All Implemented Interfaces:
ServerIdentityInterface

public final class ServerIdentity extends 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 Details

    • getLoggerMessagePrepend

      public final String getLoggerMessagePrepend()
      Specified by:
      getLoggerMessagePrepend in interface ServerIdentityInterface
      Returns:
      the Logger Message prepend
    • getJsonIdentity

      public final 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(File propertiesFile) throws 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:
      FileNotFoundException - if the property file is not found
    • setFromYamlFile

      public final ServerIdentity setFromYamlFile(File yamlFile) throws 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:
      FileNotFoundException - if the Yaml file is not found
    • setFromMap

      public final ServerIdentity setFromMap(Map<String,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:
      IllegalArgumentException - map null
    • getName

      public final String getName()
      Specified by:
      getName in interface ServerIdentityInterface
      Returns:
      the name of the Server
    • setName

      public final ServerIdentity setName(String name)
      Parameters:
      name - the name of the Server to set
      Returns:
      this
      Throws:
      IllegalArgumentException - name null
    • getRole

      public final String getRole()
      Specified by:
      getRole in interface ServerIdentityInterface
      Returns:
      the role of the Server
    • setRole

      public final ServerIdentity setRole(String role)
      Parameters:
      role - the role of the Server to set
      Returns:
      this
      Throws:
      IllegalArgumentException - role
    • getGlobalPlatformId

      public final int getGlobalPlatformId()
      Specified by:
      getGlobalPlatformId in interface ServerIdentityInterface
      Returns:
      the global uniq Id of the server (global along all sites)
    • 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:
      IllegalArgumentException - platformId < 0
    • getServerId

      public final int getServerId()
      Specified by:
      getServerId in interface ServerIdentityInterface
      Returns:
      the uniq Id of the Server
    • getSiteId

      public final int getSiteId()
      Specified by:
      getSiteId in interface ServerIdentityInterface
      Returns:
      the siteID
    • setSiteId

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