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