Package org.pipservices3.components.info
Class ContextInfo
java.lang.Object
org.pipservices3.components.info.ContextInfo
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable
,org.pipservices3.commons.config.IReconfigurable
public final class ContextInfo extends Object implements org.pipservices3.commons.config.IReconfigurable
Context information component that provides detail information
about execution context: container or/and process.
Most often ContextInfo is used by logging and performance counters to identify source of the collected logs and metrics.
### Configuration parameters ###
- name: the context (container or process) name
- description: human-readable description of the context
- properties: entire section of additional descriptive properties
- ...
### Example ###
ContextInfo contextInfo = new ContextInfo();
contextInfo.configure(ConfigParams.fromTuples(
"name", "MyMicroservice",
"description", "My first microservice"
));
context.getName(); // Result: "MyMicroservice"
context.getContextId(); // Possible result: "mylaptop"
context.getStartTime(); // Possible result: 2018-01-01:22:12:23.45Z
context.getUptime(); // Possible result: 3454345
-
Constructor Summary
Constructors Constructor Description ContextInfo()
Creates a new instance of this context info.ContextInfo(String name, String description)
Creates a new instance of this context info. -
Method Summary
Modifier and Type Method Description void
configure(org.pipservices3.commons.config.ConfigParams config)
Configures component by passing configuration parameters.static ContextInfo
fromConfig(org.pipservices3.commons.config.ConfigParams config)
Creates a new ContextInfo and sets its configuration parameters.String
getContextId()
Gets the unique context id.String
getDescription()
Gets the human-readable description of the context.String
getName()
Gets the context name.org.pipservices3.commons.data.StringValueMap
getProperties()
Gets context additional parameters.ZonedDateTime
getStartTime()
Gets the context start time.long
getUptime()
Calculates the context uptime as from the start time.void
setContextId(String contextId)
Sets the unique context id.void
setDescription(String _description)
Sets the human-readable description of the context.void
setName(String _name)
Sets the context name.void
setProperties(org.pipservices3.commons.data.StringValueMap _properties)
Sets context additional parameters.void
setStartTime(ZonedDateTime startTime)
Sets the context start time.void
setUptime(long uptime)
Sets context uptime parameter.
-
Constructor Details
-
ContextInfo
public ContextInfo()Creates a new instance of this context info. -
ContextInfo
Creates a new instance of this context info.- Parameters:
name
- (optional) a context name.description
- (optional) a human-readable description of the context.
-
-
Method Details
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.- Specified by:
configure
in interfaceorg.pipservices3.commons.config.IConfigurable
- Parameters:
config
- configuration parameters to be set.
-
getName
Gets the context name.- Returns:
- the context name
-
setName
Sets the context name.- Parameters:
_name
- a new name for the context.
-
getDescription
Gets the human-readable description of the context.- Returns:
- the human-readable description of the context.
-
setDescription
Sets the human-readable description of the context.- Parameters:
_description
- a new human readable description of the context.
-
getContextId
Gets the unique context id. Usually it is the current host name.- Returns:
- the unique context id.
-
setContextId
Sets the unique context id.- Parameters:
contextId
- a new unique context id.
-
getStartTime
Gets the context start time.- Returns:
- the context start time.
-
setStartTime
Sets the context start time.- Parameters:
startTime
- a new context start time.
-
getUptime
public long getUptime()Calculates the context uptime as from the start time.- Returns:
- number of milliseconds from the context start time.
-
setUptime
public void setUptime(long uptime)Sets context uptime parameter.- Parameters:
uptime
- a new uptime parameter.
-
getProperties
public org.pipservices3.commons.data.StringValueMap getProperties()Gets context additional parameters.- Returns:
- a JSON object with additional context parameters.
-
setProperties
public void setProperties(org.pipservices3.commons.data.StringValueMap _properties)Sets context additional parameters.- Parameters:
_properties
- a JSON object with context additional parameters
-
fromConfig
Creates a new ContextInfo and sets its configuration parameters.- Parameters:
config
- configuration parameters for the new ContextInfo.- Returns:
- a newly created ContextInfo
-