<commit_before>package github.mappingrpc.core;

import github.mappingrpc.api.annotation.RequestMapping;
import github.mappingrpc.core.io.custompackage.MappingPackageClient;
import github.mappingrpc.core.io.custompackage.MappingPackageServer;
import github.mappingrpc.core.metadata.MetaHolder;
import github.mappingrpc.core.metadata.ProviderMeta;
import github.mappingrpc.core.rpc.ServiceInvocationHandler;

import java.io.Closeable;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanNameAware;

public class CoreEngine implements BeanNameAware, Closeable {
	static Logger log = LoggerFactory.getLogger(CoreEngine.class);
	
	private boolean isListenEngine = false;
	private long feature1 = 0;
	private String listenIp; // TODO
	private short listenPort = 6200;
	private Map<String, String> serverList;
	private String beanName;

	MetaHolder metaHolder = new MetaHolder();
	MappingPackageServer listenServer;
	MappingPackageClient connectServer;

	public CoreEngine(boolean isListenEngine) {
		this.isListenEngine = isListenEngine;
	}

	public void start() {
		metaHolder.setFeature1(feature1);
		
		ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(300);
		ExecutorService threadPool = new ThreadPoolExecutor(4, 80, 60, TimeUnit.SECONDS, workQueue);// TODO
																									// 加上rejectHandle
		metaHolder.setThreadPool(threadPool);

		if (isListenEngine) {
			listenServer = new MappingPackageServer(metaHolder, listenPort);
			listenServer.start();
		} else {
			connectServer = new MappingPackageClient(metaHolder, serverList);
			connectServer.start();
			serverList = null;
		}
	}

	public Object createConsumerProxy(String serviceInterface) {
		ServiceInvocationHandler proxyHandler = metaHolder.getClientProxyHolder().get(serviceInterface);
		if (proxyHandler == null) {// FIXME
			proxyHandler = new ServiceInvocationHandler(connectServer);
			metaHolder.getClientProxyHolder().put(serviceInterface, proxyHandler);
		}

		return proxyHandler.generateProxy(serviceInterface);
	}

	/**
	 * 可以并需要运行在start()前
	 * 
	 * @param serviceImpl
	 */
	public void createProvider(Object serviceImpl) {
		Method[] methodList = serviceImpl.getClass().getMethods();
		for (Method method : methodList) {
			RequestMapping mapping = method.getAnnotation(RequestMapping.class);
			if (mapping != null) {
				ProviderMeta meta = new ProviderMeta();
				meta.setMapping(mapping.value());
				meta.setMethod(method);
				meta.setServiceImpl(serviceImpl);
				metaHolder.getProviderHolder().put(mapping.value(), meta);
			}
		}
	}

	public void setProviderList(List<Object> serviceImplList) {
		for (Object serviceImpl : serviceImplList) {
			createProvider(serviceImpl);
		}
	}

	public void close() {
		if (connectServer != null) {
			connectServer.close();
		}
		if(listenServer != null){
			listenServer.close();
		}<commit_msg>代理service获取注解<commit_after>package github.mappingrpc.core;

import github.mappingrpc.api.annotation.RequestMapping;
import github.mappingrpc.core.io.custompackage.MappingPackageClient;
import github.mappingrpc.core.io.custompackage.MappingPackageServer;
import github.mappingrpc.core.metadata.MetaHolder;
import github.mappingrpc.core.metadata.ProviderMeta;
import github.mappingrpc.core.rpc.ServiceInvocationHandler;

import java.io.Closeable;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanNameAware;

public class CoreEngine implements BeanNameAware, Closeable {
	static Logger log = LoggerFactory.getLogger(CoreEngine.class);
	
	private boolean isListenEngine = false;
	private long feature1 = 0;
	private String listenIp; // TODO
	private short listenPort = 6200;
	private Map<String, String> serverList;
	private String beanName;

	MetaHolder metaHolder = new MetaHolder();
	MappingPackageServer listenServer;
	MappingPackageClient connectServer;

	public CoreEngine(boolean isListenEngine) {
		this.isListenEngine = isListenEngine;
	}

	public void start() {
		metaHolder.setFeature1(feature1);
		
		ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(300);
		ExecutorService threadPool = new ThreadPoolExecutor(4, 80, 60, TimeUnit.SECONDS, workQueue);// TODO
																									// 加上rejectHandle
		metaHolder.setThreadPool(threadPool);

		if (isListenEngine) {
			listenServer = new MappingPackageServer(metaHolder, listenPort);
			listenServer.start();
		} else {
			connectServer = new MappingPackageClient(metaHolder, serverList);
			connectServer.start();
			serverList = null;
		}
	}

	public Object createConsumerProxy(String serviceInterface) {
		ServiceInvocationHandler proxyHandler = metaHolder.getClientProxyHolder().get(serviceInterface);
		if (proxyHandler == null) {// FIXME
			proxyHandler = new ServiceInvocationHandler(connectServer);
			metaHolder.getClientProxyHolder().put(serviceInterface, proxyHandler);
		}

		return proxyHandler.generateProxy(serviceInterface);
	}

	/**
	 * 可以并需要运行在start()前
	 * 
	 * @param serviceImpl
	 */
	public void createProvider(Object serviceImpl) {
		Method[] methodList = serviceImpl.getClass().getMethods();
		
		// 解决serviceImpl是代理类时取不到RequestMapping的问题
		boolean isProxy = serviceImpl.getClass().toString().contains("EnhancerByCGLIB") || serviceImpl.getClass().toString().contains("com.sun.proxy.$Proxy");
		if(mapping == null && isProxy) {
			String className = serviceImpl.toString().substring(0,serviceImpl.toString().indexOf("@"));
			try {
				mapping = Class.forName(className).getMethod(method.getName(), method.getParameterTypes()).getAnnotation(RequestMapping.class);
			} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) {}
		}
		
		for (Method method : methodList) {
			RequestMapping mapping = method.getAnnotation(RequestMapping.class);
			if (mapping != null) {
				ProviderMeta meta = new ProviderMeta();
				meta.setMapping(mapping.value());
				meta.setMethod(method);
				meta.setServiceImpl(serviceImpl);
				metaHolder.getProviderHolder().put(mapping.value(), meta);
			}
		}
	}

	public void setProviderList(List<Object> serviceImplList) {
		for (Object serviceImpl : serviceImplList) {
			createProvider(serviceImpl);
		}
	}

	public void close() {
		if (connectServer != null) {
			connectServer.close();
		}
		if(listenServer != null){
			listenServer.close();
		}
{'fraction_non_alphanumeric': 0.10482577635223793, 'fraction_numerical': 0.005394372357486514, 'mean_word_length': 5.276303751143641, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5155847', 'n_tokens_mistral': 2152, 'n_tokens_neox': 1939, 'n_words': 384}