Back to godoc.org

Package facility

v1.3.0
Latest Go to latest

The latest major version is v2.

Published: Feb 8, 2019 | License: Apache-2.0 | Module: github.com/graniticio/granitic

Overview

Package facility defines the high-level features that Granitic makes available to applications.

A facility is Granitic's term for a group of components that together provide a high-level feature to application developers, like logging or service error management. This package contains several sub-packages, one for each facility that can be enabled and configured by user applications.

A full description of how facilities can be enabled and configured can be found at http://granitic.io/1.0/ref/facilities but a basic description of how they work follows:

Enabling and disabling facilities

The features that are available to applications, and whether they are enabled by default or not, are enumerated in the file:

$GRANITIC_HOME/resource/facility-config/facilities.json

which will look something like:

{
  "Facilities": {
	"HttpServer": false,
	"JsonWs": false,
	"XmlWs": false,
	"FrameworkLogging": true,
	"ApplicationLogging": true,
	"QueryManager": false,
	"RdbmsAccess": false,
	"ServiceErrorManager": false,
	"RuntimeCtl": false,
	"TaskScheduler": false
  }
}

This shows that the ApplicationLogging and FrameworkLogging facilities are enabled by default, but everything else is turned off. If you wanted to enable the HttpServer facility, you'd add the following to any of your application's configuration files:

{
  "Facilities": {
	"HttpServer": true
  }
}

Configuring facilities

Each facility has a number of default settings that can be found in the file:

$GRANITIC_HOME/resource/facility-config/facilityname.json

For example, the default configuration for the HttpServer facility will look something like:

  {
    "HttpServer":{
      "Port": 8080,
	  "AccessLogging": false,
	  "TooBusyStatus": 503,
	  "AutoFindHandlers": true
    }
  }

Any of these settings can be changed by overriding one or more of the fields in your application's configuration file. For example, to change the port on which your application's HTTP server listens on, you could add the following to any of your application's configuration files:

{
  "HttpServer":{
    "Port": 9000
  }
}

Index

func BootstrapFrameworkLogging

func BootstrapFrameworkLogging(bootStrapLogLevel logging.LogLevel) (*logging.ComponentLoggerManager, *ioc.ProtoComponent)

BootstrapFrameworkLogging creates a ComponentLoggerManager that can be used to create Loggers used by internal Granitic components during the bootstrap (pre-configuration load) phase of application startup.

type FacilitiesInitialisor

type FacilitiesInitialisor struct {
	// Access to the merged view of application configuration.
	ConfigAccessor *config.ConfigAccessor

	//A ComponentLoggerManager able to create Loggers for built-in Granitic components.
	FrameworkLoggingManager *logging.ComponentLoggerManager

	//Allows the FacilitiesInitialisor to log problems during facility initialisation.
	Logger logging.Logger
	// contains filtered or unexported fields
}

The FacilitiesInitialisor finds all the facilities that have been enabled by the user application and invokes their corresponding FacilityBuilder to initialise and configure them.

func NewFacilitiesInitialisor

func NewFacilitiesInitialisor(cc *ioc.ComponentContainer, flm *logging.ComponentLoggerManager) *FacilitiesInitialisor

NewFacilitiesInitialisor creates a new FacilitiesInitialisor with access to the IoC container and a ComponentLoggerManager

func (*FacilitiesInitialisor) Initialise

func (fi *FacilitiesInitialisor) Initialise(ca *config.ConfigAccessor) error

Initialise creates a FacilityBuilder for each of the built-in Granitic facilities and then builds those facilities that have been enabled by the user.

type FacilityBuilder

type FacilityBuilder interface {
	//BuildAndRegister constructs the components that together constitute the facility and stores them in the IoC
	// container.
	BuildAndRegister(lm *logging.ComponentLoggerManager, ca *config.ConfigAccessor, cn *ioc.ComponentContainer) error

	//FacilityName returns the facility's unique name. Used to check whether the facility is enabled in configuration.
	FacilityName() string

	//DependsOnFacilities returns the names of other facilities that must be enabled in order for this facility to run
	//correctly.
	DependsOnFacilities() []string
}

A facility builder is responsible for programmatically constructing the objects required to support a facility and, where required, adding them to the IoC container.

type InstanceIdDecorator

type InstanceIdDecorator struct {
	// The instance identity that will be injected into components.
	InstanceId *instance.InstanceIdentifier
}

Decorator to inject an InstanceIdentifier into components that need to be aware of the current application instance's ID.

func (*InstanceIdDecorator) DecorateComponent

func (id *InstanceIdDecorator) DecorateComponent(subject *ioc.Component, container *ioc.ComponentContainer)

DecorateComponent injects the InstanceIdentifier in to the subject component.

func (*InstanceIdDecorator) OfInterest

func (id *InstanceIdDecorator) OfInterest(subject *ioc.Component) bool

OfInterest returns true if the supplied component implements instance.InstanceIdentifierReceiver

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier