Package fr.gouv.vitam.common
Class ServerIdentity
- java.lang.Object
-
- fr.gouv.vitam.common.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServerIdentity.MAP_KEYNAME
Map key for setFromMap
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getGlobalPlatformId()
static ServerIdentity
getInstance()
java.lang.String
getJsonIdentity()
java.lang.String
getLoggerMessagePrepend()
java.lang.String
getName()
java.lang.String
getRole()
int
getServerId()
int
getSiteId()
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.ServerIdentity
setFromPropertyFile(java.io.File propertiesFile)
Assign the ServerIdentity from a Property file where Key are elements from MAP_KEYNAME.ServerIdentity
setFromYamlFile(java.io.File yamlFile)
Assign the ServerIdentity from a Yaml file where Key are elements from MAP_KEYNAME.ServerIdentity
setName(java.lang.String name)
ServerIdentity
setRole(java.lang.String role)
ServerIdentity
setServerId(int serverId)
The PlatformId is a unique name per site (each of the 3 sites of Vitam should have a different id).ServerIdentity
setSiteId(int siteId)
Set the SideID
-
-
-
Method Detail
-
getLoggerMessagePrepend
public final java.lang.String getLoggerMessagePrepend()
- Specified by:
getLoggerMessagePrepend
in interfaceServerIdentityInterface
- Returns:
- the Logger Message prepend
-
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
-
getName
public final java.lang.String getName()
- Specified by:
getName
in interfaceServerIdentityInterface
- Returns:
- the name of the Server
-
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
-
getRole
public final java.lang.String getRole()
- Specified by:
getRole
in interfaceServerIdentityInterface
- Returns:
- the role of the Server
-
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
-
getGlobalPlatformId
public final int getGlobalPlatformId()
- Specified by:
getGlobalPlatformId
in interfaceServerIdentityInterface
- 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:
java.lang.IllegalArgumentException
- platformId < 0
-
getServerId
public final int getServerId()
- Specified by:
getServerId
in interfaceServerIdentityInterface
- Returns:
- the uniq Id of the Server
-
getSiteId
public final int getSiteId()
- Specified by:
getSiteId
in interfaceServerIdentityInterface
- Returns:
- the siteID
-
setSiteId
public final ServerIdentity setSiteId(int siteId)
Set the SideID- Parameters:
siteId
- the siteId to set- Returns:
- this
-
-