use of com.tvd12.ezyfoxserver.EzyApplication 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);
}
}
use of com.tvd12.ezyfoxserver.EzyApplication 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);
}
use of com.tvd12.ezyfoxserver.EzyApplication 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);
}
}
use of com.tvd12.ezyfoxserver.EzyApplication 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();
}
Aggregations