1 | ;
|
2 | /**
|
3 | * Copyright 2019, OpenCensus Authors
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.metricProducerManagerInstance = void 0;
|
19 | const validations_1 = require("../../common/validations");
|
20 | /**
|
21 | * Keeps a set of MetricProducer that is used by exporters to determine the
|
22 | * metrics that need to be exported.
|
23 | */
|
24 | class BaseMetricProducerManager {
|
25 | constructor() {
|
26 | this.metricProducers = new Set();
|
27 | }
|
28 | /** Gets the instance. */
|
29 | static get instance() {
|
30 | return this.singletonInstance || (this.singletonInstance = new this());
|
31 | }
|
32 | /**
|
33 | * Adds the MetricProducer to the manager if it is not already present.
|
34 | *
|
35 | * @param metricProducer The MetricProducer to be added to the manager.
|
36 | */
|
37 | add(metricProducer) {
|
38 | validations_1.validateNotNull(metricProducer, 'metricProducer');
|
39 | if (!this.metricProducers.has(metricProducer)) {
|
40 | this.metricProducers.add(metricProducer);
|
41 | }
|
42 | }
|
43 | /**
|
44 | * Removes the MetricProducer to the manager if it is present.
|
45 | *
|
46 | * @param metricProducer The MetricProducer to be removed from the manager.
|
47 | */
|
48 | remove(metricProducer) {
|
49 | validations_1.validateNotNull(metricProducer, 'metricProducer');
|
50 | this.metricProducers.delete(metricProducer);
|
51 | }
|
52 | /**
|
53 | * Clears all MetricProducers.
|
54 | */
|
55 | removeAll() {
|
56 | this.metricProducers.clear();
|
57 | }
|
58 | /**
|
59 | * Returns all registered MetricProducers that should be exported.
|
60 | *
|
61 | * This method should be used by any metrics exporter that automatically
|
62 | * exports data for MetricProducer registered with the MetricProducerManager.
|
63 | *
|
64 | * @return {Set<MetricProducer>} The Set of MetricProducers.
|
65 | */
|
66 | getAllMetricProducer() {
|
67 | return this.metricProducers;
|
68 | }
|
69 | }
|
70 | exports.metricProducerManagerInstance = BaseMetricProducerManager.instance;
|
71 | //# sourceMappingURL=metric-producer-manager.js.map |
\ | No newline at end of file |