proxy server

This commit is contained in:
insanity 2017-06-28 18:54:25 +09:00
parent 0267ae3617
commit 10d4f8a966
2 changed files with 6 additions and 40 deletions

View File

@ -1,7 +1,6 @@
package com.loafle.overflow.proxy;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
@ -21,15 +20,15 @@ public class MethodSeeker {
}
private static Method getMethodType(Class jpa, String methodName, Class<?> ...type) {
if (jpa == null) {
private static Method getMethodType(Class cls, String methodName, Class<?> ...type) {
if (cls == null) {
return null;
}
Method m = null;
try {
m = jpa.getMethod(methodName, type);
m = cls.getMethod(methodName, type);
} catch (NoSuchMethodException e) {
return MethodSeeker.getMethodType(jpa.getSuperclass(), methodName, type);
return MethodSeeker.getMethodType(cls.getSuperclass(), methodName, type);
}
return m;

View File

@ -4,16 +4,6 @@ import com.loafle.overflow.api.OverflowApiServerGrpc;
import com.loafle.overflow.api.ServerInput;
import com.loafle.overflow.api.ServerOutput;
import com.loafle.overflow.api.ServerParam;
import com.loafle.overflow.module.domain.service.DomainService;
import com.loafle.overflow.module.email.service.EmailAuthService;
import com.loafle.overflow.module.infra.service.*;
import com.loafle.overflow.module.member.service.MemberService;
import com.loafle.overflow.module.noauthprobe.service.NoAuthProbeService;
import com.loafle.overflow.module.probe.service.ProbeService;
import com.loafle.overflow.module.probe.service.ProbeTaskService;
import com.loafle.overflow.module.sensor.service.SensorItemService;
import com.loafle.overflow.module.sensor.service.SensorService;
import com.loafle.overflow.module.target.service.TargetService;
import io.grpc.ServerBuilder;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
@ -24,8 +14,6 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
/**
@ -36,29 +24,8 @@ public class ServiceProxy {
private io.grpc.Server server;
private static Map<String, Object> serviceMap = null;
public ServiceProxy() {
ApplicationContext ctx = new AnnotationConfigApplicationContext("com.loafle.overflow");
serviceMap = new ConcurrentHashMap<>();
serviceMap.put("member", ctx.getBean(MemberService.class));
serviceMap.put("email", ctx.getBean(EmailAuthService.class));
serviceMap.put("probe", ctx.getBean(ProbeService.class));
serviceMap.put("probeTask", ctx.getBean(ProbeTaskService.class));
serviceMap.put("noauthProbe", ctx.getBean(NoAuthProbeService.class));
serviceMap.put("sensor", ctx.getBean(SensorService.class));
serviceMap.put("sensorItem", ctx.getBean(SensorItemService.class));
serviceMap.put("domain", ctx.getBean(DomainService.class));
serviceMap.put("target", ctx.getBean(TargetService.class));
serviceMap.put("infra", ctx.getBean(InfraService.class));
serviceMap.put("infraHost", ctx.getBean(InfraHostService.class));
serviceMap.put("infraMachine", ctx.getBean(InfraMachineService.class));
serviceMap.put("infraOS", ctx.getBean(InfraOSService.class));
serviceMap.put("infraOSApplication", ctx.getBean(InfraOSApplicationService.class));
serviceMap.put("infraOSDaemon", ctx.getBean(InfraOSDaemonService.class));
serviceMap.put("infraOSPort", ctx.getBean(InfraOSPortService.class));
serviceMap.put("infraService", ctx.getBean(InfraServiceService.class));
}
public void start(int port) throws IOException {
@ -94,9 +61,9 @@ public class ServiceProxy {
@Override
public void exec(ServerInput request,
io.grpc.stub.StreamObserver<ServerOutput> responseObserver) {
ApplicationContext ctx = new AnnotationConfigApplicationContext("com.loafle.overflow");
String targetServiceName = request.getTarget();
Object service = serviceMap.get(targetServiceName);
Object service = ctx.getBean(targetServiceName);
if(service != null) {
try {