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 Details

    • ContextInfo

      public ContextInfo()
      Creates a new instance of this context info.
    • ContextInfo

      public ContextInfo​(String name, String description)
      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 interface org.pipservices3.commons.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.
    • getName

      public String getName()
      Gets the context name.
      Returns:
      the context name
    • setName

      public void setName​(String _name)
      Sets the context name.
      Parameters:
      _name - a new name for the context.
    • getDescription

      public String getDescription()
      Gets the human-readable description of the context.
      Returns:
      the human-readable description of the context.
    • setDescription

      public void setDescription​(String _description)
      Sets the human-readable description of the context.
      Parameters:
      _description - a new human readable description of the context.
    • getContextId

      public String getContextId()
      Gets the unique context id. Usually it is the current host name.
      Returns:
      the unique context id.
    • setContextId

      public void setContextId​(String contextId)
      Sets the unique context id.
      Parameters:
      contextId - a new unique context id.
    • getStartTime

      public ZonedDateTime getStartTime()
      Gets the context start time.
      Returns:
      the context start time.
    • setStartTime

      public void setStartTime​(ZonedDateTime startTime)
      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

      public static ContextInfo fromConfig​(org.pipservices3.commons.config.ConfigParams config)
      Creates a new ContextInfo and sets its configuration parameters.
      Parameters:
      config - configuration parameters for the new ContextInfo.
      Returns:
      a newly created ContextInfo