Search in sources :

Example 21 with Controller

use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method addEventControllers.

private void addEventControllers(EzyAppContext appContext, EzyBeanContext beanContext) {
    EzySetup setup = appContext.get(EzySetup.class);
    List<Object> eventControllers = beanContext.getSingletons(EzyEventHandler.class);
    sortEventHandlersByPriority(eventControllers);
    for (Object controller : eventControllers) {
        Class<?> controllerType = controller.getClass();
        EzyEventHandler annotation = controllerType.getAnnotation(EzyEventHandler.class);
        String eventName = EzyEventHandlerAnnotations.getEvent(annotation);
        setup.addEventController(EzyEventType.valueOf(eventName), (EzyEventController) controller);
        logger.info("add  event {} controller {}", eventName, controller);
    }
}
Also used : EzyEventHandler(com.tvd12.ezyfox.core.annotation.EzyEventHandler) EzySetup(com.tvd12.ezyfoxserver.command.EzySetup)

Example 22 with Controller

use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method setPluginRequestController.

private void setPluginRequestController(EzyPluginContext pluginContext, EzyBeanContext beanContext) {
    if (!allowRequest() || getClass().isAnnotationPresent(EzyDisallowRequest.class)) {
        return;
    }
    EzyPluginSetup setup = pluginContext.get(EzyPluginSetup.class);
    EzyPluginRequestController controller = newUserRequestController(beanContext);
    setup.setRequestController(controller);
    Set<String> commands = ((EzyCommandsAware) controller).getCommands();
    pluginContext.setProperty(COMMANDS, commands);
}
Also used : EzyPluginSetup(com.tvd12.ezyfoxserver.command.EzyPluginSetup) EzyCommandsAware(com.tvd12.ezyfoxserver.support.controller.EzyCommandsAware) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyDisallowRequest(com.tvd12.ezyfoxserver.support.annotation.EzyDisallowRequest)

Example 23 with Controller

use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementer method implement.

private Map<String, EzyUserRequestHandler> implement(Object controller) {
    Map<String, EzyUserRequestHandler> handlers = new HashMap<>();
    EzyRequestControllerProxy proxy = new EzyRequestControllerProxy(controller);
    String feature = proxy.getFeature();
    for (EzyRequestHandlerMethod method : proxy.getRequestHandlerMethods()) {
        EzyRequestHandlerImplementer implementer = newImplementer(proxy, method);
        EzyAsmRequestHandler handler = implementer.implement();
        String command = handler.getCommand();
        handlers.put(command, handler);
        requestCommandManager.addCommand(command);
        if (proxy.isManagement() || method.isManagement()) {
            requestCommandManager.addManagementCommand(command);
        }
        if (proxy.isPayment() || method.isPayment()) {
            requestCommandManager.addPaymentCommand(command);
        }
        String methodFeature = feature != null ? feature : method.getFeature();
        if (EzyStrings.isNotBlank(methodFeature)) {
            featureCommandManager.addFeatureCommand(methodFeature, command);
        }
    }
    return handlers;
}
Also used : HashMap(java.util.HashMap) EzyRequestControllerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler) EzyRequestHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyRequestHandlerMethod)

Example 24 with Controller

use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementer method implement.

public Map<String, EzyUserRequestHandler> implement(Collection<Object> controllers) {
    Map<String, EzyUserRequestHandler> handlers = new HashMap<>();
    for (Object controller : controllers) {
        Map<String, EzyUserRequestHandler> map = implement(controller);
        for (String command : map.keySet()) {
            EzyUserRequestHandler handler = map.get(command);
            EzyUserRequestHandler old = handlers.put(command, handler);
            if (old != null && !allowOverrideCommand) {
                throw new EzyDuplicateRequestHandlerException(command, old, handler);
            }
        }
    }
    return handlers;
}
Also used : HashMap(java.util.HashMap) EzyDuplicateRequestHandlerException(com.tvd12.ezyfoxserver.support.exception.EzyDuplicateRequestHandlerException) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler)

Example 25 with Controller

use of com.tvd12.ezyhttp.server.core.annotation.Controller in project ezyfox-server by youngmonkeys.

the class EzyEventControllersImplTest method multiThreadTest.

@SuppressWarnings("unchecked")
@Test
public void multiThreadTest() {
    EzyEventControllersImpl sut = new EzyEventControllersImpl();
    ExecutorService executorService = Executors.newFixedThreadPool(12);
    AtomicBoolean active = new AtomicBoolean(true);
    executorService.execute(() -> {
        while (active.get()) {
            for (EzyEventType eventType : EzyEventType.values()) {
                sut.addController(eventType, mock(EzyEventController.class));
            }
            EzyThreads.sleep(1);
        }
    });
    executorService.execute(() -> {
        while (active.get()) {
            for (EzyEventType eventType : EzyEventType.values()) {
                for (EzyEventController controller : sut.getControllers(eventType)) {
                    controller.handle(null, null);
                }
            }
            EzyThreads.sleep(1);
        }
    });
    EzyThreads.sleep(1000);
    executorService.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EzyEventType(com.tvd12.ezyfoxserver.constant.EzyEventType) EzyEventControllersImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl) ExecutorService(java.util.concurrent.ExecutorService) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

Test (org.testng.annotations.Test)38 EzyArray (com.tvd12.ezyfox.entity.EzyArray)18 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)14 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)14 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)14 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)12 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)12 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)12 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)11 BaseTest (com.tvd12.test.base.BaseTest)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 GraphQLController (com.tvd12.ezyhttp.server.graphql.controller.GraphQLController)6 GraphQLDataFetcherManager (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcherManager)5 EzySimpleUserManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting)4 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)4 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)4 GraphQLDataFetcher (com.tvd12.ezyhttp.server.graphql.GraphQLDataFetcher)4 GraphQLSchemaParser (com.tvd12.ezyhttp.server.graphql.GraphQLSchemaParser)4 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)3