Search in sources :

Example 71 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyAccessAppController method doHandle.

protected void doHandle(EzyServerContext ctx, EzyAccessAppRequest request) {
    EzyUser user = request.getUser();
    int zoneId = user.getZoneId();
    EzyAccessAppParams params = request.getParams();
    EzyZoneContext zoneContext = ctx.getZoneContext(zoneId);
    EzyAppContext appContext = zoneContext.getAppContext(params.getAppName());
    EzyApplication app = appContext.getApp();
    EzyAppSetting appSetting = app.getSetting();
    EzyAppUserManager appUserManger = app.getUserManager();
    EzySession session = request.getSession();
    String username = user.getName();
    Lock lock = appUserManger.getLock(username);
    lock.lock();
    try {
        boolean hasNotAccessed = !appUserManger.containsUser(user);
        if (hasNotAccessed) {
            checkAppUserMangerAvailable(appUserManger);
        }
        EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
        appContext.handleEvent(EzyEventType.USER_ACCESS_APP, accessAppEvent);
        if (hasNotAccessed) {
            addUser(appUserManger, user, appSetting);
            EzyUserAccessedAppEvent accessedAppEvent = new EzySimpleUserAccessedAppEvent(user);
            appContext.handleEvent(EzyEventType.USER_ACCESSED_APP, accessedAppEvent);
        }
        EzyArray output = accessAppEvent.getOutput();
        EzyResponse accessAppResponse = newAccessAppResponse(appSetting, output);
        ctx.send(accessAppResponse, session, false);
    } finally {
        lock.unlock();
        appUserManger.removeLock(username);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyAccessAppParams(com.tvd12.ezyfoxserver.request.EzyAccessAppParams) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Lock(java.util.concurrent.locks.Lock) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessedAppEvent) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)

Example 72 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzySimpleAppUserDelegate method responseUserRemoved.

protected void responseUserRemoved(EzyUser user, EzyConstant reason) {
    EzyResponse response = newExitedAppResponse(reason);
    EzyZoneContext zoneContext = appContext.getParent();
    zoneContext.send(response, user, false);
}
Also used : EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 73 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyUserDataHandler method newStreamingRequest.

protected EzyStreamingRequest newStreamingRequest(byte[] bytes) {
    EzySimpleStreamingRequest request = new EzySimpleStreamingRequest();
    request.setUser(user);
    request.setSession(session);
    request.setBytes(bytes);
    return request;
}
Also used : EzySimpleStreamingRequest(com.tvd12.ezyfoxserver.request.EzySimpleStreamingRequest)

Example 74 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyUserDataHandler method newRequest.

@SuppressWarnings({ "rawtypes" })
protected EzyRequest newRequest(EzyConstant cmd, EzyArray data) {
    EzySimpleRequest request = requestFactory.newRequest(cmd);
    request.setSession(session);
    request.setUser(user);
    request.deserializeParams(data);
    return request;
}
Also used : EzySimpleRequest(com.tvd12.ezyfoxserver.request.EzySimpleRequest)

Example 75 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyZoneUserManagerImpl method unmapSessionUser.

@Override
public void unmapSessionUser(EzySession session, EzyConstant reason) {
    EzyUser user = usersBySession.remove(session);
    if (user != null) {
        user.removeSession(session);
        logger.debug("zone: {} remove session {} from user {} by reason {}, " + "user remain: {} sessions, usersBySession.size: {}", zoneName, session.getClientAddress(), user, reason, user.getSessionCount(), usersBySession.size());
        if (shouldRemoveUserNow(user)) {
            removeUser(user, reason);
        }
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser)

Aggregations

Test (org.testng.annotations.Test)42 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)33 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)28 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)25 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)20 EzyArray (com.tvd12.ezyfox.entity.EzyArray)16 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)16 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)15 BaseTest (com.tvd12.test.base.BaseTest)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)12 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)10 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)10 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)7 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)7 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)7