ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Attributes | List of all members
adctk.factory.Factory Class Reference

factory for adctk api objects. More...

Public Member Functions

 __init__ (self)
 

Static Public Member Functions

builder.Builder get_builder ()
 Create an empty builder object or subobject for an adctk message.
 
list[str] get_publisher_names ()
 Get the names of publishers available.
 
publisher.Publisher|None get_publisher (str name, dict[str] options=None)
 Get a configured instance of the named publisher type.
 
publisher.MultiPublisher get_multi_publisher (strict=False, str|list[str]|dict|None plugins=None)
 Get a MultiPublisher for use or manually populating.
 

Static Public Attributes

 API_VERSION = adc_version.AdcVersion()._dict()
 

Static Protected Attributes

dict _publishers = {}
 

Detailed Description

factory for adctk api objects.

Constructor & Destructor Documentation

◆ __init__()

adctk.factory.Factory.__init__ (   self)
135 def __init__(self):
136 pass # Factory.__init__ nothing to do

Member Function Documentation

◆ get_builder()

builder.Builder adctk.factory.Factory.get_builder ( )
static

Create an empty builder object or subobject for an adctk message.

Returns
an empty message builder object
44 def get_builder() -> builder.Builder:
45 """! @brief Create an empty builder object or subobject for an adctk message.
46
47 @return an empty message builder object"""
48 return builder.Builder()
49

◆ get_multi_publisher()

publisher.MultiPublisher adctk.factory.Factory.get_multi_publisher (   strict = False,
str|list[str]|dict|None   plugins = None 
)
static

Get a MultiPublisher for use or manually populating.

MultiPublisher provides a convenient way to publish on multiple publishers without duplicate calls to a publish() function. Options:

Parameters
strictIf strict=True, a failure to construct any named publisher will return None instead of a multipublisher, otherwise failed or unknown publishers will be silently ignored.
pluginscan be one of:
  • None, which then constructs plugins using the name list from env("ADC_MULTI_PUBLISHER_NAMES") and their environment-defined or default options. If ADC_MULTI_PUBLISHER_NAMES is unset, an empty MultiPublisher ready to configure is returned.
  • A string naming an alternative environment variable to ADC_MULTI_PUBLISHER_NAMES. E.g. a library foo may use FOO_MULTI_PUBLISHER_NAMES.
  • A list of names from among those returned by get_publisher_names, where each named plugin is configured from environment-defined or default options. An empty list is treated as None.
  • A dictionary of dictionaries, where the top keys are plugin names and the dictionary values are as documented in each plugin.

Empty example: add individual configured publisher to result. mp = get_multi_publisher() mp.add(...)

From environment ADC_MULTI_PUBLISHER_NAMES example m1 = get_multi_publisher(plugins=[]) m1.add(...)

From environment MY_APP_MULTI_PUBLISHER_NAMES example m1 = get_multi_publisher(plugins="MY_APP_MULTI_PUBLISHER_NAMES") m1.add(...)

Configure several plugins using environment m2 = get_multi_publisher(plugins=["stdout","http"])

Configure several plugins using environment and option overrides m3 = get_multi_publisher(plugins={"stdout":{}, "http":{"port": "8443", "url": "localhost"}})

88 plugins: str|list[str]|dict|None =None) -> publisher.MultiPublisher:
89 """! Get a MultiPublisher for use or manually populating.
90
91 MultiPublisher provides a convenient way to publish on multiple
92 publishers without duplicate calls to a publish() function.
93 Options:
94
95 @param strict If strict=True, a failure to construct any named
96 publisher will return None instead of a multipublisher, otherwise
97 failed or unknown publishers will be silently ignored.
98
99 @param plugins can be one of:
100 - None, which then constructs plugins using the name list from
101 env("ADC_MULTI_PUBLISHER_NAMES") and their environment-defined
102 or default options.
103 If ADC_MULTI_PUBLISHER_NAMES is unset, an empty MultiPublisher ready
104 to configure is returned.
105 - A string naming an alternative environment variable to ADC_MULTI_PUBLISHER_NAMES.
106 E.g. a library foo may use FOO_MULTI_PUBLISHER_NAMES.
107 - A list of names from among those returned by get_publisher_names,
108 where each named plugin is configured from environment-defined or
109 default options. An empty list is treated as None.
110 - A dictionary of dictionaries, where the top keys are plugin names and
111 the dictionary values are as documented in each plugin.
112
113 Empty example: add individual configured publisher to result.
114 mp = get_multi_publisher()
115 mp.add(...)
116
117 From environment ADC_MULTI_PUBLISHER_NAMES example
118 m1 = get_multi_publisher(plugins=[])
119 m1.add(...)
120
121 From environment MY_APP_MULTI_PUBLISHER_NAMES example
122 m1 = get_multi_publisher(plugins="MY_APP_MULTI_PUBLISHER_NAMES")
123 m1.add(...)
124
125 Configure several plugins using environment
126 m2 = get_multi_publisher(plugins=["stdout","http"])
127
128 Configure several plugins using environment and option overrides
129 m3 = get_multi_publisher(plugins={"stdout":{},
130 "http":{"port": "8443", "url": "localhost"}})
131
132 """
133 return publisher.MultiPublisher(strict, plugins)
134

◆ get_publisher()

publisher.Publisher|None adctk.factory.Factory.get_publisher ( str  name,
dict[str]   options = None 
)
static

Get a configured instance of the named publisher type.

Parameters
nameone of the elements found with get_publisher_names().
optionsa map of option names and their values; plugins will silently ignore unused options. publisher.config(options) and initialize will be called unless options is None. To apply a default configuration, give the empty {} instead of None.
Returns
a publisher instance, or None if the name is unavailable.
64 def get_publisher(name: str, options: dict[str] =None) -> publisher.Publisher|None:
65 """! Get a configured instance of the named publisher type.
66
67 @param name one of the elements found with get_publisher_names().
68 @param options a map of option names and their values; plugins will
69 silently ignore unused options. publisher.config(options)
70 and initialize will be called unless options is None.
71 To apply a default configuration, give the empty {} instead of None.
72 @return a publisher instance, or None if the name is unavailable.
73 """
74 if name in Factory.get_publisher_names():
75 x = Factory._publishers[name]()
76 if x:
77 if not options:
78 return x
79 x.config(options)
80 x.initialize()
81 return x
82 if not isinstance(name, str):
83 raise ValueError(f"get_publisher expects a string name: got {name}")
84 return None
85

◆ get_publisher_names()

list[str] adctk.factory.Factory.get_publisher_names ( )
static

Get the names of publishers available.

Returns
the names of publishers available. The "none", "stdout", "file", "multifile", "syslog", and "script" publishers are always available in Linux environments.
51 def get_publisher_names() -> list[str]:
52 """! @brief Get the names of publishers available.
53
54 @return the names of publishers available.
55 The "none", "stdout", "file", "multifile", "syslog", and "script" publishers
56 are always available in Linux environments.
57 """
58 if not Factory._publishers:
59 for cls in _get_subclasses(publisher.Publisher):
60 Factory._publishers[cls._name] = cls
61 return Factory._publishers.keys()
62

Member Data Documentation

◆ _publishers

dict adctk.factory.Factory._publishers = {}
staticprotected

◆ API_VERSION

adctk.factory.Factory.API_VERSION = adc_version.AdcVersion()._dict()
static

The documentation for this class was generated from the following file: