Skip to content

Commit 2f0ec92

Browse files
committed
improve Recorder
Signed-off-by: Stefan Bischof <[email protected]>
1 parent 88d17ab commit 2f0ec92

File tree

7 files changed

+183
-240
lines changed

7 files changed

+183
-240
lines changed
Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
/*
2-
// This software is subject to the terms of the Eclipse Public License v1.0
3-
// Agreement, available at the following URL:
4-
// http://www.eclipse.org/legal/epl-v10.html.
5-
// You must accept the terms of that agreement to use this software.
6-
//
7-
// Copyright (C) 2005-2005 Julian Hyde
8-
// Copyright (C) 2005-2017 Hitachi Vantara and others
9-
// All Rights Reserved.
10-
*/
2+
* This software is subject to the terms of the Eclipse Public License v1.0
3+
* Agreement, available at the following URL:
4+
* http://www.eclipse.org/legal/epl-v10.html.
5+
* You must accept the terms of that agreement to use this software.
6+
*
7+
* Copyright (C) 2005-2005 Julian Hyde
8+
* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved.
9+
*
10+
* ---- All changes after Fork in 2023 ------------------------
11+
*
12+
* Project: Eclipse daanse
13+
*
14+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
15+
*
16+
* This program and the accompanying materials are made
17+
* available under the terms of the Eclipse Public License 2.0
18+
* which is available at https://www.eclipse.org/legal/epl-2.0/
19+
*
20+
* SPDX-License-Identifier: EPL-2.0
21+
*
22+
* Contributors after Fork in 2023:
23+
* SmartCity Jena - initial
24+
*/
1125

1226
package mondrian.recorder;
1327

@@ -23,20 +37,14 @@
2337
*/
2438
public abstract class AbstractRecorder implements MessageRecorder {
2539

26-
private final static String tooManyMessageRecorderErrors =
27-
"Context ''{0}'': Exceeded number of allowed errors ''{1,number}''";
28-
private final static String forceMessageRecorderError =
29-
"Context ''{0}'': Client forcing return with errors ''{1,number}''";
40+
private final static String tooManyMessageRecorderErrors = "Context ''{0}'': Exceeded number of allowed errors ''{1,number}''";
41+
private final static String forceMessageRecorderError = "Context ''{0}'': Client forcing return with errors ''{1,number}''";
3042

3143
/**
3244
* Helper method to format a message and write to logger.
3345
*/
34-
public static void logMessage(
35-
final String context,
36-
final String msg,
37-
final MsgType msgType,
38-
final Logger logger)
39-
{
46+
public static void logMessage(final String context, final String msg, final MessageType msgType,
47+
final Logger logger) {
4048
StringBuilder buf = new StringBuilder(64);
4149
buf.append(context);
4250
buf.append(": ");
@@ -53,15 +61,12 @@ public static void logMessage(
5361
logger.error(logMsg);
5462
break;
5563
default:
56-
logger.warn(
57-
"Unknown message type enum \"{}\" for message: {}", msgType, logMsg);
64+
logger.warn("Unknown message type enum \"{}\" for message: {}", msgType, logMsg);
5865
}
5966
}
6067

61-
enum MsgType {
62-
INFO,
63-
WARN,
64-
ERROR
68+
enum MessageType {
69+
INFO, WARN, ERROR
6570
}
6671

6772
public static final int DEFAULT_MSG_LIMIT = 10;
@@ -88,7 +93,7 @@ protected AbstractRecorder(final int errorMsgLimit) {
8893
* Resets this MessageRecorder.
8994
*/
9095
@Override
91-
public void clear() {
96+
public void clear() {
9297
errorMsgCount = 0;
9398
warningMsgCount = 0;
9499
infoMsgCount = 0;
@@ -98,27 +103,27 @@ public void clear() {
98103
}
99104

100105
@Override
101-
public long getStartTimeMillis() {
106+
public long getStartTimeMillis() {
102107
return this.startTime;
103108
}
104109

105110
@Override
106-
public long getRunTimeMillis() {
111+
public long getRunTimeMillis() {
107112
return (System.currentTimeMillis() - this.startTime);
108113
}
109114

110115
@Override
111-
public boolean hasInformation() {
116+
public boolean hasInformation() {
112117
return (infoMsgCount > 0);
113118
}
114119

115120
@Override
116-
public boolean hasWarnings() {
121+
public boolean hasWarnings() {
117122
return (warningMsgCount > 0);
118123
}
119124

120125
@Override
121-
public boolean hasErrors() {
126+
public boolean hasErrors() {
122127
return (errorMsgCount > 0);
123128
}
124129

@@ -135,7 +140,7 @@ public int getErrorCount() {
135140
}
136141

137142
@Override
138-
public String getContext() {
143+
public String getContext() {
139144
// heavy weight
140145
if (contextMsgCache == null) {
141146
final StringBuilder buf = new StringBuilder();
@@ -152,100 +157,83 @@ public String getContext() {
152157
}
153158

154159
@Override
155-
public void pushContextName(final String name) {
160+
public void pushContextName(final String name) {
156161
// light weight
157162
contexts.add(name);
158163
contextMsgCache = null;
159164
}
160165

161166
@Override
162-
public void popContextName() {
167+
public void popContextName() {
163168
// light weight
164169
contexts.remove(contexts.size() - 1);
165170
contextMsgCache = null;
166171
}
167172

168173
@Override
169-
public void throwRTException() throws RecorderException {
174+
public void throwRTException() throws RecorderException {
170175
if (hasErrors()) {
171-
final String errorMsg =
172-
MessageFormat.format(forceMessageRecorderError,
173-
getContext(),
174-
errorMsgCount);
176+
final String errorMsg = MessageFormat.format(forceMessageRecorderError, getContext(), errorMsgCount);
175177
throw new RecorderException(errorMsg);
176178
}
177179
}
178180

179181
@Override
180-
public void reportError(final Exception ex)
181-
throws RecorderException
182-
{
182+
public void reportError(final Exception ex) throws RecorderException {
183183
reportError(ex, null);
184184
}
185185

186186
@Override
187-
public void reportError(final Exception ex, final Object info)
188-
throws RecorderException
189-
{
187+
public void reportError(final Exception ex, final Object info) throws RecorderException {
190188
reportError(ex.toString(), info);
191189
}
192190

193191
@Override
194-
public void reportError(final String msg)
195-
throws RecorderException
196-
{
192+
public void reportError(final String msg) throws RecorderException {
197193
reportError(msg, null);
198194
}
199195

200196
@Override
201-
public void reportError(final String msg, final Object info)
202-
throws RecorderException
203-
{
197+
public void reportError(final String msg, final Object info) throws RecorderException {
204198
errorMsgCount++;
205-
recordMessage(msg, info, MsgType.ERROR);
199+
recordMessage(msg, info, MessageType.ERROR);
206200

207201
if (errorMsgCount >= errorMsgLimit) {
208-
final String errorMsg =
209-
MessageFormat.format(tooManyMessageRecorderErrors,
210-
getContext(),
202+
final String errorMsg = MessageFormat.format(tooManyMessageRecorderErrors, getContext(),
211203
String.valueOf(errorMsgCount));
212204
throw new RecorderException(errorMsg);
213205
}
214206
}
215207

216208
@Override
217-
public void reportWarning(final String msg) {
209+
public void reportWarning(final String msg) {
218210
reportWarning(msg, null);
219211
}
220212

221213
@Override
222-
public void reportWarning(final String msg, final Object info) {
214+
public void reportWarning(final String msg, final Object info) {
223215
warningMsgCount++;
224-
recordMessage(msg, info, MsgType.WARN);
216+
recordMessage(msg, info, MessageType.WARN);
225217
}
226218

227219
@Override
228-
public void reportInfo(final String msg) {
220+
public void reportInfo(final String msg) {
229221
reportInfo(msg, null);
230222
}
231223

232224
@Override
233-
public void reportInfo(final String msg, final Object info) {
225+
public void reportInfo(final String msg, final Object info) {
234226
infoMsgCount++;
235-
recordMessage(msg, info, MsgType.INFO);
227+
recordMessage(msg, info, MessageType.INFO);
236228
}
237229

238230
/**
239-
* Handles a message.
240-
* Classes implementing this abstract class must provide an implemention
241-
* of this method; it receives all warning/error messages.
231+
* Handles a message. Classes implementing this abstract class must provide an
232+
* implemention of this method; it receives all warning/error messages.
242233
*
243-
* @param msg the error or warning message.
244-
* @param info the information Object which might be null.
234+
* @param msg the error or warning message.
235+
* @param info the information Object which might be null.
245236
* @param msgType one of the message type enum values
246237
*/
247-
protected abstract void recordMessage(
248-
String msg,
249-
Object info,
250-
MsgType msgType);
238+
protected abstract void recordMessage(String msg, Object info, MessageType msgType);
251239
}
Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
/*
2-
// This software is subject to the terms of the Eclipse Public License v1.0
3-
// Agreement, available at the following URL:
4-
// http://www.eclipse.org/legal/epl-v10.html.
5-
// You must accept the terms of that agreement to use this software.
6-
//
7-
// Copyright (C) 2005-2005 Julian Hyde
8-
// Copyright (C) 2005-2017 Hitachi Vantara and others
9-
// All Rights Reserved.
10-
*/
2+
* This software is subject to the terms of the Eclipse Public License v1.0
3+
* Agreement, available at the following URL:
4+
* http://www.eclipse.org/legal/epl-v10.html.
5+
* You must accept the terms of that agreement to use this software.
6+
*
7+
* Copyright (C) 2005-2005 Julian Hyde
8+
* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved.
9+
*
10+
* ---- All changes after Fork in 2023 ------------------------
11+
*
12+
* Project: Eclipse daanse
13+
*
14+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
15+
*
16+
* This program and the accompanying materials are made
17+
* available under the terms of the Eclipse Public License 2.0
18+
* which is available at https://www.eclipse.org/legal/epl-2.0/
19+
*
20+
* SPDX-License-Identifier: EPL-2.0
21+
*
22+
* Contributors after Fork in 2023:
23+
* SmartCity Jena - initial
24+
*/
1125

1226
package mondrian.recorder;
1327

@@ -18,9 +32,9 @@
1832
import org.slf4j.Logger;
1933

2034
/**
21-
* Implementation of {@link MessageRecorder} that records each message
22-
* in a {@link List}. The calling code can then access the list and take
23-
* actions as needed.
35+
* Implementation of {@link MessageRecorder} that records each message in a
36+
* {@link List}. The calling code can then access the list and take actions as
37+
* needed.
2438
*/
2539
public class ListRecorder extends AbstractRecorder {
2640

@@ -35,7 +49,7 @@ public ListRecorder() {
3549
}
3650

3751
@Override
38-
public void clear() {
52+
public void clear() {
3953
super.clear();
4054
errorList.clear();
4155
warnList.clear();
@@ -55,11 +69,7 @@ public Iterator<Entry> getInfoEntries() {
5569
}
5670

5771
@Override
58-
protected void recordMessage(
59-
final String msg,
60-
final Object info,
61-
final MsgType msgType)
62-
{
72+
protected void recordMessage(final String msg, final Object info, final MessageType msgType) {
6373
String context = getContext();
6474

6575
Entry e = new Entry(context, msg, msgType, info);
@@ -74,12 +84,8 @@ protected void recordMessage(
7484
errorList.add(e);
7585
break;
7686
default:
77-
e = new Entry(
78-
context,
79-
new StringBuilder("Unknown message type enum \"").append(msgType)
80-
.append("\" for message: ").append(msg).toString(),
81-
MsgType.WARN,
82-
info);
87+
e = new Entry(context, new StringBuilder("Unknown message type enum \"").append(msgType)
88+
.append("\" for message: ").append(msg).toString(), MessageType.WARN, info);
8389
warnList.add(e);
8490
}
8591
}
@@ -109,49 +115,15 @@ static void logMessage(Iterator<Entry> it, Logger logger) {
109115
}
110116
}
111117

112-
static void logMessage(
113-
final Entry e,
114-
final Logger logger)
115-
{
116-
logMessage(e.getContext(), e.getMessage(), e.getMsgType(), logger);
118+
static void logMessage(final Entry e, final Logger logger) {
119+
logMessage(e.context(), e.message(), e.msgType(), logger);
117120
}
118121

119122
/**
120-
* Entry is a Info, Warning or Error message. This is the object stored
121-
* in the Lists MessageRecorder's info, warning and error message lists.
123+
* Entry is a Info, Warning or Error message. This is the object stored in the
124+
* Lists MessageRecorder's info, warning and error message lists.
122125
*/
123-
public static class Entry {
124-
private final String context;
125-
private final String msg;
126-
private final MsgType msgType;
127-
private final Object info;
128-
129-
private Entry(
130-
final String context,
131-
final String msg,
132-
final MsgType msgType,
133-
final Object info)
134-
{
135-
this.context = context;
136-
this.msg = msg;
137-
this.msgType = msgType;
138-
this.info = info;
139-
}
126+
public static record Entry(String context, String message, MessageType msgType, Object info) {
140127

141-
public String getContext() {
142-
return context;
143-
}
144-
145-
public String getMessage() {
146-
return msg;
147-
}
148-
149-
public MsgType getMsgType() {
150-
return msgType;
151-
}
152-
153-
public Object getInfo() {
154-
return info;
155-
}
156128
}
157129
}

0 commit comments

Comments
 (0)