Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collect local request type #93

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/org/usf/inspect/core/LocalRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ public class LocalRequest extends SessionStage implements MutableStage {

private String name; //method, title
private String location; //class, URL
private String type;
private ExceptionInfo exception;

@Override
String prettyFormat() {
var s = isNull(getUser()) ? "" : '<' + getUser() + '>';
var s = isNull(type) ? "" : '['+type+']';
if(nonNull(getUser())) {
s+= '<' + getUser() + '>';
}
s+= name + "(" + location + ")";
if(nonNull(exception)) {
s += " >> " + exception;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/usf/inspect/core/LocalRequestType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.usf.inspect.core;

public enum LocalRequestType {

CONST, //enum.
FILE, //read|write
CACHE, //put|get
EXEC //run

}
7 changes: 1 addition & 6 deletions src/main/java/org/usf/inspect/core/MainSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class MainSession extends LocalRequest implements Session {

private String id;
private String type; //@see MainSessionType
// inherits String type //@see MainSessionType
private List<RestRequest> restRequests;
private List<DatabaseRequest> databaseRequests;
private List<LocalRequest> localRequests;
Expand All @@ -30,9 +30,4 @@ public class MainSession extends LocalRequest implements Session {
private List<NamingRequest> ldapRequests;

private final AtomicInteger lock = new AtomicInteger();

@Override
public String toString() {
return '['+type+']'+ super.toString();
}
}
9 changes: 7 additions & 2 deletions src/main/java/org/usf/inspect/core/MainSessionAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static org.usf.inspect.core.Helper.formatLocation;
import static org.usf.inspect.core.Helper.newInstance;
import static org.usf.inspect.core.Helper.threadName;
import static org.usf.inspect.core.LocalRequestType.CACHE;
import static org.usf.inspect.core.LocalRequestType.EXEC;
import static org.usf.inspect.core.SessionManager.currentSession;
import static org.usf.inspect.core.SessionManager.endSession;
import static org.usf.inspect.core.SessionManager.localRequestCreator;
Expand All @@ -19,6 +21,7 @@
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.core.Ordered;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -49,6 +52,7 @@ Object aroundBatch(ProceedingJoinPoint joinPoint) throws Throwable {
}
return call(joinPoint::proceed, (s,e,o,t)-> {
var req = new LocalRequest();
req.setType(EXEC.name());
fill(req, s, e, joinPoint, t);
return req;
}, requestAppender());
Expand All @@ -57,8 +61,10 @@ Object aroundBatch(ProceedingJoinPoint joinPoint) throws Throwable {
@Around("@annotation(org.springframework.cache.annotation.Cacheable)")
Object aroundCacheable(ProceedingJoinPoint joinPoint) throws Throwable {
var sign = joinPoint.getSignature();
var annt = ((MethodSignature)joinPoint.getSignature()).getMethod().getAnnotation(Cacheable.class);
var name = isNull(annt) || annt.key().isEmpty() ? sign.getName() : annt.key();
return call(joinPoint::proceed,
localRequestCreator(sign.getName(), formatLocation(sign.getDeclaringTypeName(), sign.getName()), null),
localRequestCreator(name, formatLocation(sign.getDeclaringTypeName(), sign.getName()), CACHE),
requestAppender());
}

Expand All @@ -69,7 +75,6 @@ static void fill(LocalRequest stg, Instant start, Instant end, ProceedingJoinPoi
stg.setName(ant.value().isBlank() ? joinPoint.getSignature().getName() : ant.value());
stg.setLocation(joinPoint.getSignature().getDeclaringTypeName());
stg.setThreadName(threadName());
stg.setUser(null); // default user supplier
stg.setException(mainCauseException(e));
if(ant.sessionUpdater() != StageUpdater.class) { //specific.
newInstance(ant.sessionUpdater())
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/usf/inspect/core/MainSessionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
public enum MainSessionType {

VIEW, //replace webapp
VIEW,
BATCH,
//v22
STARTUP;
}
9 changes: 5 additions & 4 deletions src/main/java/org/usf/inspect/core/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.usf.inspect.core.Helper.synchronizedArrayList;
import static org.usf.inspect.core.Helper.threadName;
import static org.usf.inspect.core.Helper.warnStackTrace;
import static org.usf.inspect.core.LocalRequestType.EXEC;
import static org.usf.inspect.core.MainSessionType.BATCH;
import static org.usf.inspect.core.MainSessionType.STARTUP;
import static org.usf.inspect.core.Session.nextId;
Expand Down Expand Up @@ -130,22 +131,22 @@ public static MainSession endStatupSession() {
}

public static <E extends Throwable> void trackRunnable(String name, SafeRunnable<E> fn) throws E {
exec(fn, localRequestCreator(name, stackLocation(), null), requestAppender());
exec(fn, localRequestCreator(name, stackLocation(), EXEC), requestAppender());
}

public static <T, E extends Throwable> T trackCallble(String name, SafeCallable<T,E> fn) throws E {
return call(fn, localRequestCreator(name, stackLocation(), null), requestAppender());
return call(fn, localRequestCreator(name, stackLocation(), EXEC), requestAppender());
}

public static <T> StageCreator<T, LocalRequest> localRequestCreator(String name, String location, String user) {
public static <T> StageCreator<T, LocalRequest> localRequestCreator(String name, String location, LocalRequestType type) {
return (s,e,o,t)->{
var req = new LocalRequest();
req.setName(name);
req.setLocation(location);
req.setUser(user);
req.setStart(s);
req.setEnd(e);
req.setThreadName(threadName());
req.setType(isNull(type) ? null : type.name());
if(nonNull(t)) {
req.setException(mainCauseException(t));
}
Expand Down
Loading