Skip to content

Commit a17d91a

Browse files
Remove RequestRecordHolder
This class is no longer needed. Functionality was taken over by MDC.
1 parent 756e073 commit a17d91a

File tree

9 files changed

+38
-110
lines changed

9 files changed

+38
-110
lines changed

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/RequestRecord.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.sap.hcp.cf.logging.common;
22

3-
import java.io.Closeable;
43
import java.util.HashMap;
54
import java.util.HashSet;
65
import java.util.Map;
@@ -39,7 +38,7 @@
3938
*
4039
*
4140
*/
42-
public class RequestRecord implements Closeable {
41+
public class RequestRecord {
4342

4443
/*
4544
* -- default values for request fields that are marked as "required"
@@ -100,7 +99,6 @@ public RequestRecord(String layerKey, Direction direction) {
10099
addTag(Fields.DIRECTION, direction.toString());
101100
setDefaults();
102101
start();
103-
RequestRecordHolder.add(this);
104102
}
105103

106104
/**
@@ -198,11 +196,6 @@ public long stop() {
198196
return endMs;
199197
}
200198

201-
@Override
202-
public void close() {
203-
RequestRecordHolder.remove(this);
204-
}
205-
206199
@Override
207200
public String toString() {
208201
/*

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/RequestRecordHolder.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

cf-java-logging-support-core/src/test/java/com/sap/hcp/cf/logging/common/RequestRecordConfiguratorTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public void testAddingSingleActivatedOptionalTagToRequestRecord() throws JSONObj
2020
String tag = "TestTag";
2121

2222
to(requestRecord).addOptionalTag(canBeLogged, key, tag);
23-
requestRecord.close();
2423

2524
assertEquals(tag, getFieldFromRequestRecord(requestRecord, key));
2625
}
@@ -33,7 +32,6 @@ public void testAddingSingleForbiddenOptionalTagToRequestRecord() throws JSONObj
3332
String tag = "TestTag";
3433

3534
to(requestRecord).addOptionalTag(canBeLogged, key, tag);
36-
requestRecord.close();
3735

3836
assertEquals(Defaults.REDACTED, getFieldFromRequestRecord(requestRecord, key));
3937
}
@@ -46,7 +44,6 @@ public void testAddingSingleForbiddenOptionalNullTagToRequestRecord() throws JSO
4644
String tag = Defaults.UNKNOWN;
4745

4846
to(requestRecord).addOptionalTag(canBeLogged, key, tag);
49-
requestRecord.close();
5047

5148
assertEquals(Defaults.UNKNOWN, getFieldFromRequestRecord(requestRecord, key));
5249
}
@@ -59,7 +56,6 @@ public void testAddingSingleActivatedOptionalNullTagToRequestRecord() throws JSO
5956
String tag = Defaults.UNKNOWN;
6057

6158
to(requestRecord).addOptionalTag(canBeLogged, key, tag);
62-
requestRecord.close();
6359

6460
assertEquals(Defaults.UNKNOWN, getFieldFromRequestRecord(requestRecord, key));
6561
}

cf-java-logging-support-core/src/test/java/com/sap/hcp/cf/logging/common/converter/TestJsonMessageConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public void testLogRecordMsgNotFlattened() {
5858
RequestRecord lrec = new RequestRecord(LOG_PROVIDER);
5959
String lmsg = lrec.toString();
6060
assertThat(formatMsg(jmc, lmsg), is(lmsg));
61-
lrec.close();
6261
}
6362

6463
@Test
@@ -68,7 +67,6 @@ public void testLogRecordMsgFlattened() {
6867
RequestRecord lrec = new RequestRecord(LOG_PROVIDER);
6968
String lmsg = lrec.toString();
7069
assertThat(formatMsg(jmc, lmsg), is(lmsg.substring(1, lmsg.length() - 1)));
71-
lrec.close();
7270
}
7371

7472
@Test

cf-java-logging-support-jersey/src/main/java/com/sap/hcp/cf/logging/jersey/filter/ResponseHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ public void handle(ResponseContextAdapter responseContext, RequestRecord rr) {
2020
rr.addValue(Fields.RESPONSE_STATUS, new LongValue(responseContext.getStatus()));
2121
rr.stop();
2222
LOGGER.info(Markers.REQUEST_MARKER, "{}", rr);
23-
/*
24-
* -- close this instance
25-
*/
26-
rr.close();
2723
} else {
2824
LOGGER.error("No record found to handle response {}", responseContext);
2925
}

cf-java-logging-support-log4j2/src/test/java/com/sap/hcp/cf/log4j2/converter/TestJsonMessageConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public void testLogRecordMsgNotFlattened() {
5656
RequestRecord lrec = new RequestRecord(LOG_PROVIDER);
5757
String lmsg = lrec.toString();
5858
assertThat(format(jmc, makeEvent(lmsg, NO_ARGS)), is(lmsg));
59-
lrec.close();
6059
}
6160

6261
@Test
@@ -65,7 +64,6 @@ public void testLogRecordMsgFlattened() {
6564
RequestRecord lrec = new RequestRecord(LOG_PROVIDER);
6665
String lmsg = lrec.toString();
6766
assertThat(format(jmc, makeEvent(lmsg, NO_ARGS)), is(lmsg.substring(1, lmsg.length() - 1)));
68-
lrec.close();
6967
}
7068

7169
@Test

cf-java-logging-support-logback/src/main/java/com/sap/hcp/cf/logback/perf/PerfTestRequestRecord.java

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,39 @@
1212

1313
public class PerfTestRequestRecord {
1414

15-
private static final int DEF_ITERATIONS = 1000000;
16-
private final int iterations;
17-
private static final Logger LOGGER = LoggerFactory.getLogger(PerfTestRequestRecord.class);
18-
19-
public PerfTestRequestRecord(int iterations) {
20-
if (iterations > 0) {
21-
this.iterations = iterations;
22-
} else {
23-
this.iterations = DEF_ITERATIONS;
24-
}
25-
}
26-
27-
public static void main(String[] args) {
28-
new PerfTestRequestRecord(DEF_ITERATIONS).run(args);
29-
}
30-
31-
private void run(String[] args) {
32-
long start = System.nanoTime();
33-
PrintStream defOut = System.out;
34-
System.setOut(new PrintStream(new OutputStream() {
35-
36-
@Override
37-
public void write(int b) throws IOException {
38-
}
39-
}));
40-
for (int i = 0; i < iterations; i++) {
41-
RequestRecord rrec = null;
42-
try {
43-
rrec = new RequestRecord(PerfTestRequestRecord.class.getName());
44-
LOGGER.info(Markers.REQUEST_MARKER, rrec.toString());
45-
} finally {
46-
rrec.close();
47-
}
48-
}
49-
double delta = (System.nanoTime() - start) / 1000000.0;
50-
System.setOut(defOut);
51-
System.out.println("Writing " + iterations + " records took " + delta + " msecs, " + delta / iterations +
52-
" msecs per record");
53-
}
15+
private static final int DEF_ITERATIONS = 1000000;
16+
private final int iterations;
17+
private static final Logger LOGGER = LoggerFactory.getLogger(PerfTestRequestRecord.class);
18+
19+
public PerfTestRequestRecord(int iterations) {
20+
if (iterations > 0) {
21+
this.iterations = iterations;
22+
} else {
23+
this.iterations = DEF_ITERATIONS;
24+
}
25+
}
26+
27+
public static void main(String[] args) {
28+
new PerfTestRequestRecord(DEF_ITERATIONS).run(args);
29+
}
30+
31+
private void run(String[] args) {
32+
long start = System.nanoTime();
33+
PrintStream defOut = System.out;
34+
System.setOut(new PrintStream(new OutputStream() {
35+
36+
@Override
37+
public void write(int b) throws IOException {
38+
}
39+
}));
40+
for (int i = 0; i < iterations; i++) {
41+
RequestRecord rrec = new RequestRecord(PerfTestRequestRecord.class.getName());
42+
LOGGER.info(Markers.REQUEST_MARKER, rrec.toString());
43+
}
44+
double delta = (System.nanoTime() - start) / 1000000.0;
45+
System.setOut(defOut);
46+
System.out.println("Writing " + iterations + " records took " + delta + " msecs, " + delta / iterations
47+
+ " msecs per record");
48+
}
5449

5550
}

cf-java-logging-support-logback/src/test/java/com/sap/hcp/cf/logback/converter/TestJsonMessageConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public void testLogRecordMsgNotFlattened() {
6666
RequestRecord lrec = new RequestRecord(LOG_PROVIDER);
6767
String lmsg = lrec.toString();
6868
assertThat(jmc.convert(makeEvent(lmsg, NO_ARGS)), is(lmsg));
69-
lrec.close();
7069
}
7170

7271
@Test
@@ -77,7 +76,6 @@ public void testLogRecordMsgFlattened() {
7776
RequestRecord lrec = new RequestRecord(LOG_PROVIDER);
7877
String lmsg = lrec.toString();
7978
assertThat(jmc.convert(makeEvent(lmsg, NO_ARGS)), is(lmsg.substring(1, lmsg.length() - 1)));
80-
lrec.close();
8179
}
8280

8381
@Test

cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/RequestLoggingFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ private void doFilterRequest(HttpServletRequest httpRequest, HttpServletResponse
9393
*/
9494
LogContext.initializeContext(getCorrelationIdFromHeader(httpRequest));
9595

96-
RequestRecord rr = null;
9796
try {
98-
rr = new RequestRecord(LOG_PROVIDER);
97+
RequestRecord rr = new RequestRecord(LOG_PROVIDER);
9998
ContentLengthTrackingResponseWrapper responseWrapper = null;
10099
ContentLengthTrackingRequestWrapper requestWrapper = null;
101100

@@ -125,6 +124,8 @@ private void doFilterRequest(HttpServletRequest httpRequest, HttpServletResponse
125124
}
126125
rr.stop();
127126

127+
LOGGER.info("Request is async? {}", httpRequest.isAsyncStarted());
128+
128129
if (requestWrapper != null) {
129130
rr.addValue(Fields.REQUEST_SIZE_B, new LongValue(requestWrapper.getContentLength()));
130131
} else {
@@ -148,8 +149,6 @@ private void doFilterRequest(HttpServletRequest httpRequest, HttpServletResponse
148149
* -- close this
149150
*/
150151
} finally {
151-
rr.close();
152-
153152
if (dynamicLogLevelProcessor != null) {
154153
dynamicLogLevelProcessor.removeDynamicLogLevelFromMDC();
155154
}

0 commit comments

Comments
 (0)