com.google.testing.threadtester.CallLoggerFactory Maven / Gradle / Ivy
Show all versions of threadweaver Show documentation
/*
* Copyright 2009 Weaver 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 com.google.testing.threadtester;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Creates a {@link CallLogger} for every instrumented class. A reference to
* this class is added to the bytecode of any class instrumented by the
* {@link TestInstrumenter}.
*
* This class is made public in order to allow instrumented classes to call it,
* but it should not be called otherwise.
*
* @author [email protected] (Alasdair Mackintosh)
*/
public class CallLoggerFactory {
/**
* The current instance of CallLoggerFactory. This is a static, initialized
* the first time we call {@link #getFactory}. It is made static because we
* need a way to obtain a call logger inside the constructor of each
* instrumented class.
*/
private static CallLoggerFactory factory;
/**
* Maps an Object onto the corresponding instrumentation data. Note that we
* use an IdentityHashMap. We always want to track each object independently,
* regardless of the object's implementation of hashCode and equals. Plus, we
* don't want to have to invoke the object's hashCode() and equals() methods
* during its own constructor, as it may not be designed to allow that. (See
* {@link #getObjectInstrumentation}, which is called from within an
* instrumented object's constructor.
*/
private IdentityHashMap