final UndertowDeploymentService deploymentService = (UndertowDeploymentService) controller.getService();
Deployment deployment = deploymentService.getDeployment();
SessionManager sessionManager = deployment.getSessionManager();
SessionStat stat = SessionStat.getStat(operation.require(ModelDescriptionConstants.NAME).asString());
SessionManagerStatistics sms = sessionManager instanceof SessionManagerStatistics ? (SessionManagerStatistics) sessionManager : null;
if (stat == null) {
context.getFailureDescription().set(UndertowLogger.ROOT_LOGGER.unknownMetric(operation.require(ModelDescriptionConstants.NAME).asString()));
} else {
ModelNode result = new ModelNode();
switch (stat) {
case ACTIVE_SESSIONS:
result.set(sessionManager.getActiveSessions().size());
break;
case EXPIRED_SESSIONS:
if(sms == null) {
result.set(0);
} else {
result.set((int)sms.getExpiredSessionCount());
}
break;
case MAX_ACTIVE_SESSIONS:
if(sms == null) {
result.set(0);
} else {
result.set((int)sms.getMaxActiveSessions());
}
break;
case SESSIONS_CREATED:
if(sms == null) {
result.set(0);
} else {
result.set((int)sms.getCreatedSessionCount());
}
break;
//case DUPLICATED_SESSION_IDS:
// result.set(sm.getDuplicates());
// break;
case SESSION_AVG_ALIVE_TIME:
if(sms == null) {
result.set(0);
} else {
result.set((int)sms.getAverageSessionAliveTime());
}
break;
case SESSION_MAX_ALIVE_TIME:
if(sms == null) {
result.set(0);
} else {
result.set((int)sms.getMaxSessionAliveTime());
}
break;
case REJECTED_SESSIONS:
if(sms == null) {
result.set(0);
} else {
result.set((int)sms.getRejectedSessions());
}
break;
default:
throw new IllegalStateException(UndertowLogger.ROOT_LOGGER.unknownMetric(stat));
}