<commit_before>package org.stagemonitor.tracing.soap;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stagemonitor.core.CorePlugin;
import org.stagemonitor.core.Stagemonitor;
import org.stagemonitor.core.instrument.StagemonitorByteBuddyTransformer;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.xml.ws.Binding;
import javax.xml.ws.handler.Handler;

import __redirected.org.stagemonitor.dispatcher.Dispatcher;

import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.isSubTypeOf;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;

public class SoapHandlerTransformer extends StagemonitorByteBuddyTransformer {

	private static final Logger logger = LoggerFactory.getLogger(SoapHandlerTransformer.class);

	public SoapHandlerTransformer() {
		final String key = "org.stagemonitor.tracing.soap.SoapHandlerTransformer";
		Dispatcher.getValues().putIfAbsent(key, new CopyOnWriteArrayList<Handler>());
		// using a list as there can be multiple applications using stagemonitor deployed to a single application server
		// this makes sure they don't override each other
		final List<Handler<?>> handlers = Arrays.<Handler<?>>asList(new TracingServerSOAPHandler(), new TracingClientSOAPHandler());
		Dispatcher.<List<Handler>>get(key).addAll(handlers);
		logger.info("Adding SOAPHandlers " + handlers);
		// remove handler on shutdown to avoid class loader leaks
		Stagemonitor.getPlugin(CorePlugin.class).closeOnShutdown(new Closeable() {
			@Override
			public void close() throws IOException {
				logger.info("Removing SOAP handlers " + handlers);
				Dispatcher.<List<Handler>>get(key).removeAll(handlers);
			}
		});
	}

	@Override
	public ElementMatcher.Junction<TypeDescription> getTypeMatcher() {
		return not(ElementMatchers.isInterface()).and(isSubTypeOf(Binding.class));
	}

	@Override
	protected boolean transformsCoreJavaClasses() {
		return true;
	}

	@Override
	protected ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
		return any();
	}<commit_msg>Improve performance of SoapHandlerTransformer<commit_after>package org.stagemonitor.tracing.soap;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stagemonitor.core.CorePlugin;
import org.stagemonitor.core.Stagemonitor;
import org.stagemonitor.core.instrument.StagemonitorByteBuddyTransformer;

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.xml.ws.Binding;
import javax.xml.ws.handler.Handler;

import __redirected.org.stagemonitor.dispatcher.Dispatcher;

import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isSubTypeOf;
import static net.bytebuddy.matcher.ElementMatchers.nameContains;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;

public class SoapHandlerTransformer extends StagemonitorByteBuddyTransformer {

	private static final Logger logger = LoggerFactory.getLogger(SoapHandlerTransformer.class);

	public SoapHandlerTransformer() {
		final String key = "org.stagemonitor.tracing.soap.SoapHandlerTransformer";
		Dispatcher.getValues().putIfAbsent(key, new CopyOnWriteArrayList<Handler>());
		// using a list as there can be multiple applications using stagemonitor deployed to a single application server
		// this makes sure they don't override each other
		final List<Handler<?>> handlers = Arrays.<Handler<?>>asList(new TracingServerSOAPHandler(), new TracingClientSOAPHandler());
		Dispatcher.<List<Handler>>get(key).addAll(handlers);
		logger.info("Adding SOAPHandlers " + handlers);
		// remove handler on shutdown to avoid class loader leaks
		Stagemonitor.getPlugin(CorePlugin.class).closeOnShutdown(new Closeable() {
			@Override
			public void close() throws IOException {
				logger.info("Removing SOAP handlers " + handlers);
				Dispatcher.<List<Handler>>get(key).removeAll(handlers);
			}
		});
	}

	@Override
	public ElementMatcher.Junction<TypeDescription> getTypeMatcher() {
		// It's important to pre-select potential matches first with the nameContains matcher
		// otherwise, the type hierarchy of each and every class has to be determined whether it derives from Binding
		return nameContains("Binding")
				.and(not(isInterface()))
				.and(isSubTypeOf(Binding.class));
	}

	@Override
	protected boolean transformsCoreJavaClasses() {
		return true;
	}

	@Override
	protected ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
		return any();
	}
{'fraction_non_alphanumeric': 0.09673274596182085, 'fraction_numerical': 0.0007342143906020558, 'mean_word_length': 6.207671957671957, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3638621', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1589, 'n_words': 340}