use of org.jboss.hal.dmr.ModelDescriptionConstants.GET_SESSION_CREATION_TIME in project console by hal.
the class DeploymentPresenter method reload.
@Override
protected void reload() {
ResourceAddress address = deploymentAddress();
// task 1: read sessions ids, servlets and websockets
Operation readResourceOp = new Operation.Builder(address, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).param(RECURSIVE, true).build();
Operation listSessionsOp = new Operation.Builder(address, LIST_SESSIONS).build();
Task<FlowContext> task1 = context -> dispatcher.execute(new Composite(readResourceOp, listSessionsOp)).doOnSuccess((CompositeResult result) -> {
ModelNode readResourceResult = result.step(0).get(RESULT);
List<NamedNode> servlets = asNamedNodes(failSafePropertyList(readResourceResult, SERVLET));
List<NamedNode> websockets = asNamedNodes(failSafePropertyList(readResourceResult, WEBSOCKET));
// sorted session ids (important for step 2!)
ModelNode listSessionsResult = result.step(1).get(RESULT);
List<String> sessionIds = listSessionsResult.isDefined() ? listSessionsResult.asList().stream().map(ModelNode::asString).sorted().collect(toList()) : Collections.emptyList();
context.set(SERVLETS, servlets);
context.set(WEBSOCKETS, websockets);
context.set(SESSION_IDS, sessionIds);
}).toCompletable();
// task 2: read session creation and last access times
Task<FlowContext> task2 = context -> {
List<String> sessionIds = context.get(SESSION_IDS);
if (sessionIds.isEmpty()) {
context.set(SESSIONS, Collections.emptyList());
return Completable.complete();
} else {
List<Operation> operations = new ArrayList<>();
for (String id : sessionIds) {
operations.add(new Operation.Builder(address, GET_SESSION_CREATION_TIME).param(SESSION_ID, id).build());
operations.add(new Operation.Builder(address, GET_SESSION_LAST_ACCESSED_TIME).param(SESSION_ID, id).build());
}
return dispatcher.execute(new Composite(operations)).doOnSuccess((CompositeResult result) -> {
int i = 0;
List<Session> sessions = new ArrayList<>();
for (String sessionId : sessionIds) {
ModelNode modelNode = new ModelNode();
if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
modelNode.get(CREATION_TIME).set(result.step(i).get(RESULT));
}
i++;
if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
modelNode.get(LAST_ACCESSED_TIME).set(result.step(i).get(RESULT));
}
i++;
sessions.add(new Session(sessionId, modelNode));
}
context.set(SESSIONS, sessions);
}).toCompletable();
}
};
series(new FlowContext(progress.get()), task1, task2).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext context) {
List<Session> sessions = context.get(SESSIONS);
List<NamedNode> servlets = context.get(SERVLETS);
List<NamedNode> websockets = context.get(WEBSOCKETS);
getView().updateSessions(sessions);
getView().updateServlets(servlets);
getView().updateWebsockets(websockets);
}
});
}
Aggregations