use of com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory in project newrelic-java-agent by newrelic.
the class OptimizedClassMatcherTest method testSkipObjectMethods_looseMatch.
@Test
public void testSkipObjectMethods_looseMatch() throws IOException {
ClassMatchVisitorFactory matcher = OptimizedClassMatcherBuilder.newBuilder().addClassMethodMatcher(new DefaultClassAndMethodMatcher(new AllClassesMatcher(), new AllMethodsMatcher())).build();
Match match = getMatch(matcher, MyObject.class);
Assert.assertNotNull(match);
for (Method m : OBJECT_METHODS) {
Assert.assertFalse(match.getMethods().contains(m));
}
}
use of com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory in project newrelic-java-agent by newrelic.
the class ClassWeaverService method loadInternalWeavePackages.
/**
* Load all the weave packages embedded in the agent jar.
*/
private Collection<ClassMatchVisitorFactory> loadInternalWeavePackages() {
final Collection<ClassMatchVisitorFactory> matchers = Sets.newConcurrentHashSet();
Collection<String> jarFileNames = AgentJarHelper.findAgentJarFileNames(Pattern.compile("instrumentation\\/(.*).jar"));
if (jarFileNames.isEmpty()) {
LOG.log(Level.SEVERE, "No instrumentation packages were found in the agent.");
} else {
LOG.log(Level.FINE, "Loading {0} instrumentation packages", jarFileNames.size());
}
int partitions = (jarFileNames.size() < PARTITIONS) ? jarFileNames.size() : PARTITIONS;
// Note: An ExecutorService would be better suited for this work but we are
// specifically not using it here to prevent the ConcurrentCallablePointCut
// from being loaded too early
final CountDownLatch executorCountDown = new CountDownLatch(partitions);
List<Set<String>> weavePackagePartitions = partitionInstrumentationJars(jarFileNames, partitions);
for (final Set<String> weavePackageJars : weavePackagePartitions) {
Runnable loadWeavePackagesRunnable = new Runnable() {
@Override
public void run() {
try {
for (final String name : weavePackageJars) {
URL instrumentationUrl = BootstrapAgent.class.getResource('/' + name);
if (instrumentationUrl == null) {
Agent.LOG.error("Unable to find instrumentation jar: " + name);
} else {
try (InputStream inputStream = instrumentationUrl.openStream()) {
WeavePackage internalWeavePackage = createWeavePackage(inputStream, instrumentationUrl.toExternalForm());
if (null == internalWeavePackage) {
LOG.log(Level.FINEST, "internal weave package: {0} was null", instrumentationUrl.toExternalForm());
continue;
} else if (internalWeavePackage.getPackageViolations().size() > 0) {
LOG.log(Level.FINER, "skip loading weave package: {0}", internalWeavePackage.getName());
for (WeaveViolation violation : internalWeavePackage.getPackageViolations()) {
LOG.log(Level.FINER, "\t violation: {0}", violation);
}
} else {
LOG.log(Level.FINER, "adding weave package: {0}", internalWeavePackage.getName());
internalWeavePackages.add(internalWeavePackage.getName());
weavePackageManager.register(internalWeavePackage);
}
} catch (Throwable t) {
LOG.log(Level.FINER, t, "unable to load weave package jar {0}", instrumentationUrl);
}
}
}
} catch (Throwable t) {
LOG.log(Level.FINER, t, "A thread loading weaved packages threw an error");
} finally {
executorCountDown.countDown();
}
}
};
new Thread(loadWeavePackagesRunnable).start();
}
try {
// Wait for all partitions to complete
executorCountDown.await();
LOG.log(Level.FINE, "Loaded {0} internal instrumentation packages", internalWeavePackages.size());
} catch (InterruptedException e) {
LOG.log(Level.FINE, e, "Interrupted while waiting for instrumentation packages.");
}
return matchers;
}
use of com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory in project newrelic-java-agent by newrelic.
the class ClassWeaverService method unloadExternalWeavePackages.
/**
* Unload the given external instrumentation packages
*/
private Collection<ClassMatchVisitorFactory> unloadExternalWeavePackages(Set<String> removedFilePaths) {
LOG.log(Level.INFO, "ClassWeaveService removing {0} weave packages.", removedFilePaths.size());
Collection<ClassMatchVisitorFactory> matchers = Sets.newHashSetWithExpectedSize(removedFilePaths.size());
for (String removedFilePath : removedFilePaths) {
String weavePackageName = this.externalWeavePackages.get(removedFilePath);
if (this.internalWeavePackages.contains(weavePackageName)) {
Agent.LOG.log(Level.FINER, "Attempted to unload internal weave package {0} -- {1}. Ignoring request.", weavePackageName, removedFilePath);
continue;
}
WeavePackage externalPackage = weavePackageManager.deregister(weavePackageName);
if (null == externalPackage) {
Agent.LOG.log(Level.FINER, "Attempted to unload non-existent weave package {0} -- {1}. Ignoring request.", weavePackageName, removedFilePath);
} else {
externalWeavePackages.remove(removedFilePath);
}
}
return matchers;
}
use of com.newrelic.agent.instrumentation.context.ClassMatchVisitorFactory in project newrelic-java-agent by newrelic.
the class JarCollectorInputs method build.
public static JarCollectorInputs build(boolean jarCollectorEnabled, JarAnalystFactory jarAnalystFactory, ExecutorService executorService, Logger jarCollectorLogger) {
ClassMatchVisitorFactory classNoticingFactory = jarCollectorEnabled ? new ClassNoticingFactory(jarAnalystFactory, executorService, jarCollectorLogger) : ClassMatchVisitorFactory.NO_OP_FACTORY;
ExtensionsLoadedListener extensionAnalysisProducer = jarCollectorEnabled ? new ExtensionAnalysisProducer(jarAnalystFactory, executorService, jarCollectorLogger) : ExtensionsLoadedListener.NOOP;
return new JarCollectorInputs(extensionAnalysisProducer, classNoticingFactory);
}
Aggregations