|
Groovy example source code file (JmxOperationInfoManager.groovy)
The Groovy JmxOperationInfoManager.groovy source code/* * Copyright 2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package groovy.jmx.builder import javax.management.Descriptor import javax.management.MBeanParameterInfo import javax.management.modelmbean.DescriptorSupport import javax.management.modelmbean.ModelMBeanConstructorInfo import javax.management.modelmbean.ModelMBeanOperationInfo /** * This class is responsible for assembling JMX Operation Info from the meta map. * It cycles through the provided meta map from the bean() node and generate JMX Info objects used to * expose information in the MBeanServer. * * @author Vladimir Vivien * * @see groovy.jmx.builder.JmxMetaMapBuilder * */ class JmxOperationInfoManager { /** * * This method extracts an array of MBeanConstructorInfo from a list of meta maps. * @param list of meta maps * @return array of ModelMBeanConstructorInfo */ public static List<ModelMBeanConstructorInfo> getConstructorInfosFromMap(Map metaMap) { if (!metaMap) return null def ctors = [] metaMap.each {ctorName, map -> ModelMBeanConstructorInfo info = getConstructorInfoFromMap(map) ctors << info } return ctors } /** * * This method extracts ModelMBeanConstructorInfo from provided meta map. * It also iterates over any parameters and builds the necessary MBeanParameterInfo array. * @param meta map containing descriptor information * @return the fully realized ModelMBeanConstructorInfo for the provided constructor reference. */ public static ModelMBeanConstructorInfo getConstructorInfoFromMap(Map map) { if (!map) return null def ctor = map.remove("constructor") if (!ctor) { throw new JmxBuilderException("Unable generate ModelMBeanConstructorInfo, missing constructor reference.") } MBeanParameterInfo[] params = (MBeanParameterInfo[]) buildParamInfosFromMaps(map.remove("params")) Descriptor desc = new DescriptorSupport() desc.setField(JmxBuilderTools.DESC_KEY_NAME, map.remove(JmxBuilderTools.DESC_KEY_NAME)) desc.setField(JmxBuilderTools.DESC_KEY_TYPE, JmxBuilderTools.DESC_VAL_TYPE_OP) desc.setField(JmxBuilderTools.DESC_KEY_ROLE, map.remove(JmxBuilderTools.DESC_KEY_ROLE)) desc.setField JmxBuilderTools.DESC_KEY_DISPLAY_NAME, map.remove(JmxBuilderTools.DESC_KEY_DISPLAY_NAME) map.each {key, value -> desc.setField(key, value) } ModelMBeanConstructorInfo info = new ModelMBeanConstructorInfo( ctor.name, (String) desc.getFieldValue(JmxBuilderTools.DESC_KEY_DISPLAY_NAME), params, desc ) return info } /** * * This method extracts an array of MBeanOperationInfo from a list of meta maps. * @param list of meta maps * @return array of ModelMBeanOperationInfo */ public static List<ModelMBeanOperationInfo> getOperationInfosFromMap(Map metaMap) { if (!metaMap) return null def ops = [] metaMap.each {opNames, map -> ModelMBeanOperationInfo info = getOperationInfoFromMap(map) ops << info } return ops } /** * * Generates a ModelMBeanOperationInfo object from a meta map provided. * @param the meta map for the method * @return the generated ModelMBeanOprationInfo */ public static ModelMBeanOperationInfo getOperationInfoFromMap(Map map) { if (!map) return null MetaMethod method = map.remove("method") if (!method) { throw new JmxBuilderException("Unable to generate ModelMBeanOperationInfo, missing method reference.") } MBeanParameterInfo[] params = (MBeanParameterInfo[]) buildParamInfosFromMaps(map.remove("params")) Descriptor desc = new DescriptorSupport() desc.setField(JmxBuilderTools.DESC_KEY_NAME, map.remove(JmxBuilderTools.DESC_KEY_NAME)) desc.setField(JmxBuilderTools.DESC_KEY_TYPE, JmxBuilderTools.DESC_VAL_TYPE_OP) desc.setField(JmxBuilderTools.DESC_KEY_ROLE, map.remove(JmxBuilderTools.DESC_KEY_ROLE)) desc.setField JmxBuilderTools.DESC_KEY_DISPLAY_NAME, map.remove(JmxBuilderTools.DESC_KEY_DISPLAY_NAME) ModelMBeanOperationInfo info = new ModelMBeanOperationInfo( method.name, (String) desc.getFieldValue(JmxBuilderTools.DESC_KEY_DISPLAY_NAME), params, method.returnType.name, ModelMBeanOperationInfo.ACTION, desc ) return info } /** * Build an array of MBeanParameterInfo from the operation's meta map. * @param the meta map containing the param info * @return an array of JMX MBeanParameterInfo */ public static List<MBeanParameterInfo> buildParamInfosFromMaps(Map metaMap) { if (!metaMap || metaMap.size() == 0) return null List<MBeanParameterInfo> result = new ArrayList Other Groovy examples (source code examples)Here is a short list of links related to this Groovy JmxOperationInfoManager.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.