From notifications-return-6629-archive-asf-public=cust-asf.ponee.io@ignite.apache.org Mon Sep 9 13:32:49 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7692A18065C for ; Mon, 9 Sep 2019 15:32:48 +0200 (CEST) Received: (qmail 9856 invoked by uid 500); 9 Sep 2019 13:32:48 -0000 Mailing-List: contact notifications-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list notifications@ignite.apache.org Received: (qmail 9756 invoked by uid 99); 9 Sep 2019 13:32:47 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Sep 2019 13:32:47 +0000 From: GitBox To: notifications@ignite.apache.org Subject: [GitHub] [ignite] alex-plekhanov commented on a change in pull request #6845: IGNITE-12145: Monitoring list engine. Message-ID: <156803596777.22949.3687608861434816946.gitbox@gitbox.apache.org> Date: Mon, 09 Sep 2019 13:32:47 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit alex-plekhanov commented on a change in pull request #6845: IGNITE-12145: Monitoring list engine. URL: https://github.com/apache/ignite/pull/6845#discussion_r321754188 ########## File path: modules/codegen/src/main/java/org/apache/ignite/codegen/MonitoringRowAttributeWalkerGenerator.java ########## @@ -0,0 +1,283 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.ignite.codegen; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.ObjIntConsumer; +import org.apache.ignite.internal.processors.metric.list.walker.Order; +import org.apache.ignite.spi.metric.jmx.MonitoringListMBean; +import org.apache.ignite.spi.metric.list.MonitoringList; +import org.apache.ignite.spi.metric.list.MonitoringRow; +import org.apache.ignite.spi.metric.list.MonitoringRowAttributeWalker; +import org.apache.ignite.spi.metric.list.view.CacheGroupView; +import org.apache.ignite.spi.metric.list.view.CacheView; +import org.apache.ignite.spi.metric.list.view.ComputeTaskView; +import org.apache.ignite.spi.metric.list.view.ServiceView; + +import static org.apache.ignite.codegen.MessageCodeGenerator.DFLT_SRC_DIR; +import static org.apache.ignite.codegen.MessageCodeGenerator.TAB; + +/** + * Application for code generation of {@link MonitoringRowAttributeWalker}. + * Usage: simply run main method from Ignite source folder(using IDE or other way). + * Generated code used in {@link MonitoringList}. + * + * @see MonitoringListMBean + * @see MonitoringListLocalSystemView + */ +public class MonitoringRowAttributeWalkerGenerator { + /** Methods that should be excluded from specific {@link MonitoringRowAttributeWalker}. */ + private static final Set SYS_METHODS = new HashSet<>(Arrays.asList("equals", "hashCode", "toString", + "getClass", "monitoringRowId")); + + /** Package for {@link MonitoringRowAttributeWalker} implementations. */ + public static final String WALKER_PACKAGE = "org.apache.ignite.internal.processors.metric.list.walker"; + + /** + * @throws Exception If generation failed. + */ + public static void main(String[] args) throws Exception { + MonitoringRowAttributeWalkerGenerator gen = new MonitoringRowAttributeWalkerGenerator(); + + gen.generateAndWrite(CacheGroupView.class, DFLT_SRC_DIR); + gen.generateAndWrite(CacheView.class, DFLT_SRC_DIR); + gen.generateAndWrite(ServiceView.class, DFLT_SRC_DIR); + gen.generateAndWrite(ComputeTaskView.class, DFLT_SRC_DIR); + } + + /** + * Generates {@link MonitoringRowAttributeWalker} implementation and write it to the file. + * + * @param clazz Class to geneare {@link MonitoringRowAttributeWalker} for. + * @param srcRoot Source root folder. + * @param type of the {@link MonitoringRow}. + * @throws IOException If generation failed. + */ + private > void generateAndWrite(Class clazz, String srcRoot) throws IOException { + File walkerClass = new File(srcRoot + '/' + WALKER_PACKAGE.replaceAll("\\.", "/") + '/' + + clazz.getSimpleName() + "Walker.java"); + + Collection code = generate(clazz); + + walkerClass.createNewFile(); + + try (FileWriter writer = new FileWriter(walkerClass)) { + for (String line : code) { + writer.write(line); + writer.write('\n'); + } + } + } + + /** + * Generates {@link MonitoringRowAttributeWalker} implementation. + * + * @param clazz Class to geneare {@link MonitoringRowAttributeWalker} for. + * @param type of the {@link MonitoringRow}. + * @return Java source code of the {@link MonitoringRowAttributeWalker} implementation. + */ + private > Collection generate(Class clazz) { + final List code = new ArrayList<>(); + final Set imports = new TreeSet<>(); + + imports.add("import " + MonitoringRowAttributeWalker.class.getName() + ';'); + imports.add("import " + clazz.getName() + ';'); + + String simpleName = clazz.getSimpleName(); + + code.add("package " + WALKER_PACKAGE + ";"); + code.add(""); + code.add("/**"); + code.add(" * Generated by {@code " + MonitoringRowAttributeWalkerGenerator.class.getName() + "}."); + code.add(" * {@link " + simpleName + "} attributes walker."); + code.add(" * "); + code.add(" * @see " + simpleName); + code.add(" */"); + code.add("public class " + simpleName + "Walker implements MonitoringRowAttributeWalker<" + simpleName + "> {"); + code.add(TAB + "/** {@inheritDoc} */"); + code.add(TAB + "@Override public void visitAll(AttributeVisitor v) {"); + + forEachMethod(clazz, (m, i) -> { + String name = m.getName(); + + Class retClazz = m.getReturnType(); + + String line = TAB + TAB; + + if (!retClazz.isPrimitive()) { + if (!retClazz.getName().startsWith("java.lang")) + imports.add("import " + retClazz.getName() + ';'); + + line += "v.accept(" + i + ", \"" + name + "\", " + retClazz.getSimpleName() + ".class);"; + } else if (retClazz == boolean.class) Review comment: NL ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services