All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glassfish.pfl.tf.spi.EnhancedClassDataBase Maven / Gradle / Ivy

There is a newer version: 4.0.4
Show newest version
/*
 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0, which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.glassfish.pfl.tf.spi;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author ken
 */
public abstract class EnhancedClassDataBase implements EnhancedClassData {
    protected Util util ;
    protected final Set annotationNames ;

    protected EnhancedClassDataBase( Util util, Set annotationNames ) {
        this.util = util ;
        this.annotationNames = annotationNames ;
    }

    protected String className ;

    protected final Set annoNamesForClass =
        new HashSet() ;

    // Map from MM annotation internal name to
    // SynchronizedHolder field
    // name.  Use something like __$mm$__nnn that is unlikely to collide with
    // another field name that is already in use.
    protected final Map annoToHolderName =
        new HashMap() ;

    // List of tracing names of MM methods.  Index of method is identifier in
    // MethodMonitor calls.  Sorted to guarantee consistent order.
    protected final List methodNames =
        new ArrayList() ;

    // List of descriptions of methods.  This is in the same order as
    // methodNames.
    protected final List methodDescriptions = 
        new ArrayList() ;

    // List of timing point types of methods.  This is in the same order as
    // methodNames.  All names of monitored methods have type BOTH;
    // names of info methods may be ENTER, EXIT, or NONE.
    protected final List methodTPTs =
        new ArrayList() ;

    protected final List methodTPNames =
        new ArrayList() ;

    // List of annotations of methods.  This is in the same order as
    // methodNames.  If the method is a monitored method, this is the
    // annotation on the method; if the method is an info method, this is
    // null.
    protected final List methodAnnoList = 
        new ArrayList() ;

    // List of descriptors of @InfoMethod-annotated methods.
    // Needed for validating and transforming calls to such methods.
    protected final Set infoMethodDescs =
        new HashSet() ;

    protected final Set mmMethodDescs =
        new HashSet() ;

    // Map from method signature to internal name of its MM annotation.
    protected final Map methodToAnno =
        new HashMap() ;

    public String getClassName() {
        return className ;
    }

    public Map getAnnotationToHolderName() {
        return annoToHolderName ;
    }

    public List getMethodNames() {
        return methodNames ;
    }
    
    public int getMethodIndex( String methodName ) {
        if (methodName != null) {
            for (int ctr = 0; ctr < methodNames.size(); ctr++) {
                if (methodName.equals(methodNames.get(ctr))) {
                    return ctr ;
                }
            }
        }

        return -1 ;
    }
    
    public String getHolderName( String fullMethodDescriptor ) {
        String aname = methodToAnno.get( fullMethodDescriptor ) ;
        String result = annoToHolderName.get( aname ) ;
        return result ;
    }
    
    public MethodType classifyMethod( String fullMethodDescriptor ) {
        if (fullMethodDescriptor.equals( "()V")) {
            return MethodType.STATIC_INITIALIZER ;
        } else if (infoMethodDescs.contains( fullMethodDescriptor )) {
            return MethodType.INFO_METHOD ;
        } else if (mmMethodDescs.contains( fullMethodDescriptor)) {
            return MethodType.MONITORED_METHOD ;
        } else {
            return MethodType.NORMAL_METHOD ;
        }
    }
    
    public boolean isTracedClass() {
        return !annoNamesForClass.isEmpty() ;
    }

    public void updateInfoDesc() {
        String[] descs = infoMethodDescs.toArray( 
            new String[infoMethodDescs.size() ] ) ;

        infoMethodDescs.clear() ;

        for (String desc : descs) {
            int index = desc.indexOf( '(' ) ;
            String name = desc.substring( 0, index )  ;
            String d = desc.substring( index ) ;
            String fd = util.augmentInfoMethodDescriptor(d) ;
            infoMethodDescs.add( name + fd ) ;
        }
    }

    /** List of descriptions of monitored methods and info methods.
     * If no description was given in the annotations, the value is "".
     *
     * @return List of descriptions in the same order as in
     * getMethodTracingNames.
     */
    public List getDescriptions() {
        return methodDescriptions ;
    }

    /** List of timing point types of monitored methods and info methods.
     * The list contains BOTH for a monitored method.  An info method that
     * does not represent a timing point is represented by NONE.
     *
     * @return List of TimingPointTypes in the same order as in
     * getMethodTracingNames.
     */
    public List getTimingPointTypes() {
        return methodTPTs ;
    }

    public List getTimingPointNames() {
        return methodTPNames ;
    }

    public List getMethodMMAnnotationName() {
        return methodAnnoList ;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy