Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.openjpa.enhance;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.instrument.Instrumentation;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.util.Locale;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.JavaVendors;
import org.apache.openjpa.lib.util.Localizer;
/**
* Factory for obtaining an {@link Instrumentation} instance.
*
* @author Marc Prud'hommeaux
* @since 1.0.0
*/
public class InstrumentationFactory {
private static Instrumentation _inst;
private static boolean _dynamicallyInstall = true;
private static final String _name = InstrumentationFactory.class.getName();
private static final Localizer _loc = Localizer.forPackage(
InstrumentationFactory.class);
/**
* This method is not synchronized because when the agent is loaded from
* getInstrumentation() that method will cause agentmain(..) to be called.
* Synchronizing this method would cause a deadlock.
*
* @param inst The instrumentation instance to be used by this factory.
*/
public static void setInstrumentation(Instrumentation inst) {
_inst = inst;
}
/**
* Configures whether or not this instance should attempt to dynamically
* install an agent in the VM. Defaults to true.
*/
public static synchronized void setDynamicallyInstallAgent(boolean val) {
_dynamicallyInstall = val;
}
/**
* @param log OpenJPA log.
* @return null if Instrumentation can not be obtained, or if any
* Exceptions are encountered.
*/
public static synchronized Instrumentation getInstrumentation(final Log log) {
if (log.isTraceEnabled()) {
log.trace(_name + ".getInstrumentation() _inst:" + _inst
+ " _dynamicallyInstall:" + _dynamicallyInstall);
}
if ( _inst != null || !_dynamicallyInstall)
return _inst;
AccessController.doPrivileged(new PrivilegedAction