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

rpc.turbo.common.RemoteContext Maven / Gradle / Ivy

There is a newer version: 0.0.9
Show newest version
package rpc.turbo.common;

import java.lang.reflect.Method;

import rpc.turbo.config.HostPort;
import rpc.turbo.util.concurrent.AttachmentThreadUtils;

/**
 * 远程调用上下文
 * 
 * @author Hank
 *
 */
public final class RemoteContext {

	private static final int CLIENT_ADRESS_ATTACHMENT_INDEX = AttachmentThreadUtils.nextVarIndex();
	private static final int SERVER_ADRESS_ATTACHMENT_INDEX = AttachmentThreadUtils.nextVarIndex();
	private static final int INVOKER_ATTACHMENT_INDEX = AttachmentThreadUtils.nextVarIndex();
	private static final int SERVICE_METHOD_NAME_ATTACHMENT_INDEX = AttachmentThreadUtils.nextVarIndex();

	/**
	 * 获取当前远程调用的客户端地址
	 * 
	 * @return
	 */
	public static HostPort getClientAddress() {
		return AttachmentThreadUtils.get(CLIENT_ADRESS_ATTACHMENT_INDEX);
	}

	public static void setClientAddress(HostPort clientAddress) {
		AttachmentThreadUtils.put(CLIENT_ADRESS_ATTACHMENT_INDEX, clientAddress);
	}

	/**
	 * 获取当前远程调用的服务端地址
	 * 
	 * @return
	 */
	public static HostPort getServerAddress() {
		return AttachmentThreadUtils.get(SERVER_ADRESS_ATTACHMENT_INDEX);
	}

	public static void setServerAddress(HostPort serverAddress) {
		AttachmentThreadUtils.put(SERVER_ADRESS_ATTACHMENT_INDEX, serverAddress);
	}

	/**
	 * 获取当前远程调用的接口方法, 可能为空
	 * 
	 * @return
	 */
	public static Method getRemoteMethod() {
		return AttachmentThreadUtils.get(INVOKER_ATTACHMENT_INDEX);
	}

	public static void setRemoteMethod(Method remoteMethod) {
		AttachmentThreadUtils.put(INVOKER_ATTACHMENT_INDEX, remoteMethod);
	}

	/**
	 * 获取当前远程调用的服务名称, 可能为空
	 * 
	 * @return
	 */
	public static String getServiceMethodName() {
		return AttachmentThreadUtils.get(SERVICE_METHOD_NAME_ATTACHMENT_INDEX);
	}

	public static void setServiceMethodName(String serviceMethodName) {
		AttachmentThreadUtils.put(SERVICE_METHOD_NAME_ATTACHMENT_INDEX, serviceMethodName);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy