Package java.lang.instrument

Examples of java.lang.instrument.Instrumentation


        ClassLoader loader = new FilteredChildFirstClassLoader(getClass().getClassLoader(), "org.apache.openejb.core.cmp.jpa");

        PersistenceClassLoaderHandler persistenceClassLoaderHandler = new PersistenceClassLoaderHandler() {

            public void addTransformer(String unitId, ClassLoader classLoader, ClassFileTransformer classFileTransformer) {
                Instrumentation instrumentation = Agent.getInstrumentation();
                if (instrumentation != null) {
                    instrumentation.addTransformer(new ControllableTransformer(classFileTransformer));
                }
            }

            public void destroy(String unitId) {
            }
View Full Code Here


        private final Map<String, List<ClassFileTransformer>> transformers = new TreeMap<String, List<ClassFileTransformer>>();

        @Override
        public void addTransformer(final String unitId, final ClassLoader classLoader, final ClassFileTransformer classFileTransformer) {
            final Instrumentation instrumentation = Agent.getInstrumentation();
            if (instrumentation != null) {
                instrumentation.addTransformer(classFileTransformer);

                if (unitId != null) {
                    List<ClassFileTransformer> transformers = this.transformers.get(unitId);
                    if (transformers == null) {
                        transformers = new ArrayList<ClassFileTransformer>(1);
View Full Code Here

        @Override
        public void destroy(final String unitId) {
            final List<ClassFileTransformer> transformers = this.transformers.remove(unitId);
            if (transformers != null) {
                final Instrumentation instrumentation = Agent.getInstrumentation();
                if (instrumentation != null) {
                    for (final ClassFileTransformer transformer : transformers) {
                        instrumentation.removeTransformer(transformer);
                    }
                } else {
                    logger.error("assembler.noAgent");
                }
            }
View Full Code Here

    public static void main(String args[]) throws IOException {
        JarFile bootclasses = new JarFile("BootSupport.jar");
        JarFile agentclasses = new JarFile("AgentSupport.jar");

        Instrumentation ins = Agent.getInstrumentation();

        // Test 1: Add BootSupport.jar to boot class path and check that
        // BootSupport is loaded by the bootstrap class loader
        ins.appendToBootstrapClassLoaderSearch(bootclasses);
        checkLoadedByLoader("BootSupport", null);

        // Test 2: Add AgentSupport.jar to the system class path and check that
        // AgentSupport is loaded by the system class loader.
        try {
            ins.appendToSystemClassLoaderSearch(agentclasses);
            checkLoadedByLoader("AgentSupport", ClassLoader.getSystemClassLoader());
        } catch (UnsupportedOperationException x) {
            System.out.println("System class loader does not support adding to class path");
        }
View Full Code Here


        JarFile bootclasses = new JarFile("BootSupport.jar");
        JarFile agentclasses = new JarFile("AgentSupport.jar");

        Instrumentation ins = Agent.getInstrumentation();

        ins.appendToBootstrapClassLoaderSearch(bootclasses);
        try {
            new BootSupport();
            System.out.println("FAIL: BootSupport resolved");
            failures++;
        } catch (NoClassDefFoundError x) {
            System.out.println("PASS: BootSupport failed to resolve");
        }

        try {
            ins.appendToSystemClassLoaderSearch(agentclasses);
            try {
                new AgentSupport();
                System.out.println("FAIL: AgentSupport resolved");
                failures++;
            } catch (NoClassDefFoundError x) {
View Full Code Here

        private final Map<String, List<ClassFileTransformer>> transformers = new TreeMap<String, List<ClassFileTransformer>>();

        @Override
        public void addTransformer(final String unitId, final ClassLoader classLoader, final ClassFileTransformer classFileTransformer) {
            final Instrumentation instrumentation = Agent.getInstrumentation();
            if (instrumentation != null) {
                instrumentation.addTransformer(classFileTransformer);

                if (unitId != null) {
                    List<ClassFileTransformer> transformers = this.transformers.get(unitId);
                    if (transformers == null) {
                        transformers = new ArrayList<ClassFileTransformer>(1);
View Full Code Here

        @Override
        public void destroy(final String unitId) {
            final List<ClassFileTransformer> transformers = this.transformers.remove(unitId);
            if (transformers != null) {
                final Instrumentation instrumentation = Agent.getInstrumentation();
                if (instrumentation != null) {
                    for (final ClassFileTransformer transformer : transformers) {
                        instrumentation.removeTransformer(transformer);
                    }
                } else {
                    logger.error("assembler.noAgent");
                }
            }
View Full Code Here

        }
    }

    private static class Handler implements PersistenceClassLoaderHandler {
        public void addTransformer(String unitId, ClassLoader classLoader, ClassFileTransformer classFileTransformer) {
            Instrumentation instrumentation = Agent.getInstrumentation();
            if (instrumentation != null) {
                instrumentation.addTransformer(new Transformer(classFileTransformer));
            }
        }
View Full Code Here

   * @param theClass the class
   * @param <T> the base class type
   * @return all the classes extending from the parameter. An empty collection will be returned if this java agent is not installed
   */
  public static <T> Collection<Class<? extends T>> instancesOf(Class<T> theClass) {
    Instrumentation aInst = instrumentation();

    if (aInst == null) {
      return Sets.newHashSet();
    }

    Set<Class<? extends T>> aClasses = Sets.newHashSet();

    for (Class<?> aCls : aInst.getAllLoadedClasses()) {
      if (theClass.isAssignableFrom(aCls)) {
        aClasses.add((Class<T>) aCls);
      }
    }

View Full Code Here

   * Return all the classes which have the given annotation applied to them
   * @param theAnnotation the annotation
   * @return the classes with the annotation.  An empty collection will be returned if this java agent is not installed
   */
  public static Collection<Class<?>> annotatedWith(Class<? extends Annotation> theAnnotation) {
    Instrumentation aInst = instrumentation();
    if (aInst == null) {
      return Sets.newHashSet();
    }

    Set<Class<?>> aClasses = Sets.newHashSet();

    for (Class<?> aCls : aInst.getAllLoadedClasses()) {
      if (aCls.getAnnotation(theAnnotation) != null) {
        aClasses.add(aCls);
      }
    }

View Full Code Here

TOP

Related Classes of java.lang.instrument.Instrumentation

Copyright © 2018 www.massapicom. 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.