use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.
the class EntryCallSequence method removeExpiredSessions.
/**
* removes all expired sessions from the filter and sends them to
* tBehaviorModelPreperationOutputPort.
*/
private void removeExpiredSessions() {
final long timeNow = System.currentTimeMillis() * 1000000;
final Set<String> sessionsToRemove = new HashSet<>();
for (final String sessionId : this.sessions.keySet()) {
final UserSession session = this.sessions.get(sessionId);
final long exitTime = session.getExitTime();
final boolean isExpired = exitTime + EntryCallSequence.USER_SESSION_EXPIRATIONTIME < timeNow;
if (isExpired) {
this.userSessionOutputPort.send(session);
sessionsToRemove.add(sessionId);
}
}
for (final String sessionId : sessionsToRemove) {
this.sessions.remove(sessionId);
}
}
use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.
the class EntryCallSequence method execute.
@Override
protected void execute() {
final ISessionEvent sessionEvent = this.sessionEventInputPort.receive();
if (sessionEvent != null) {
if (sessionEvent instanceof SessionStartEvent) {
this.sessions.put(UserSession.createUserSessionId(sessionEvent), new UserSession(sessionEvent.getHostname(), sessionEvent.getSessionId()));
}
if (sessionEvent instanceof SessionEndEvent) {
final UserSession session = this.sessions.get(UserSession.createUserSessionId(sessionEvent));
if (session != null) {
this.userSessionOutputPort.send(session);
this.sessions.remove(sessionEvent.getSessionId());
}
}
}
final PayloadAwareEntryCallEvent event = this.entryCallInputPort.receive();
if (event != null) {
/**
* add the event to the corresponding user session in case the user session is not yet
* available, create one.
*/
final String userSessionId = UserSession.createUserSessionId(event);
UserSession userSession = this.sessions.get(userSessionId);
if (userSession == null) {
userSession = new UserSession(event.getHostname(), event.getSessionId());
this.sessions.put(userSessionId, userSession);
// TODO this should trigger a warning.
}
userSession.add(event, true);
}
// this.removeExpiredSessions();
}
use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.
the class TEntryCallSequenceWithPCM method execute.
@Override
protected void execute(final PayloadAwareEntryCallEvent event) {
/**
* check if operationEvent is from an known object
*/
if (CorrespondenceUtility.findModelElementForOperation(this.correspondenceModel, Repository.class, event.getClassSignature(), event.getOperationSignature()) != null) {
// add the event to the corresponding user session
// in case the user session is not yet available, create one
final String userSessionId = UserSession.createUserSessionId(event);
UserSession userSession = this.sessions.get(userSessionId);
if (userSession == null) {
userSession = new UserSession(event.getHostname(), event.getSessionId());
this.sessions.put(userSessionId, userSession);
}
// do not sort since TEntryEventSequence will sort any ways
userSession.add(event, false);
// collect all user sessions which have more elements as a defined threshold and send
// them
// to the next filter
final List<UserSession> listToSend = this.sessions.values().stream().filter(session -> session.size() > TEntryCallSequenceWithPCM.USER_SESSION_THRESHOLD).collect(Collectors.toList());
if (!listToSend.isEmpty()) {
this.outputPort.send(new UserSessionCollectionModel(listToSend));
}
}
}
use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.
the class BranchModelCreator method createCallBranchModel.
/**
* It creates a BranchModel from an EntryCallSequenceModel. At that the single sequences are
* aggregated to a tree-like structure: Equal sequences are summarized to one sequence,
* alternative sequences are represented via branches.
*
* @param entryCallSequenceModel
* whose call sequences are aggregated to a coherent CallBranchModel
* @return a BranchModel corresponding to the passed EntryCallSequenceModel
*/
public BranchModel createCallBranchModel(final UserSessionCollectionModel entryCallSequenceModel) {
// Sets the user group's specific workload intensity and likelihood
final BranchModel branchModel = new BranchModel(entryCallSequenceModel.getWorkloadIntensity(), entryCallSequenceModel.getLikelihoodOfUserGroup());
final List<UserSession> userSessions = entryCallSequenceModel.getUserSessions();
// The initial branch that contains the root node
// Every sequence passes this branch -> likelihood of reaching this branch is 1
final Branch rootBranch = new Branch();
rootBranch.setBranchLikelihood(1);
rootBranch.setBranchId(1);
rootBranch.setTreeLevel(0);
// Descending sort by call sequence length
Collections.sort(userSessions, BranchModelCreator.SORT_USER_SESSION_BY_CALL_SEQUENCE_SIZE);
// Initializes the root sequence with the longest call sequence
this.setBranchSequence(rootBranch, userSessions.get(0).getEvents(), 0);
int numberOfBranches = 1;
// loops over all userSession without the first user session that initialized the rootBranch
for (int j = 1; j < userSessions.size(); j++) {
final UserSession userSession = userSessions.get(j);
// The branchGuide guides through the tree structure. It determines the recent regarded
// branch
final List<Integer> branchGuide = new ArrayList<>();
// The position states the recent position within the branch sequence
int positionInBranch = 0;
for (int i = 0; i <= userSession.getEvents().size(); i++) {
// Determines which branch is currently examined
final Branch examinedBranch = this.getExaminedBranch(branchGuide, rootBranch);
if (i < userSession.getEvents().size()) {
final EntryCallEvent callEvent = userSession.getEvents().get(i);
// currently examined branch
if (this.checkPositionMatchInBranch(callEvent, examinedBranch, positionInBranch)) {
this.incrementCountOfBranchElement(examinedBranch, positionInBranch);
positionInBranch++;
continue;
}
// a child branch
if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
final int indexOfMatchingChildBranch = this.getIndexOfMatchingChildBranch(callEvent, examinedBranch);
if (indexOfMatchingChildBranch > -1) {
// Continue with the same call event but switching to the new branch
branchGuide.add(indexOfMatchingChildBranch);
// NOCS
i--;
positionInBranch = 0;
continue;
}
}
// No match could be found --> Split branch into child branches
numberOfBranches = this.splitBranch(examinedBranch, positionInBranch, numberOfBranches, false, userSession, i);
break;
} else {
// End of sequence -> looking for an exit element
if (this.checkIfBranchSequenceTerminates(examinedBranch, positionInBranch)) {
this.incrementCountOfBranchElement(examinedBranch, positionInBranch);
break;
}
// Checks if there is an exit branch
if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
final int indexOfMatchingChildBranch = this.getIndexOfMatchingExitBranch(examinedBranch);
if (indexOfMatchingChildBranch > -1) {
// Iterate the exit state adding but switching to the new branch
branchGuide.add(indexOfMatchingChildBranch);
// NOCS
i--;
positionInBranch = 0;
continue;
}
}
// No matching exit element found --> Split branch into child branches
numberOfBranches = this.splitBranch(examinedBranch, positionInBranch, numberOfBranches, true, null, 0);
break;
}
}
}
branchModel.setRootBranch(rootBranch);
branchModel.setNumberOfBranches(numberOfBranches);
return branchModel;
}
use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.
the class ClusteringPrePostProcessing method getCallCountModel.
/**
* Transforms the passed user sessions to counts of called operation signatures that can be used
* for the similarity calculation of the user group clustering. The objective is to transform
* each user session to a list that contains the number of calls of each distinct operation
* signature. It parses through the entry call sequences of each user session and counts the
* calls of each distinct operation signature. The result is a list of user sessions whose call
* sequence is represented as counts of calls.
*
* @param userSessions
* are transformed to counts of calls
* @param listOfDistinctOperationSignatures
* are the distinct operation signatures whose calls are counted for each user
* session
* @return the passed user sessions as counts of calls
*/
public List<UserSessionAsCountsOfCalls> getCallCountModel(final List<UserSession> userSessions, final List<String> listOfDistinctOperationSignatures) {
final List<UserSessionAsCountsOfCalls> callCountModel = new ArrayList<>();
// during the user session
for (final UserSession userSession : userSessions) {
final UserSessionAsCountsOfCalls absoluteCountOfCalls = new UserSessionAsCountsOfCalls(userSession.getSessionId(), listOfDistinctOperationSignatures.size());
final List<EntryCallEvent> callSequence = userSession.getEvents();
for (int i = 0; i < callSequence.size(); i++) {
final String currentCall = callSequence.get(i).getOperationSignature();
final int indexOfCurrentCall = listOfDistinctOperationSignatures.indexOf(currentCall);
absoluteCountOfCalls.getAbsoluteCountOfCalls()[indexOfCurrentCall] = absoluteCountOfCalls.getAbsoluteCountOfCalls()[indexOfCurrentCall] + 1;
}
callCountModel.add(absoluteCountOfCalls);
}
return callCountModel;
}
Aggregations