All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yx.rpc.RpcActions Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/**
 * Copyright (C) 2016 - 2030 youtongluan.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.yx.rpc;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.yx.annotation.spec.SoaSpec;
import org.yx.annotation.spec.Specs;
import org.yx.common.action.ActInfoUtil;
import org.yx.conf.AppInfo;
import org.yx.main.SumkServer;
import org.yx.util.StringUtil;

public final class RpcActions {

	private static Map> pojoMap = new ConcurrentHashMap<>();

	private static Map actMap = new ConcurrentHashMap<>();

	public static Class getArgType(String method) {
		String m = getArgClassName(method);
		return pojoMap.get(m);
	}

	private static String getArgClassName(String method) {
		int k = method.lastIndexOf('.');
		return method.substring(0, k) + "_" + method.substring(k + 1);
	}

	public static RpcActionNode getActionNode(String soaName) {
		return actMap.get(soaName);
	}

	public static void putActNode(String soaName, RpcActionNode actInfo) {
		actMap.putIfAbsent(soaName, actInfo);
	}

	public static Set soaSet() {
		return actMap.keySet();
	}

	public static List publishSoaSet() {
		List list = new ArrayList<>(actMap.size());
		for (Map.Entry entry : actMap.entrySet()) {
			String api = entry.getKey();
			if (needPublish(api, entry.getValue())) {
				list.add(api);
			}
		}
		return list;
	}

	static boolean needPublish(String api, RpcActionNode node) {
		return AppInfo.getBoolean("sumk.rpc.publish.".concat(api), node.publish());
	}

	public static List> infos(boolean full) {
		if (!SumkServer.isRpcEnable()) {
			return Collections.emptyList();
		}
		List names = new ArrayList<>(actMap.keySet());
		List> ret = new ArrayList<>(names.size());
		names.sort(null);
		for (String name : names) {
			RpcActionNode rpc = actMap.get(name);
			if (rpc == null) {
				continue;
			}
			Map map = full ? ActInfoUtil.fullInfoMap(name, rpc) : ActInfoUtil.simpleInfoMap(name, rpc);
			ret.add(map);
			SoaSpec soa = Specs.extractSoa(rpc.rawMethod());
			if (soa != null) {
				map.put("cnName", soa.cnName());
				if (StringUtil.isNotEmpty(rpc.comment())) {
					map.put("comment", rpc.comment());
				}
			}
			if (!needPublish(name, rpc)) {
				map.put("publish", Boolean.FALSE);
			}
			if (rpc.toplimit() != AppInfo.getInt("sumk.rpc.thread.priority.default", 100000)) {
				map.put("toplimit", rpc.toplimit());
			}
		}
		return ret;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy