Search in sources :

Example 1 with EzyUser

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

the class EzyAppResponseImplTest method testPerformance.

@Test
public void testPerformance() {
    EzyAppResponse response = newResponse();
    EzyUser user1 = new ExUser("user1");
    EzySession session1 = new ExSession();
    EzySession session2 = new ExSession();
    user1.addSession(session1);
    user1.addSession(session2);
    EzyUser user2 = new ExUser("user2");
    EzySession session3 = new ExSession();
    EzySession session4 = new ExSession();
    user2.addSession(session3);
    user2.addSession(session4);
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<Object> list = new ArrayList<>();
    long time = Performance.create().loop(1000000).test(() -> {
        response.users(new EzyUser[] { user1, user2 }, false);
        list.add(user1);
        list.add(user2);
        list.add(Arrays.asList(user1, user2));
        list.addAll(user1.getSessions());
        list.addAll(user2.getSessions());
        response.user(user1);
        response.user(user2);
    }).getTime();
    System.out.println("time = " + time);
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) ArrayList(java.util.ArrayList) EzyAppResponse(com.tvd12.ezyfoxserver.command.EzyAppResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzyUser

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

the class EzyLoginProcessor method apply.

public void apply(EzyZoneContext zoneContext, EzyUserLoginEvent event) {
    EzyZone zone = zoneContext.getZone();
    EzyZoneSetting zoneSetting = zone.getSetting();
    EzyUserManagementSetting userManagementSetting = zoneSetting.getUserManagement();
    String username = checkUsername(event.getUsername(), userManagementSetting.getUserNamePattern(), userManagementSetting.isAllowGuestLogin(), userManagementSetting.getGuestNamePrefix());
    String password = event.getPassword();
    EzyZoneUserManager userManager = zone.getUserManager();
    EzyUser user;
    EzySession session = event.getSession();
    boolean alreadyLoggedIn;
    Lock lock = userManager.getLock(username);
    lock.lock();
    try {
        alreadyLoggedIn = userManager.containsUser(username);
        if (alreadyLoggedIn) {
            user = userManager.getUser(username);
        } else {
            user = newUser(zoneSetting, userManagementSetting, username, password, event.getUserProperties());
        }
        int maxSessionPerUser = userManagementSetting.getMaxSessionPerUser();
        boolean allowChangeSession = userManagementSetting.isAllowChangeSession();
        EzyStreamingSetting streamingSetting = zoneSetting.getStreaming();
        boolean streamingEnable = streamingSetting.isEnable() && event.isStreamingEnable();
        processUserSessions(user, session, maxSessionPerUser, allowChangeSession, streamingEnable);
        addUserToManager(userManager, user, session, alreadyLoggedIn);
    } finally {
        lock.unlock();
        userManager.removeLock(username);
    }
    fireUserAddedEvent(zoneContext, user, session, event.getData(), alreadyLoggedIn);
    EzyResponse response = newLoginResponse(zoneContext, user, event.getOutput());
    serverContext.send(response, session, false);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyStreamingSetting(com.tvd12.ezyfoxserver.setting.EzyStreamingSetting) EzyUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzyUserManagementSetting) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) Lock(java.util.concurrent.locks.Lock)

Example 3 with EzyUser

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

the class EzyLoginProcessor method newUser.

protected EzyUser newUser(EzyZoneSetting zoneSetting, EzyUserManagementSetting userManagementSetting, String newUserName, String password, Map<Object, Object> properties) {
    EzySimpleUser user = new EzySimpleUser();
    user.setName(newUserName);
    user.setPassword(password);
    user.setZoneId(zoneSetting.getId());
    user.setMaxIdleTime(userManagementSetting.getUserMaxIdleTime());
    user.setMaxSessions(userManagementSetting.getMaxSessionPerUser());
    user.setProperties(properties);
    return user;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser)

Example 4 with EzyUser

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

the class EzyPluginInfoController method handle.

@Override
public void handle(EzyServerContext ctx, EzyPluginInfoRequest request) {
    EzyUser user = request.getUser();
    EzySession session = request.getSession();
    EzyPluginInfoParams params = request.getParams();
    EzyZoneContext zoneCtx = ctx.getZoneContext(user.getZoneId());
    EzyPluginContext pluginCtx = zoneCtx.getPluginContext(params.getPluginName());
    if (pluginCtx != null) {
        EzyPluginSetting setting = pluginCtx.getPlugin().getSetting();
        EzyResponse response = newPluginInfoResponse(setting);
        ctx.send(response, session, false);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginInfoParams(com.tvd12.ezyfoxserver.request.EzyPluginInfoParams) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting)

Example 5 with EzyUser

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

the class EzySimpleAppUserDelegate method handleUserRemovedEvent.

protected void handleUserRemovedEvent(EzyUser user, EzyConstant reason) {
    EzyEvent event = new EzySimpleUserRemovedEvent(user, reason);
    appContext.handleEvent(EzyEventType.USER_REMOVED, event);
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUserRemovedEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRemovedEvent)

Aggregations

EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)26 Test (org.testng.annotations.Test)16 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)13 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)12 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)6 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)6 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)5 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)5 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)5 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)4 EzySessionDelegate (com.tvd12.ezyfoxserver.delegate.EzySessionDelegate)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)4 EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)4 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)4 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)3 EzyArray (com.tvd12.ezyfox.entity.EzyArray)3