Skip to content
Draft
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
2 changes: 1 addition & 1 deletion agent/src/main/java/com/appland/appmap/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static void startAutoRecording(Runnable logShutdown) {
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmss");
final String timestamp = dateFormat.format(date);
final Metadata metadata = new Metadata("java", "process");
final Recorder recorder = Recorder.getInstance();
final Recorder recorder = Recorder.INSTANCE;
if (appmapName == null || appmapName.trim().isEmpty()) {
appmapName = timestamp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Hooks to capture method invocations from classes included in configuration.
*/
public class MethodCall {
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

@ArgumentArray
@HookCondition(ConfigCondition.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Hooks to capture method exceptions from classes included in configuration.
*/
public class MethodException {
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

@ArgumentArray
@HookCondition(value = ConfigCondition.class, methodEvent = MethodEvent.METHOD_EXCEPTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Hooks to capture method returns from classes included in configuration.
*/
public class MethodReturn {
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;
private static final EventTemplateRegistry templateRegistry = EventTemplateRegistry.get();

@ArgumentArray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.appland.appmap.transform.annotations.MethodEvent;

public class RecordMethod {
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

@ArgumentArray
@ExcludeReceiver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class RecordingSupport {
private static final TaggedLogger logger = AppMapConfig.getLogger(null);

private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

public static class TestDetails {
public String definedClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void start(HttpServletRequest req) {
RecordingSession recordingSession = new RecordingSession(metadata);

try {
Recorder.getInstance().setThreadSession(recordingSession);
Recorder.INSTANCE.setThreadSession(recordingSession);
req.setAttribute(ServletListener.RECORDING_ATTRIBUTE, recordingSession);
} catch (ActiveSessionException e) {
ServletListener.logger.warn(e);
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void stop(HttpServletRequest req) {
localStart.format(Recording.RECORDING_TIME_FORMATTER));
recordingSession.getMetadata().scenarioName = appMapName;

Recording recording = Recorder.getInstance().stopThread();
Recording recording = Recorder.INSTANCE.stopThread();
String filename = String.format("%.3f_%s", startTime.toEpochMilli() / 1000.0, req.getRequestURI());
filename = Recorder.sanitizeFilename(filename) + ".appmap.json";
recording.moveTo(filename);
Expand All @@ -75,7 +75,7 @@ public static void stop(HttpServletRequest req) {
* abort stops the current thread's recording and throws it away.
*/
public static void abort() {
Recorder.getInstance().stopThread();
Recorder.INSTANCE.stopThread();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
@Unique("sql_query")
public class SqlQuery {
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

// ================================================================================================
// Calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class HttpClientRequest {
private static final TaggedLogger logger = AppMapConfig.getLogger(null);

private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

/*
* See https://hc.apache.org/httpcomponents-client-4.5.x/index.html for a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class HttpServerRequest {
private static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = "org.springframework.web.servlet.HandlerMapping.uriTemplateVariables";

private static final String LAST_EVENT_KEY = PACKAGE_NAME + ".lastEvent";
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

public static void recordHttpServerRequest(Event event, HttpServletRequest req) {
if (req.getRequestURI().endsWith(RemoteRecordingManager.RecordRoute)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface RemoteRecordingRequest {
public class RemoteRecordingManager {
private static final TaggedLogger logger = AppMapConfig.getLogger(null);

private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;
public static final String RecordRoute = "/_appmap/record";
public static final String CheckpointRoute = "/_appmap/record/checkpoint";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TestNG {
private static final TaggedLogger logger = AppMapConfig.getLogger(null);
private static final String TESTNG_NAME = "testng";

private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;
private static final ThreadLocal<Event> lastReturnEvent = new ThreadLocal<>();

private static class ITestResult extends ReflectiveType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class EventTemplateRegistry {
private static final TaggedLogger logger = AppMapConfig.getLogger(null);

private static final EventTemplateRegistry instance = new EventTemplateRegistry();
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

private final List<Event> eventTemplates = new ArrayList<>();

Expand Down
20 changes: 4 additions & 16 deletions agent/src/main/java/com/appland/appmap/record/Recorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Event getLastThreadEvent() {
* Recorder is a singleton responsible for managing recording sessions and routing events to any
* active session. It also maintains a code object tree containing every known package/class/method.
*/
public class Recorder {
public enum Recorder {
INSTANCE;

private static final String ERROR_SESSION_PRESENT = "an active recording session already exists";
private static final String ERROR_NO_SESSION = "there is no active recording session";

private static final Recorder instance = new Recorder();

private final ActiveSession activeSession = new ActiveSession();
private final CodeObjectTree globalCodeObjects = new CodeObjectTree();
private final Map<Long, ThreadState> threadState = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -184,18 +184,6 @@ synchronized void addThreadEvent(Event event) {
}
}

/**
* Get the global Recorder instance.
*
* @return The global recorder instance
*/
public static Recorder getInstance() {
return Recorder.instance;
}

private Recorder() {
}

/**
* Start a recording session.
*
Expand Down Expand Up @@ -266,7 +254,7 @@ public void add(Event event) {
event.ignore();
}
}

event.setStartTime();
ts.callStack.push(event);
} else if ( event.event.equals("return") ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public synchronized Recording stop() {
}

CodeObjectTree getClassMap() {
CodeObjectTree registeredObjects = Recorder.getInstance().getRegisteredObjects();
CodeObjectTree registeredObjects = Recorder.INSTANCE.getRegisteredObjects();
CodeObjectTree classMap = new CodeObjectTree();
for (String key : this.classReferences) {
String[] parts = key.split(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


public class RecorderTest {
private static final Recorder recorder = Recorder.getInstance();
private static final Recorder recorder = Recorder.INSTANCE;

@BeforeEach
public void initialize() throws Exception {
Expand Down
13 changes: 7 additions & 6 deletions agent/src/test/java/com/appland/appmap/record/RecorderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -50,13 +51,13 @@ public void before() throws Exception {
final Recorder.Metadata metadata =
new Recorder.Metadata("recorder_test", "tests");

Recorder.getInstance().start(metadata);
Recorder.INSTANCE.start(metadata);
}

@AfterEach
public void after() throws Exception {
if ( Recorder.getInstance().hasActiveSession()) {
Recorder.getInstance().stop();
if (Recorder.INSTANCE.hasActiveSession()) {
Recorder.INSTANCE.stop();
}
}

Expand All @@ -74,7 +75,7 @@ private Event newEvent() {
}

private Recorder recordEvents() {
final Recorder recorder = Recorder.getInstance();
final Recorder recorder = Recorder.INSTANCE;
final Event[] events = new Event[3];

for (int i = 0; i < events.length; i++) {
Expand Down Expand Up @@ -189,7 +190,7 @@ public void testAllEventsWritten() throws IOException {

@Test
public void testMultithreadCheckpoint() throws InterruptedException {
final Recorder recorder = spy(Recorder.getInstance());
final Recorder recorder = spy(Recorder.INSTANCE);

// This puts an entry in recorder.threadState, so there will be a
// value to iterate over.
Expand Down Expand Up @@ -221,7 +222,7 @@ public void testMultithreadCheckpoint() throws InterruptedException {
iterLock.release();
eventAddedLock.acquire();
return ret;
}).when(recorder).getThreadStateIterator();
}).when(recorder).getThreadStateIterator();

recorder.checkpoint();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline
2 changes: 1 addition & 1 deletion agent/test/access/RecordPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class RecordPackage {
public static void main(String[] argv) {
final Recording recording = Recorder.getInstance().record(() -> {
final Recording recording = Recorder.INSTANCE.record(() -> {
new MyClass().callNonPublic();
});

Expand Down
2 changes: 1 addition & 1 deletion agent/test/access/RecordUnnamed.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class RecordUnnamed {
public static void main(String[] argv) {
final Recording recording = Recorder.getInstance().record(() -> {
final Recording recording = Recorder.INSTANCE.record(() -> {
new HelloWorld().getGreetingWithPunctuation("!");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
@Override
public int runTest() throws IOException {
try {
Recorder recorder = Recorder.getInstance();
Recorder recorder = Recorder.INSTANCE;
Recording recording = recorder.record(() -> {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class HttpClientTest {

public static void main(String[] argv) throws IOException {

final Recording recording = Recorder.getInstance().record(() -> {
final Recording recording = Recorder.INSTANCE.record(() -> {
try {
new HttpClientTest(argv[0], argv.length > 1 ? argv[1] : null).run();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HttpHostTest {

public static void main(String[] argv) throws IOException {

final Recording recording = Recorder.getInstance().record(() -> {
final Recording recording = Recorder.INSTANCE.record(() -> {
try {
new HttpHostTest(argv[0], Integer.parseInt(argv[1]), argv[2]).run();
} catch (IOException e) {
Expand Down