Search in sources :

Example 1 with EzyEventController

use of com.tvd12.ezyfoxserver.controller.EzyEventController in project ezyfox-server by youngmonkeys.

the class EzyPluginSetupImplTest method addEventControllerTest.

@SuppressWarnings("rawtypes")
@Test
public void addEventControllerTest() {
    // given
    EzySimplePlugin plugin = new EzySimplePlugin();
    EzyEventControllers eventControllers = mock(EzyEventControllers.class);
    plugin.setEventControllers(eventControllers);
    EzyPluginSetupImpl sut = new EzyPluginSetupImpl(plugin);
    EzyEventController controller = mock(EzyEventController.class);
    // when
    sut.addEventController(EzyEventType.SERVER_INITIALIZING, controller);
    // then
    verify(eventControllers, times(1)).addController(EzyEventType.SERVER_INITIALIZING, controller);
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyPluginSetupImpl(com.tvd12.ezyfoxserver.command.impl.EzyPluginSetupImpl) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 2 with EzyEventController

use of com.tvd12.ezyfoxserver.controller.EzyEventController 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 3 with EzyEventController

use of com.tvd12.ezyfoxserver.controller.EzyEventController 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)

Example 4 with EzyEventController

use of com.tvd12.ezyfoxserver.controller.EzyEventController in project ezyfox-server by youngmonkeys.

the class EzyEventControllersImplTest method getListControllerTest.

@Test
public void getListControllerTest() {
    // given
    EzyEventControllersImpl sut = new EzyEventControllersImpl();
    EzyEventController c1 = mock(EzyEventController.class);
    EzyEventController c2 = mock(EzyEventController.class);
    sut.addController(EzyEventType.SERVER_INITIALIZING, c1);
    sut.addController(EzyEventType.SERVER_INITIALIZING, c2);
    // when
    List<EzyEventController> controllers = sut.getControllers(EzyEventType.SERVER_INITIALIZING);
    // then
    Asserts.assertEquals(controllers, Arrays.asList(c1, c2), false);
    Asserts.assertEmpty(sut.getControllers(EzyEventType.USER_ACCESS_APP));
}
Also used : EzyEventControllersImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 5 with EzyEventController

use of com.tvd12.ezyfoxserver.controller.EzyEventController in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method addEventControllers.

private void addEventControllers(EzyPluginContext context, EzyBeanContext beanContext) {
    EzySetup setup = context.get(EzySetup.class);
    List<Object> eventControllers = beanContext.getSingletons(EzyEventHandler.class);
    sortEventHandlersByPriority(eventControllers);
    for (Object controller : eventControllers) {
        Class<?> handlerType = controller.getClass();
        EzyEventHandler annotation = handlerType.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)

Aggregations

EzyEventController (com.tvd12.ezyfoxserver.controller.EzyEventController)5 Test (org.testng.annotations.Test)5 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)3 BaseTest (com.tvd12.test.base.BaseTest)3 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)2 EzyEventHandler (com.tvd12.ezyfox.core.annotation.EzyEventHandler)2 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)2 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)2 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)2 EzySetup (com.tvd12.ezyfoxserver.command.EzySetup)2 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)2 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)2 EzyEventControllersImpl (com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)1 EzyPluginSetupImpl (com.tvd12.ezyfoxserver.command.impl.EzyPluginSetupImpl)1 EzyEventType (com.tvd12.ezyfoxserver.constant.EzyEventType)1 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)1 EzySimplePluginContext (com.tvd12.ezyfoxserver.context.EzySimplePluginContext)1 EzySimpleAppEntry (com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry)1