Search in sources :

Example 6 with EzySocketUserRemoval

use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval in project ezyfox-server by youngmonkeys.

the class EzySocketUserRemovalHandler method processUserRemoval.

private void processUserRemoval(EzySocketUserRemoval removal) {
    try {
        EzyUser user = removal.getUser();
        try {
            EzyConstant reason = removal.getReason();
            EzyZoneContext zoneContext = removal.getZoneContext();
            EzyUserRemovedEvent event = newUserRemovedEvent(user, reason);
            removeUserFromApps(zoneContext, event);
            notifyUserRemovedToPlugins(zoneContext, event);
        } finally {
            user.destroy();
        }
        logger.debug("user {} has destroyed", user);
    } finally {
        removal.release();
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzyUserRemovedEvent(com.tvd12.ezyfoxserver.event.EzyUserRemovedEvent)

Example 7 with EzySocketUserRemoval

use of com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval 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

EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 Test (org.testng.annotations.Test)5 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)4 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)4 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)3 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)3 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)3 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)2 EzySocketUserRemoval (com.tvd12.ezyfoxserver.socket.EzySocketUserRemoval)2 EzyZone (com.tvd12.ezyfoxserver.EzyZone)1 EzyUserEvent (com.tvd12.ezyfoxserver.event.EzyUserEvent)1 EzyUserRemovedEvent (com.tvd12.ezyfoxserver.event.EzyUserRemovedEvent)1 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)1 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)1 EzyBlockingSocketUserRemovalQueue (com.tvd12.ezyfoxserver.socket.EzyBlockingSocketUserRemovalQueue)1 EzySimpleSocketUserRemoval (com.tvd12.ezyfoxserver.socket.EzySimpleSocketUserRemoval)1