Search in sources :

Example 1 with EzySessionAware

use of com.tvd12.ezyfoxserver.entity.EzySessionAware in project ezyfox-server by youngmonkeys.

the class EzyUserRequestPrototypeController method handle.

public void handle(C context, E event) {
    EzyArray data = event.getData();
    String cmd = data.get(0, String.class);
    EzyPrototypeSupplier supplier = handlers.get(cmd);
    if (supplier == null) {
        logger.warn("has no handler with command: {} from session: {}", cmd, event.getSession().getName());
        return;
    }
    EzyHandler handler = (EzyHandler) supplier.supply(beanContext);
    if (handler instanceof EzyUserAware) {
        ((EzyUserAware) handler).setUser(event.getUser());
    }
    if (handler instanceof EzySessionAware) {
        ((EzySessionAware) handler).setSession(event.getSession());
    }
    if (handler instanceof EzyDataBinding) {
        EzyData params = data.get(1, EzyData.class, null);
        if (params != null) {
            unmarshaller.unwrap(params, handler);
        }
    }
    try {
        preHandle(context, event, cmd, handler);
        handler.handle();
        postHandle(context, event, cmd, handler);
    } catch (EzyBadRequestException e) {
        if (e.isSendToClient()) {
            EzyData errorData = newErrorData(e);
            responseError(context, event, errorData);
        }
        logger.debug("request cmd: {} by session: {} with data: {} error", cmd, event.getSession().getName(), data, e);
        postHandle(context, event, cmd, handler, e);
    } catch (Exception e) {
        postHandle(context, event, cmd, handler, e);
        throw e;
    }
}
Also used : EzyUserAware(com.tvd12.ezyfoxserver.entity.EzyUserAware) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyData(com.tvd12.ezyfox.entity.EzyData) EzyPrototypeSupplier(com.tvd12.ezyfox.bean.EzyPrototypeSupplier) EzyDataBinding(com.tvd12.ezyfox.binding.EzyDataBinding) EzyBadRequestException(com.tvd12.ezyfox.core.exception.EzyBadRequestException) EzyHandler(com.tvd12.ezyfox.function.EzyHandler) EzySessionAware(com.tvd12.ezyfoxserver.entity.EzySessionAware) EzyBadRequestException(com.tvd12.ezyfox.core.exception.EzyBadRequestException)

Aggregations

EzyPrototypeSupplier (com.tvd12.ezyfox.bean.EzyPrototypeSupplier)1 EzyDataBinding (com.tvd12.ezyfox.binding.EzyDataBinding)1 EzyBadRequestException (com.tvd12.ezyfox.core.exception.EzyBadRequestException)1 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyData (com.tvd12.ezyfox.entity.EzyData)1 EzyHandler (com.tvd12.ezyfox.function.EzyHandler)1 EzySessionAware (com.tvd12.ezyfoxserver.entity.EzySessionAware)1 EzyUserAware (com.tvd12.ezyfoxserver.entity.EzyUserAware)1