use of com.tvd12.example.lucky_wheel.entity.User 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();
}
}
use of com.tvd12.example.lucky_wheel.entity.User 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.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.
the class EzyAbstractUserManager method addUser.
@Override
public EzyUser addUser(EzyUser user) {
EzyUser answer = doAddUser(user);
logger.info("{} add user: {}, locks.size = {}, usersById.size = {}, usersByName.size = {}", getMessagePrefix(), user, locks.size(), usersById.size(), usersByName.size());
return answer;
}
use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.
the class EzySimplePluginEntryTest method handleClientRequest.
private void handleClientRequest(EzyPluginContext context) {
EzySimplePlugin plugin = (EzySimplePlugin) context.getPlugin();
EzyPluginRequestController requestController = plugin.getRequestController();
EzyAbstractSession session = spy(EzyAbstractSession.class);
EzySimpleUser user = new EzySimpleUser();
EzyArray data = EzyEntityFactory.newArrayBuilder().append("chat").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
EzyUserRequestPluginEvent event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("chat").build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("no command").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noUser").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noSession").append(EzyEntityFactory.newObjectBuilder().append("message", "greet")).build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("noDataBinding").build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("badRequestSend").build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("badRequestNoSend").build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
data = EzyEntityFactory.newArrayBuilder().append("exception").build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
try {
requestController.handle(context, event);
} catch (Exception e) {
assert e instanceof IllegalStateException;
}
data = EzyEntityFactory.newArrayBuilder().append("plugin").build();
event = new EzySimpleUserRequestPluginEvent(user, session, data);
requestController.handle(context, event);
}
use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.
the class EzyUserManagerImplTest method test.
@Test
public void test() {
MyTestUserManager manager = MyTestUserManager.builder().build();
MyTestSession session = new MyTestSession();
session.setId(10);
MyTestUser user = new MyTestUser();
user.setId(1);
user.setName("dungtv");
session.setToken("123456");
user.addSession(session);
manager.addUser(session, user);
assert manager.getUser(1) == user;
assert manager.getUser("dungtv") == user;
assert manager.containsUser(1);
assert !manager.containsUser(-1);
assert manager.containsUser(session);
assert manager.containsUser(user);
manager.removeUser(user.getId());
assert manager.getUser(1) == null;
manager.addUser(session, user);
manager.removeUser(user.getName());
assert manager.getUser("dungtv") == null;
manager.addUser(session, user);
manager.removeUser((EzyUser) null);
}
Aggregations