Search in sources :

Example 31 with CFMLEngine

use of lucee.loader.engine.CFMLEngine in project Lucee by lucee.

the class InstrumentationFactory method getInstrumentation.

public static synchronized Instrumentation getInstrumentation(final Config config) {
    final Log log = config.getLog("application");
    final CFMLEngine engine = ConfigWebUtil.getEngine(config);
    Instrumentation instr = _getInstrumentation(log, config);
    // agent already exist
    if (instr != null)
        return instr;
    AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            ClassLoader ccl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
            try {
                JavaVendor vendor = JavaVendor.getCurrentVendor();
                Resource toolsJar = null;
                // When running on IBM, the attach api classes are packaged in vm.jar which is a part
                // of the default vm classpath.
                RefBoolean useOurOwn = new RefBooleanImpl(true);
                // if (!vendor.isIBM()) {
                // If we can't find the tools.jar and we're not on IBM we can't load the agent.
                toolsJar = findToolsJar(config, log, useOurOwn);
                if (toolsJar == null) {
                    return null;
                }
                // }
                log.info("Instrumentation", "tools.jar used:" + toolsJar);
                // add the attach native library
                if (useOurOwn.toBooleanValue())
                    addAttachIfNecessary(config, log);
                Class<?> vmClass = loadVMClass(toolsJar, log, vendor);
                log.info("Instrumentation", "loaded VirtualMachine class:" + (vmClass == null ? "null" : vmClass.getName()));
                if (vmClass == null) {
                    return null;
                }
                String agentPath = createAgentJar(log, config).getAbsolutePath();
                if (agentPath == null) {
                    return null;
                }
                log.info("Instrumentation", "try to load agent (path:" + agentPath + ")");
                loadAgent(config, log, agentPath, vmClass);
            // log.info("Instrumentation","agent loaded (path:"+agentPath+")");
            } catch (IOException ioe) {
                log.log(Log.LEVEL_INFO, "Instrumentation", ioe);
            } finally {
                Thread.currentThread().setContextClassLoader(ccl);
            }
            return null;
        }
    });
    // If the load(...) agent call was successful, this variable will no
    // longer be null.
    instr = _getInstrumentation(log, config);
    if (instr == null) {
        try {
            Resource agentJar = createAgentJar(log, config);
            throw new PageRuntimeException(new ApplicationException(Constants.NAME + " was not able to load a Agent dynamically! " + "You need to load one manually by adding the following to your JVM arguments [-javaagent:\"" + (agentJar) + "\"]"));
        } catch (IOException ioe) {
            SystemOut.printDate(ioe);
        }
    }
    return instr;
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) Instrumentation(java.lang.instrument.Instrumentation) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) URLClassLoader(java.net.URLClassLoader) CFMLEngine(lucee.loader.engine.CFMLEngine) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Aggregations

CFMLEngine (lucee.loader.engine.CFMLEngine)31 File (java.io.File)10 IOException (java.io.IOException)9 CFMLEngineFactory (lucee.loader.engine.CFMLEngineFactory)9 Bundle (org.osgi.framework.Bundle)9 Resource (lucee.commons.io.res.Resource)6 BundleFile (lucee.runtime.osgi.BundleFile)5 BundleException (org.osgi.framework.BundleException)5 ServletException (javax.servlet.ServletException)4 BundleContext (org.osgi.framework.BundleContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Reader (java.io.Reader)3 BundleCollection (lucee.loader.osgi.BundleCollection)3 PageContext (lucee.runtime.PageContext)3 Struct (lucee.runtime.type.Struct)3 OutputStream (java.io.OutputStream)2 StringReader (java.io.StringReader)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2