Skip to content

Commit 730e601

Browse files
committed
fixes #24
1 parent bf44329 commit 730e601

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

services/src/main/java/spp/probe/services/instrument/LiveInstrumentService.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import java.lang.instrument.UnmodifiableClassException
2323
import java.util.*
2424
import java.util.concurrent.ConcurrentHashMap
2525
import java.util.function.BiConsumer
26-
import java.util.function.Consumer
2726
import java.util.stream.Collectors
2827

2928
object LiveInstrumentService {
@@ -42,26 +41,21 @@ object LiveInstrumentService {
4241
timer.schedule(object : TimerTask() {
4342
override fun run() {
4443
val removeInstruments: MutableList<ActiveLiveInstrument> = ArrayList()
45-
instruments.values.forEach(Consumer {
44+
instruments.values.forEach {
4645
if (it.instrument.expiresAt != null
4746
&& System.currentTimeMillis() >= it.instrument.expiresAt!!
4847
) {
4948
removeInstruments.add(it)
5049
}
51-
})
52-
applyingInstruments.values.forEach(Consumer {
50+
}
51+
applyingInstruments.values.forEach {
5352
if (it.instrument.expiresAt != null
5453
&& System.currentTimeMillis() >= it.instrument.expiresAt!!
5554
) {
5655
removeInstruments.add(it)
5756
}
58-
})
59-
removeInstruments.forEach(Consumer {
60-
_removeInstrument(
61-
it.instrument,
62-
null
63-
)
64-
})
57+
}
58+
removeInstruments.forEach { _removeInstrument(it.instrument, null) }
6559
}
6660
}, 5000, 5000)
6761
}
@@ -212,6 +206,7 @@ object LiveInstrumentService {
212206
removedInstrument.isRemoval = true
213207
if (removedInstrument.isLive) {
214208
liveInstrumentApplier.apply(instrumentation!!, removedInstrument)
209+
removedInstrument.instrument.id?.let { ContextReceiver.clear(it) }
215210
return listOf(ModelSerializer.INSTANCE.toJson(removedInstrument.instrument))
216211
}
217212
}
@@ -223,6 +218,7 @@ object LiveInstrumentService {
223218
removedInstrument.isRemoval = true
224219
if (removedInstrument.isLive) {
225220
liveInstrumentApplier.apply(instrumentation!!, removedInstrument)
221+
removedInstrument.instrument.id?.let { ContextReceiver.clear(it) }
226222
removedInstruments.add(ModelSerializer.INSTANCE.toJson(removedInstrument.instrument))
227223
}
228224
}
@@ -232,8 +228,8 @@ object LiveInstrumentService {
232228
return emptyList()
233229
}
234230

235-
fun _removeInstrument(instrument: LiveInstrument?, ex: Throwable?) {
236-
removeInstrument(instrument!!.location.source, instrument.location.line, instrument.id)
231+
fun _removeInstrument(instrument: LiveInstrument, ex: Throwable?) {
232+
removeInstrument(instrument.location.source, instrument.location.line, instrument.id)
237233
val map: MutableMap<String, Any?> = HashMap()
238234
when (instrument) {
239235
is LiveBreakpoint -> map["breakpoint"] = ModelSerializer.INSTANCE.toJson(instrument)
@@ -273,7 +269,7 @@ object LiveInstrumentService {
273269
.collect(Collectors.toSet())
274270
instruments.addAll(
275271
applyingInstruments.values.stream()
276-
.filter { it.instrument.location.source == source}
272+
.filter { it.instrument.location.source == source }
277273
.collect(Collectors.toSet()))
278274
return ArrayList(instruments)
279275
}

0 commit comments

Comments
 (0)