<commit_before>package com.nhn.pinpoint.profiler.modifier.connector.npc.interceptor;

import java.net.InetSocketAddress;

import com.nhn.pinpoint.profiler.context.TraceContext;
import com.nhn.pinpoint.profiler.interceptor.*;
import com.nhn.pinpoint.profiler.logging.PLogger;
import com.nhn.pinpoint.profiler.logging.PLoggerFactory;
import com.nhn.pinpoint.profiler.util.MetaObject;
import com.nhncorp.lucy.npc.connector.KeepAliveNpcHessianConnector;
import com.nhncorp.lucy.npc.connector.NpcConnectorOption;

/**
 * based on NPC client 1.5.18
 * 
 * @author netspider
 * 
 */
public class ConnectorConstructorInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader {

	private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
	private final boolean isDebug = logger.isDebugEnabled();

	private MethodDescriptor descriptor;
	private TraceContext traceContext;

	private MetaObject<InetSocketAddress> setServerAddress = new MetaObject<InetSocketAddress>("__setServerAddress", InetSocketAddress.class);

	@Override
	public void before(Object target, Object[] args) {
		if (isDebug) {
			logger.beforeInterceptor(target, args);
		}

		if (target instanceof KeepAliveNpcHessianConnector) {
			/*
			 * com.nhncorp.lucy.npc.connector.KeepAliveNpcHessianConnector.
			 * KeepAliveNpcHessianConnector(InetSocketAddress, long, long,
			 * Charset)
			 */
			if (args.length == 4) {
				if (args[0] instanceof InetSocketAddress) {
					setServerAddress.invoke(target, (InetSocketAddress) args[0]);
				}
			} else if (args.length == 1) {
				if (args[0] instanceof NpcConnectorOption) {
					NpcConnectorOption option = (NpcConnectorOption) args[0];
					InetSocketAddress address = option.getAddress();
					setServerAddress.invoke(target, address);
				}
			}
		} else {
			if (args[0] instanceof NpcConnectorOption) {
				NpcConnectorOption option = (NpcConnectorOption) args[0];
				InetSocketAddress address = option.getAddress();
				setServerAddress.invoke(target, address);
			}
		}
	}

	@Override
	public void after(Object target, Object[] args, Object result) {

	}

	@Override
	public void setMethodDescriptor(MethodDescriptor descriptor) {
		this.descriptor = descriptor;
		traceContext.cacheApi(descriptor);
	}

	@Override
	public void setTraceContext(TraceContext traceContext) {
		this.traceContext = traceContext;
	}
}<commit_msg>[유치수] [tomcat-profiler-11] npc interceptor에서 connection 초기화 실패시 서버맵에 연결 실패 보여주기.<commit_after>package com.nhn.pinpoint.profiler.modifier.connector.npc.interceptor;

import java.net.InetSocketAddress;

import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.profiler.context.Trace;
import com.nhn.pinpoint.profiler.context.TraceContext;
import com.nhn.pinpoint.profiler.interceptor.*;
import com.nhn.pinpoint.profiler.logging.PLogger;
import com.nhn.pinpoint.profiler.logging.PLoggerFactory;
import com.nhn.pinpoint.profiler.util.MetaObject;
import com.nhncorp.lucy.npc.connector.KeepAliveNpcHessianConnector;
import com.nhncorp.lucy.npc.connector.NpcConnectorOption;

/**
 * based on NPC client 1.5.18
 * 
 * @author netspider
 * 
 */
public class ConnectorConstructorInterceptor implements SimpleAroundInterceptor, ByteCodeMethodDescriptorSupport, TraceContextSupport, TargetClassLoader {

	private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
	private final boolean isDebug = logger.isDebugEnabled();

	private MethodDescriptor descriptor;
	private TraceContext traceContext;

	private final MetaObject<InetSocketAddress> setServerAddress = new MetaObject<InetSocketAddress>("__setServerAddress", InetSocketAddress.class);

	@Override
	public void before(Object target, Object[] args) {
		if (isDebug) {
			logger.beforeInterceptor(target, args);
		}

		InetSocketAddress serverAddress = null;

		if (target instanceof KeepAliveNpcHessianConnector) {
			/*
			 * com.nhncorp.lucy.npc.connector.KeepAliveNpcHessianConnector.
			 * KeepAliveNpcHessianConnector(InetSocketAddress, long, long,
			 * Charset)
			 */
			if (args.length == 4) {
				if (args[0] instanceof InetSocketAddress) {
					serverAddress = (InetSocketAddress) args[0];
				}
			} else if (args.length == 1) {
				if (args[0] instanceof NpcConnectorOption) {
					NpcConnectorOption option = (NpcConnectorOption) args[0];
					serverAddress = option.getAddress();
				}
			}
		} else {
			if (args[0] instanceof NpcConnectorOption) {
				NpcConnectorOption option = (NpcConnectorOption) args[0];
				serverAddress = option.getAddress();
			}
		}

		setServerAddress.invoke(target, serverAddress);

		Trace trace = traceContext.currentTraceObject();
		if (trace == null) {
			return;
		}

		trace.traceBlockBegin();
		trace.markBeforeTime();
		trace.recordServiceType(ServiceType.NPC_CLIENT);

		int port = serverAddress.getPort();
		String endPoint = serverAddress.getHostName() + ((port > 0) ? ":" + port : "");
		trace.recordDestinationId(endPoint);
	}

	@Override
	public void after(Object target, Object[] args, Object result) {
		if (isDebug) {
			logger.afterInterceptor(target, args);
		}

		Trace trace = traceContext.currentTraceObject();
		if (trace == null) {
			return;
		}

		try {
			trace.recordApi(descriptor);
			trace.recordException(result);
			trace.markAfterTime();
		} finally {
			trace.traceBlockEnd();
		}
	}

	@Override
	public void setMethodDescriptor(MethodDescriptor descriptor) {
		this.descriptor = descriptor;
		traceContext.cacheApi(descriptor);
	}

	@Override
	public void setTraceContext(TraceContext traceContext) {
		this.traceContext = traceContext;
	}
}
{'fraction_non_alphanumeric': 0.10586348244519693, 'fraction_numerical': 0.004811976474781679, 'mean_word_length': 4.926082365364309, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5634331', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1796, 'n_words': 331}