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

com.ikasoa.rpc.BaseGetServiceFactory Maven / Gradle / Ivy

There is a newer version: 0.3.3-BETA3
Show newest version
package com.ikasoa.rpc;

import com.ikasoa.core.thrift.GeneralFactory;
import com.ikasoa.core.thrift.client.ThriftClient;
import com.ikasoa.core.thrift.client.ThriftClientConfiguration;
import com.ikasoa.core.thrift.server.ThriftServerConfiguration;
import com.ikasoa.rpc.client.IkasoaClientService;
import com.ikasoa.rpc.client.InvalidGetService;
import com.ikasoa.rpc.handler.ClientInvocationHandler;
import com.ikasoa.rpc.handler.ProtocolHandler;
import com.ikasoa.rpc.handler.ProtocolHandlerFactory;
import com.ikasoa.rpc.handler.ReturnData;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * 基础服务工厂
 * 
 * @author Larry
 * @version 0.1
 */
@Slf4j
public class BaseGetServiceFactory extends GeneralFactory {

	private ProtocolHandlerFactory protocolHandlerFactory = new ProtocolHandlerFactory<>();

	@Getter
	@Setter
	@SuppressWarnings("rawtypes")
	private Class protocolHandlerClass;

	@Getter
	@Setter
	private ClientInvocationHandler clientInvocationHandler;

	public BaseGetServiceFactory(ThriftServerConfiguration thriftServerConfiguration) {
		super(thriftServerConfiguration);
	}

	public BaseGetServiceFactory(ThriftClientConfiguration thriftClientConfiguration) {
		super(thriftClientConfiguration);
	}

	public BaseGetServiceFactory(ThriftServerConfiguration thriftServerConfiguration,
			ThriftClientConfiguration thriftClientConfiguration) {
		super(thriftServerConfiguration, thriftClientConfiguration);
	}

	public BaseGetService getBaseGetService(ThriftClient thriftClient, String serviceKey, ReturnData resultData) {
		return getBaseGetService(thriftClient, serviceKey,
				protocolHandlerFactory.getProtocolHandler(resultData, getProtocolHandlerClass()));
	}

	public BaseGetService getBaseGetService(ThriftClient thriftClient, String serviceKey,
			ProtocolHandler protocolHandler) {
		if (thriftClient == null || serviceKey == null || protocolHandler == null)
			return new InvalidGetService();
		log.debug("Create new instance 'IkasoaClientService' . (serverHost : {}, serverPort : {}, serviceKey : {})",
				thriftClient.getServerHost(), thriftClient.getServerPort(), serviceKey);
		return new IkasoaClientService(this, thriftClient, serviceKey, protocolHandler, clientInvocationHandler);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy