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

com.ikasoa.rpc.service.IkasoaServerService Maven / Gradle / Ivy

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

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.ikasoa.rpc.RpcException;
import com.ikasoa.rpc.handler.ProtocolHandler;

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

/**
 * IKASOA服务端服务实现
 * 
 * @author Larry
 * @version 0.1
 */
@Slf4j
public class IkasoaServerService extends AbstractGetService {

	@Getter
	@Setter
	private Object classObj;

	@Getter
	@Setter
	private Method method;

	public IkasoaServerService(Object classObj, Method method, ProtocolHandler protocolHandler) {
		this.classObj = classObj;
		this.method = method;
		this.protocolHandler = protocolHandler;
	}

	@Override
	public Object get(Object[] args) throws RpcException {
		if (method == null)
			throw new RpcException("'method' is null !");
		if (classObj == null)
			throw new RpcException("'classObj' is null !");
		if (args == null) {
			log.debug("'args' is null , Will create default args object .");
			args = new Object[] {};
		}
		log.debug("Execute class '{}' function '{}' , parameters is '{}' .", classObj.getClass().getName(),
				method.getName(), args.toString());
		method.setAccessible(Boolean.TRUE);
		try {
			return method.invoke(classObj, args);
		} catch (IllegalAccessException e) {
			throw new RpcException("'GET' reflect exception !", e);
		} catch (IllegalArgumentException e) {
			throw new RpcException("'GET' reflect exception !", e);
		} catch (InvocationTargetException e) {
			log.debug(e.getTargetException().toString());
			return e.getTargetException();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy