Package ariba.awreload.jmti

Source Code of ariba.awreload.jmti.JVMTIClient

package ariba.awreload.jmti;

import java.lang.instrument.ClassDefinition;
import java.lang.instrument.Instrumentation;

public class JVMTIClient
{
    public JVMTIClient() {
        if (!Agent.getInstrumentation().isRedefineClassesSupported()) {
            throw new UnsupportedOperationException("This Java 5 does not support JVMTI redefine()");
        }
    }

    // hotswap (ClassDefinition[] defns, Boolean[]succeeded)

    public void hotswap (ClassDefinition[] changes, Boolean[] succeeded)
    {
        Instrumentation instrumentation = Agent.getInstrumentation();
        if (!instrumentation.isRedefineClassesSupported()) {
            //TODO - should we fail ?
            return;
        }

        // try to reload them all
        try {
            instrumentation.redefineClasses(changes);
            for (int i=0; i<changes.length; i++) succeeded[i] = true;
        } catch (Exception e) {
            // throw new AWGenericException(e);
            if (changes.length == 1) {
                succeeded[0] = false;
            } else {
                // we failed to load one or more, so try to load them individually
                for (int i=0; i<changes.length; i++) {
                    ClassDefinition[] change = new ClassDefinition[] {changes[i]};
                    try {
                        instrumentation.redefineClasses(change);
                        succeeded[i] = true;
                    } catch (Exception e2) {
                        succeeded[i] = false;
                    }
                }
            }
        }
    }
}
TOP

Related Classes of ariba.awreload.jmti.JVMTIClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.