org.snapscript.studio.agent.debug.ScopeEventBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.studio.agent.debug;
import static org.snapscript.studio.agent.debug.ScopeVariableTree.EMPTY;
import java.util.concurrent.atomic.AtomicInteger;
import org.snapscript.core.trace.TraceType;
import org.snapscript.studio.agent.ProcessMode;
import org.snapscript.studio.agent.event.ScopeEvent;
public class ScopeEventBuilder {
private final ScopeVariableTree blank;
private final ScopeExtractor extractor;
private final AtomicInteger counter;
private final TraceType type;
private final String process;
private final String resource;
private final String thread;
private final String stack;
private final int line;
private final int depth;
private final int count;
public ScopeEventBuilder(ScopeExtractor extractor, TraceType type, String process, String thread, String stack, String resource, int line, int depth, int count) {
this.counter = new AtomicInteger();
this.blank = EMPTY;
this.extractor = extractor;
this.process = process;
this.thread = thread;
this.resource = resource;
this.stack = stack;
this.line = line;
this.depth = depth;
this.count = count;
this.type = type;
}
public ScopeEvent suspendEvent(ProcessMode mode) {
boolean remote = mode.isRemoteAttachment();
int count = counter.getAndIncrement();
ScopeContext context = extractor.build(remote, count > 0 || !remote); // this is totally rubbish
ScopeVariableTree variables = context.getTree();
String source = context.getSource();
String name = type.name();
return new ScopeEvent.Builder(process)
.withVariables(variables)
.withThread(thread)
.withStack(stack)
.withInstruction(name)
.withStatus(ThreadStatus.SUSPENDED)
.withResource(resource)
.withSource(source)
.withLine(line)
.withDepth(depth)
.withKey(count)
.build();
}
public ScopeEvent resumeEvent(ProcessMode mode) {
String name = type.name();
return new ScopeEvent.Builder(process)
.withVariables(blank)
.withThread(thread)
.withStack(stack)
.withInstruction(name)
.withStatus(ThreadStatus.RUNNING)
.withResource(resource)
.withLine(line)
.withDepth(depth)
.withKey(count)
.build();
}
}