diff --git a/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java b/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java index 8000e39..786c2d4 100644 --- a/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java +++ b/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java @@ -1,9 +1,6 @@ package com.loafle.overflow.container.general.server; -import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import com.loafle.overflow.container.general.service.Service; @@ -14,6 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; +import static com.loafle.overflow.core.interfaces.Service.execServices; +import static com.loafle.overflow.core.interfaces.Service.ServiceMethodType; + @Component public class GeneralContainerServer extends ContainerServer { @Autowired @@ -34,78 +34,31 @@ public class GeneralContainerServer extends ContainerServer { } this.services = new HashMap<>(); - services.forEach((name, bean)->{ + services.forEach((name, bean) -> { this.services.put(bean.getClass(), bean); }); - this.execServices(this.services, com.loafle.overflow.core.interfaces.Service.ServiceMethodType.INIT, Service.OrderedServices, false); + execServices(this.services, ServiceMethodType.INIT, Service.OrderedServices, false); } @Override protected void onStart() throws Exception { super.onStart(); - this.execServices(this.services, com.loafle.overflow.core.interfaces.Service.ServiceMethodType.START, Service.OrderedServices, false); + execServices(this.services, ServiceMethodType.START, Service.OrderedServices, false); } @Override protected void onStop() throws Exception { - this.execServices(this.services, com.loafle.overflow.core.interfaces.Service.ServiceMethodType.STOP, Service.OrderedServices, true); - + execServices(this.services, ServiceMethodType.STOP, Service.OrderedServices, true); super.onStop(); } @Override protected void destroy() throws Exception { - this.execServices(this.services, com.loafle.overflow.core.interfaces.Service.ServiceMethodType.DESTROY, Service.OrderedServices, true); - + execServices(this.services, ServiceMethodType.DESTROY, Service.OrderedServices, true); super.destroy(); } - - private void execServices(Map, Object> services, com.loafle.overflow.core.interfaces.Service.ServiceMethodType methodType, Class[] orderedTypes, boolean reverse) throws Exception { - if (null == services || 0 == services.size()) { - return; - } - if (null == orderedTypes || 0 == orderedTypes.length) { - return; - } - - List orderedServices = new ArrayList<>(orderedTypes.length); - if (reverse) { - for (int i = orderedTypes.length - 1; i >= 0; i--) { - Class clazz = orderedTypes[i]; - Object service = services.get(clazz); - if (null == service) { - continue; - } - orderedServices.add(service); - } - } else { - for (int i = 0; i < orderedTypes.length; i++) { - Class clazz = orderedTypes[i]; - Object service = services.get(clazz); - if (null == service) { - continue; - } - orderedServices.add(service); - } - } - - if (0 == orderedServices.size()) { - return; - } - - Class[] parameterTypes = new Class[]{}; - for (int i = 0; i < orderedServices.size(); i++) { - Object service = orderedServices.get(i); - Class clazz = service.getClass(); - Method method = clazz.getMethod(methodType.toString(), parameterTypes); - if (null == method) { - continue; - } - method.invoke(service); - } - } }