View Javadoc
1   /*
2    * Copyright (c) 2001-2017, Zoltan Farkas All Rights Reserved.
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   *
18   * Additionally licensed with:
19   *
20   * Licensed under the Apache License, Version 2.0 (the "License");
21   * you may not use this file except in compliance with the License.
22   * You may obtain a copy of the License at
23   *
24   *      http://www.apache.org/licenses/LICENSE-2.0
25   *
26   * Unless required by applicable law or agreed to in writing, software
27   * distributed under the License is distributed on an "AS IS" BASIS,
28   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29   * See the License for the specific language governing permissions and
30   * limitations under the License.
31   */
32  package org.spf4j.perf;
33  
34  import javax.annotation.Nonnull;
35  import javax.annotation.concurrent.Immutable;
36  import javax.management.openmbean.CompositeType;
37  import javax.management.openmbean.OpenDataException;
38  import javax.management.openmbean.OpenType;
39  import org.spf4j.tsdb2.avro.Aggregation;
40  import org.spf4j.tsdb2.avro.MeasurementType;
41  
42  /**
43   *
44   * @author zoly
45   */
46  @Immutable
47  public interface MeasurementsInfo {
48  
49    @Nonnull
50    Object getMeasuredEntity();
51  
52    @Nonnull
53    String getDescription();
54  
55    String[] getMeasurementNames();
56  
57    String[] getMeasurementUnits();
58  
59    Aggregation[] getAggregations();
60  
61    String getMeasurementName(int measurementNr);
62  
63    String getMeasurementUnit(int measurementNr);
64  
65    Aggregation getMeasurementAggregation(int measurementNr);
66  
67    int getNumberOfMeasurements();
68  
69    MeasurementType getMeasurementType();
70  
71    default CompositeType toCompositeType() {
72      OpenType<?>[] types = new OpenType[getNumberOfMeasurements()];
73      for (int i = 0; i < types.length; i++) {
74        types[i] = javax.management.openmbean.SimpleType.LONG;
75      }
76      try {
77        String entityName = getMeasuredEntity().toString();
78        String description = getDescription();
79        if (description.isEmpty()) {
80          description = entityName;
81        }
82        return new CompositeType(entityName, description, getMeasurementNames(), getMeasurementUnits(), types);
83      } catch (OpenDataException ex) {
84        throw new IllegalArgumentException("Cannot convert to composite data " + this, ex);
85      }
86    }
87  
88  }