use of com.newrelic.agent.instrumentation.context.InstrumentationContextClassMatcherHelper in project newrelic-java-agent by newrelic.
the class ExtensionService method reloadCustomExtensionsIfModified.
private void reloadCustomExtensionsIfModified() {
File[] xmlFiles = getExtensionFiles(ExtensionFileTypes.XML.getFilter());
File[] ymlFiles = getExtensionFiles(ExtensionFileTypes.YML.getFilter());
// element count start at -1 to ensure fileModified is true the first time
boolean fileModified = (xmlFiles.length + ymlFiles.length) != elementCount;
if (!fileModified) {
for (File file : xmlFiles) {
fileModified |= (file.lastModified() <= System.currentTimeMillis() && lastReloaded < file.lastModified());
}
for (File file : ymlFiles) {
fileModified |= (file.lastModified() <= System.currentTimeMillis() && lastReloaded < file.lastModified());
}
}
// if you are changing be sure to test without an extensions directory
if (fileModified) {
lastReloaded = System.currentTimeMillis();
elementCount = xmlFiles.length + ymlFiles.length;
pointCuts.clear();
HashMap<String, Extension> allExtensions = new HashMap<>(internalExtensions);
loadValidExtensions(xmlFiles, extensionParsers.getXmlParser(), allExtensions);
loadValidExtensions(ymlFiles, extensionParsers.getYamlParser(), allExtensions);
Set<Extension> externalExtensions = new HashSet<>(allExtensions.values());
externalExtensions.removeAll(internalExtensions.values());
Set<Extension> oldExtensions = extensions;
extensions = Collections.unmodifiableSet(externalExtensions);
JmxService jmxService = ServiceFactory.getJmxService();
if (jmxService != null) {
jmxService.reloadExtensions(oldExtensions, extensions);
}
for (Extension extension : allExtensions.values()) {
pointCuts.addAll(extension.getInstrumentationMatchers());
}
ClassRetransformer retransformer = ServiceFactory.getClassTransformerService().getLocalRetransformer();
if (retransformer != null) {
Class<?>[] allLoadedClasses = ServiceFactory.getCoreService().getInstrumentation().getAllLoadedClasses();
retransformer.setClassMethodMatchers(pointCuts);
InstrumentationContextClassMatcherHelper matcherHelper = new InstrumentationContextClassMatcherHelper();
Set<Class<?>> classesToRetransform = ClassesMatcher.getMatchingClasses(retransformer.getMatchers(), matcherHelper, allLoadedClasses);
ReinstrumentUtils.checkClassExistsAndRetransformClasses(new ReinstrumentResult(), Collections.<ExtensionClassAndMethodMatcher>emptyList(), null, classesToRetransform);
}
}
}
use of com.newrelic.agent.instrumentation.context.InstrumentationContextClassMatcherHelper in project newrelic-java-agent by newrelic.
the class RemoteInstrumentationServiceImpl method updateJvmWithExtension.
private void updateJvmWithExtension(Extension ext, ReinstrumentResult result) {
List<ExtensionClassAndMethodMatcher> pointCuts = null;
if (ext == null || !ext.isEnabled()) {
// remove all if the extension is empty or disabled
pointCuts = Collections.emptyList();
} else {
pointCuts = ExtensionConversionUtility.convertToEnabledPointCuts(Arrays.asList(ext), true, InstrumentationType.RemoteCustomXml, isLiveAttributesEnabled);
}
result.setPointCutsSpecified(pointCuts.size());
// this set of classes to retransform will include any classes that matched the last set of matchers AND
// classes matched with the new matchers
ClassRetransformer remoteRetransformer = ServiceFactory.getClassTransformerService().getRemoteRetransformer();
remoteRetransformer.setClassMethodMatchers(pointCuts);
Class<?>[] allLoadedClasses = ServiceFactory.getCoreService().getInstrumentation().getAllLoadedClasses();
InstrumentationContextClassMatcherHelper matcherHelper = new InstrumentationContextClassMatcherHelper();
Set<Class<?>> classesToRetransform = ClassesMatcher.getMatchingClasses(remoteRetransformer.getMatchers(), matcherHelper, allLoadedClasses);
ReinstrumentUtils.checkClassExistsAndRetransformClasses(result, pointCuts, ext, classesToRetransform);
}
Aggregations