Search in sources :

Example 41 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzyExitAppController method handle.

@Override
public void handle(EzyServerContext ctx, EzyExitAppRequest request) {
    int appId = request.getParams().getAppId();
    EzyAppContext appContext = ctx.getAppContext(appId);
    EzyApplication app = appContext.getApp();
    EzyAppUserManager userManager = app.getUserManager();
    userManager.removeUser(request.getUser(), EzyUserRemoveReason.EXIT_APP);
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 42 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class BaseCoreTest method newServerContext.

protected EzyServerContext newServerContext() {
    EzyServerContext serverContext = newServerContextBuilder().build();
    for (EzyZoneContext zoneContext : serverContext.getZoneContexts()) {
        ((EzyInitable) zoneContext).init();
    }
    for (EzyAppContext appContext : serverContext.getAppContexts()) {
        ((EzyInitable) appContext).init();
    }
    EzySimpleServerContext ctx = (EzySimpleServerContext) serverContext;
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    server.setResponseApi(mock(EzyResponseApi.class));
    return ctx;
}
Also used : EzyInitable(com.tvd12.ezyfox.util.EzyInitable) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi)

Example 43 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandler method removeUserFromApp.

protected void removeUserFromApp(EzyAppContext appContext, EzyUserRemovedEvent event) {
    EzyUser user = event.getUser();
    EzyApplication app = appContext.getApp();
    EzyAppUserManager userManager = app.getUserManager();
    try {
        boolean contains = userManager.containsUser(user);
        if (contains) {
            userManager.removeUser(user, event.getReason());
        }
    } catch (Exception e) {
        String appName = app.getSetting().getName();
        logger.error("remove user: {} from app: {} error", event.getUser(), appName, e);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyProcessor.processWithLogException(com.tvd12.ezyfox.util.EzyProcessor.processWithLogException)

Example 44 with EzyAppContext

use of com.tvd12.ezyfoxserver.context.EzyAppContext in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandlerTest method notifyUserRemovedToPluginsExceptionCaseTest.

@Test
public void notifyUserRemovedToPluginsExceptionCaseTest() {
    TestBlockingSocketUserRemovalQueue queue = new TestBlockingSocketUserRemovalQueue();
    EzyAppContext appContext1 = mock(EzyAppContext.class);
    EzyAppUserManager userManager1 = mock(EzyAppUserManager.class);
    when(userManager1.containsUser(any(EzyUser.class))).thenReturn(true);
    EzyApplication app1 = mock(EzyApplication.class);
    when(app1.getUserManager()).thenReturn(userManager1);
    when(appContext1.getApp()).thenReturn(app1);
    doThrow(new RuntimeException()).when(appContext1).handleEvent(any(EzyConstant.class), any(EzyUserEvent.class));
    EzyAppContext appContext2 = mock(EzyAppContext.class);
    EzyAppUserManager userManager2 = mock(EzyAppUserManager.class);
    when(userManager2.containsUser(any(EzyUser.class))).thenReturn(false);
    EzyApplication app2 = mock(EzyApplication.class);
    when(app2.getUserManager()).thenReturn(userManager2);
    when(appContext2.getApp()).thenReturn(app2);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getAppContexts()).thenReturn(Lists.newArrayList(appContext1, appContext2));
    EzyZone zone = mock(EzyZone.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneSetting zoneSetting = mock(EzyZoneSetting.class);
    when(zoneSetting.getName()).thenReturn("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    doThrow(new RuntimeException()).when(zoneContext).broadcastPlugins(any(EzyConstant.class), any(EzyUserEvent.class), anyBoolean());
    EzySimpleUser user = new EzySimpleUser();
    user.setName("test");
    EzySocketUserRemoval item = new EzySimpleSocketUserRemoval(zoneContext, user, EzyUserRemoveReason.EXIT_APP);
    queue.add(item);
    EzySocketUserRemovalHandler handler = new EzySocketUserRemovalHandler(queue);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyUserEvent(com.tvd12.ezyfoxserver.event.EzyUserEvent) Test(org.testng.annotations.Test)

Aggregations

EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)32 Test (org.testng.annotations.Test)24 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)21 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)18 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)18 BaseTest (com.tvd12.test.base.BaseTest)15 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)12 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)11 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)11 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)10 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)9 EzySimpleAppUserDelegate (com.tvd12.ezyfoxserver.delegate.EzySimpleAppUserDelegate)7 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)6 EzyAppRequestController (com.tvd12.ezyfoxserver.app.EzyAppRequestController)5 EzySimpleUserAccessAppEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)5 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)5 EzyAppSetting (com.tvd12.ezyfoxserver.setting.EzyAppSetting)5 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyZone (com.tvd12.ezyfoxserver.EzyZone)4 EzyAccessAppController (com.tvd12.ezyfoxserver.controller.EzyAccessAppController)4