@@ -132,11 +132,13 @@ abstract class DebugEventSubscriber(vararg val events: String) {
132
132
/* * Object to dispatch debug events */
133
133
object DebugEventDispatcher {
134
134
135
- val _enabled : AtomicBoolean = AtomicBoolean (false )
135
+ val enabledRef: AtomicBoolean = AtomicBoolean (false )
136
+
137
+ @JvmStatic
136
138
var enabled: Boolean
137
- get() = _enabled .get()
139
+ get() = enabledRef .get()
138
140
set(value) {
139
- _enabled .set(value)
141
+ enabledRef .set(value)
140
142
}
141
143
142
144
private val minLogLevelRef = AtomicReference (LogLevel .DEBUG )
@@ -148,22 +150,22 @@ object DebugEventDispatcher {
148
150
minLogLevelRef.set(value)
149
151
}
150
152
151
- private val _mutableSubscribers : MutableSet <DebugEventSubscriber > = mutableSetOf ()
153
+ private val mutableSubscribers : MutableSet <DebugEventSubscriber > = mutableSetOf ()
152
154
153
155
val subscribers: Set <DebugEventSubscriber >
154
- @Synchronized get() = _mutableSubscribers
156
+ @Synchronized get() = mutableSubscribers
155
157
156
158
@JvmStatic
157
159
inline fun dispatch (
158
160
type : String ,
159
161
renderStateId : String ,
160
162
timestamp : Long = System .currentTimeMillis(), // for calender time
161
163
logLevel : LogLevel = LogLevel .DEBUG ,
162
- attributesFiller : AttributesFiller = AttributesFiller {},
164
+ attributesAccumulator : AttributesAccumulator = AttributesAccumulator {},
163
165
) {
164
166
if (enabled && logLevel >= this .minLogLevel) {
165
167
val attributes = LinkedHashMap <String , Any ?>()
166
- attributesFiller.fillAttributes (attributes)
168
+ attributesAccumulator.accumulate (attributes)
167
169
168
170
val event =
169
171
DebugMarkerEvent (
@@ -185,13 +187,13 @@ object DebugEventDispatcher {
185
187
inline fun dispatch (
186
188
type : String ,
187
189
renderStateId : String ,
188
- attributesFiller : AttributesFiller = AttributesFiller {}
190
+ attributesAccumulator : AttributesAccumulator = AttributesAccumulator {}
189
191
) {
190
192
dispatch(
191
193
type = type,
192
194
renderStateId = renderStateId,
193
195
timestamp = System .currentTimeMillis(), // for calender time
194
- attributesFiller = attributesFiller ,
196
+ attributesAccumulator = attributesAccumulator ,
195
197
)
196
198
}
197
199
@@ -200,22 +202,22 @@ object DebugEventDispatcher {
200
202
type : String ,
201
203
renderStateId : String ,
202
204
logLevel : LogLevel = LogLevel .DEBUG ,
203
- attributesFiller : AttributesFiller = AttributesFiller {},
205
+ attributesAccumulator : AttributesAccumulator = AttributesAccumulator {},
204
206
) {
205
207
dispatch(
206
208
type = type,
207
209
renderStateId = renderStateId,
208
210
timestamp = System .currentTimeMillis(), // for calender time
209
211
logLevel = logLevel,
210
- attributesFiller = attributesFiller ,
212
+ attributesAccumulator = attributesAccumulator ,
211
213
)
212
214
}
213
215
214
216
@JvmStatic
215
217
inline fun <T > trace (
216
218
type : String ,
217
219
renderStateId : String ,
218
- attributesFiller : AttributesFiller = AttributesFiller {},
220
+ attributesAccumulator : AttributesAccumulator = AttributesAccumulator {},
219
221
block : (TraceScope ? ) -> T ,
220
222
): T {
221
223
@@ -236,7 +238,7 @@ object DebugEventDispatcher {
236
238
}
237
239
238
240
val attributes = LinkedHashMap <String , Any ?>()
239
- attributesFiller.fillAttributes (attributes)
241
+ attributesAccumulator.accumulate (attributes)
240
242
241
243
val startTime = System .nanoTime()
242
244
val res = block(TraceScope (attributes = attributes))
@@ -257,17 +259,17 @@ object DebugEventDispatcher {
257
259
258
260
@Synchronized
259
261
fun subscribe (subscriber : DebugEventSubscriber ) {
260
- _mutableSubscribers .add(subscriber)
262
+ mutableSubscribers .add(subscriber)
261
263
}
262
264
263
265
@Synchronized
264
266
internal fun unsubscribe (subscriber : DebugEventSubscriber ) {
265
- _mutableSubscribers .remove(subscriber)
267
+ mutableSubscribers .remove(subscriber)
266
268
}
267
269
268
270
@Synchronized
269
271
fun unsubscribeAll () {
270
- _mutableSubscribers .clear()
272
+ mutableSubscribers .clear()
271
273
}
272
274
273
275
class TraceScope (private val attributes : LinkedHashMap <String , Any ?>) {
@@ -313,15 +315,12 @@ object DebugEventBus {
313
315
}
314
316
315
317
/* *
316
- * This consumer interface is used so that clients can fill the [DebugEvent] attributes map in a
317
- * cleaner way in both Java and Kotlin.
318
- *
319
- * By doing this (and not use a lambda directly), we can guarantee that Java clients are not forced
320
- * to return `Unit.INSTANCE` or `null`.
318
+ * This accumulator interface is invoked to get attributes of a [DebugEvent]. Using this interface
319
+ * improve ergonomics in Java; i.e. not return `Unit.INSTANCE` or `null`.
321
320
*/
322
- fun interface AttributesFiller {
321
+ fun interface AttributesAccumulator {
323
322
324
- fun fillAttributes (map : MutableMap <String , Any ?>)
323
+ fun accumulate (map : MutableMap <String , Any ?>)
325
324
}
326
325
327
326
@JvmInline
0 commit comments