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);
}
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);
}
}
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();
}
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));
}
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);
}
}
Aggregations