Skip to content

Commit 803363b

Browse files
committed
refactor: add applied/added instrument event models
1 parent 8fc3dd3 commit 803363b

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2023 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.protocol.instrument.event
18+
19+
import io.vertx.codegen.annotations.DataObject
20+
import io.vertx.core.json.JsonObject
21+
import spp.protocol.instrument.LiveInstrument
22+
import spp.protocol.instrument.LiveInstrumentType
23+
import java.time.Instant
24+
25+
/**
26+
* todo: description.
27+
*
28+
* @since 0.7.7
29+
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
30+
*/
31+
@DataObject
32+
data class LiveInstrumentAdded(
33+
val liveInstrument: LiveInstrument,
34+
override val occurredAt: Instant = Instant.now()
35+
) : TrackedLiveEvent {
36+
override val eventType: LiveInstrumentEventType
37+
get() {
38+
return when (liveInstrument.type) {
39+
LiveInstrumentType.BREAKPOINT -> LiveInstrumentEventType.BREAKPOINT_ADDED
40+
LiveInstrumentType.LOG -> LiveInstrumentEventType.LOG_ADDED
41+
LiveInstrumentType.METER -> LiveInstrumentEventType.METER_ADDED
42+
LiveInstrumentType.SPAN -> LiveInstrumentEventType.SPAN_ADDED
43+
}
44+
}
45+
46+
constructor(json: JsonObject) : this(
47+
liveInstrument = LiveInstrument.fromJson(json.getJsonObject("liveInstrument")),
48+
occurredAt = Instant.parse(json.getString("occurredAt"))
49+
)
50+
51+
fun toJson(): JsonObject {
52+
return JsonObject.mapFrom(this)
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022-2023 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.protocol.instrument.event
18+
19+
import io.vertx.codegen.annotations.DataObject
20+
import io.vertx.core.json.JsonObject
21+
import spp.protocol.instrument.LiveInstrument
22+
import spp.protocol.instrument.LiveInstrumentType
23+
import java.time.Instant
24+
25+
/**
26+
* todo: description.
27+
*
28+
* @since 0.7.7
29+
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
30+
*/
31+
@DataObject
32+
data class LiveInstrumentApplied(
33+
val liveInstrument: LiveInstrument,
34+
override val occurredAt: Instant = Instant.now()
35+
) : TrackedLiveEvent {
36+
override val eventType: LiveInstrumentEventType
37+
get() {
38+
return when (liveInstrument.type) {
39+
LiveInstrumentType.BREAKPOINT -> LiveInstrumentEventType.BREAKPOINT_APPLIED
40+
LiveInstrumentType.LOG -> LiveInstrumentEventType.LOG_APPLIED
41+
LiveInstrumentType.METER -> LiveInstrumentEventType.METER_APPLIED
42+
LiveInstrumentType.SPAN -> LiveInstrumentEventType.SPAN_APPLIED
43+
}
44+
}
45+
46+
constructor(json: JsonObject) : this(
47+
liveInstrument = LiveInstrument.fromJson(json.getJsonObject("liveInstrument")),
48+
occurredAt = Instant.parse(json.getString("occurredAt"))
49+
)
50+
51+
fun toJson(): JsonObject {
52+
return JsonObject.mapFrom(this)
53+
}
54+
}

0 commit comments

Comments
 (0)