All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.appland.appmap.util.AppMapClassPool Maven / Gradle / Ivy

There is a newer version: 1.27.1
Show newest version
package com.appland.appmap.util;

import java.util.ArrayDeque;
import java.util.Deque;

import javassist.ClassPool;
import javassist.LoaderClassPath;

public class AppMapClassPool {
  private static final ThreadLocal> threadPoolQueue =
      ThreadLocal.withInitial(() -> new ArrayDeque());

  public static ClassPool acquire(ClassLoader classLoader) {
    ClassPool ret = new ClassPool();
    ret.appendClassPath(new LoaderClassPath(classLoader));
    threadPoolQueue.get().push(ret);
    return ret;
  }

  public static ClassPool get() {
    ClassPool ret = threadPoolQueue.get().peek();
    if (ret == null) {
      throw new InternalError("not acquired");
    }
    return ret;
  }

  public static void release() {
    threadPoolQueue.get().pop();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy