Md Sadique Inam
02/20/2024, 2:13 AMelonzh
02/23/2024, 4:18 PMRay Rahke
02/25/2024, 7:59 PMRay Rahke
02/25/2024, 8:00 PMAkshay Taru
02/26/2024, 5:33 AMAbhi
02/26/2024, 9:28 AMDaria Voronina [JB]
02/26/2024, 1:32 PMAns Trakhtman
02/27/2024, 1:48 PMAns Trakhtman
02/27/2024, 1:52 PMimport akka.actor.*
import com.typesafe.config.Config
import kotlin.time.Duration.Companion.seconds
class JobsScheduler {
fun run(config: Config) {
val system = ActorSystem.create("jobsScheduler", config)
val job = system.actorOf(Job.props(), "job1")
system.scheduler.scheduleOnce(5.seconds, job, Job.Message("foo")); // this needs some ExecutorContext, which I can't figure out what it is.
}
}
I would greatly appreciate any help to make this dummy example run. Can’t figure out what’s wrong 🤦Hildebrandt Tobias
02/28/2024, 4:49 PMMd Sadique Inam
02/29/2024, 11:22 AMChristopher Hübner
03/04/2024, 8:22 AMLaurent Thiebaud
03/04/2024, 3:13 PMLaurent Thiebaud
03/05/2024, 11:14 AMFred Bowker
03/06/2024, 1:39 PM@Singleton
class PostServiceWeb
@Inject
constructor(
properties: AppProperties,
networkJson: Json,
) : ServiceWeb(
to use a Json that has
Json { encodeDefaults = true }
Basically I want to create a default JSON that has this set then it would be injected across the application, or do people change this at the retrofit level, any help would be appreciatedHildebrandt Tobias
03/07/2024, 11:54 AMCHANGE_PROFILE
and ADD_PROFILE
. The first needs id, from, to
and the latter just needs id, name
.
Somewhere up in the code an Audit(user, auditAction)
is created and passed down.
It eventuelle lands at the point where it should be written to the databse.
So I have imagine something that looks into the `AuditAction`and depending if it's change or add a different function(signature) is presented, they all return a Map<AuditDetail, String>
.
So in pseudo code something like this:
enum class AuditDetail {
ID,
NAME,
FROM,
TO,
}
object AuditPresets {
fun profileChange(id: String, from: String, to: String) = mapOf(
AuditDetail.ID to id,
AuditDetail.FROM to from,
AuditDetail.TO to to,
)
fun profileAdd(id: String, name: String) = mapOf(
AuditDetail.ID to id,
AuditDetail.NAME to name,
)
}
enum class AuditAction(val transformer: ???) {
PROFILE_CHANGE(AuditPresets::profileChange),
PROFILE_ADD(AuditPresets::profileAdd)
}
Now this obviously doesn't work since calling audit.auditAction()
could be any of the AuditAction
and the compiler doesn't know the signature ahead of time.
I just want a way to connect the AuditAction
enum(or sealed class or whatever) to a specific function even when the result is something like:
return when (audit.auditAction) {
AuditAction.PROFILE_CHANGE -> AuditAction.PROFILE_CHANGE("0","oldValue", "newValue")
AuditAction.PROFILE_ADD -> AuditAction.PROFILE_ADD("1","newName")
}
I feel like the solution might be simple and obvious and I just can't see the forest for the trees.Loïc Lamarque
03/08/2024, 1:44 PMNotBlankString
explicit type that you’ve dreamed of. 🙌
What’s more? This type uses kotlinx.serialization for automatic conversion from or as String
. 🤯
Want more? Check Kotools Types on GitHub. 👀Md Sadique Inam
03/15/2024, 1:34 AMKev
03/19/2024, 11:58 AMBharat Kumar
03/20/2024, 6:27 AMAndrea Alberti
03/26/2024, 1:30 PMJohannes Wirde
03/29/2024, 9:34 PMError: Main method not found in class com.example.HelloWorldKt, please define the main method as:
public static void main(String[] args)
which is yucky Java stuff and I'm in Kotlin... Any hints?Spoudel347
04/10/2024, 12:02 PMHildebrandt Tobias
04/11/2024, 8:49 AMfun getDeviceUpdater(id: DeviceId): DeviceUpdater {
if(!deviceMap.containsKey(id))
deviceMap[id] = Device()
return deviceMap[id].toDeviceUpdater()!!
}
I don't want to make the return type nullable.Md Sadique Inam
04/13/2024, 8:12 AMMd Sadique Inam
04/13/2024, 12:58 PMFabio Beoni
04/13/2024, 8:12 PMError running 'jvm in docker' Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused
// build.gradle.kts
//
// I have included:
// "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
// and 5005 port mapping
//
application {
mainClass.set("io.ktor.server.cio.EngineMain")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf(
"-Dio.ktor.development=$isDevelopment",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
)
}
ktor {
docker {
// setup port mapping for the container/service
portMappings.set(listOf(
io.ktor.plugin.features.DockerPortMapping(
outsideDocker = 8080,
insideDocker = 8080,
io.ktor.plugin.features.DockerPortMappingProtocol.TCP
),
io.ktor.plugin.features.DockerPortMapping(
outsideDocker = 5005,
insideDocker = 5005,
io.ktor.plugin.features.DockerPortMappingProtocol.TCP
),
))
}
}
// application.yaml
ktor:
development: true
application:
modules:
- net.beoni.ktorunderalb.ApplicationKt.module
deployment:
port: 8080
autoreload: true
IDEA Run Cofiguration (jvm remote)Fabio Beoni
04/13/2024, 8:13 PMHildebrandt Tobias
04/17/2024, 10:25 AMException during IR lowering
error and am a little bit stumped.
The relevant error part is this I presume:
Caused by: java.lang.RuntimeException: Exception while generating code for:
FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:<redacted>.server.domain.system.events.StreamUpdate.New<T of <redacted>.server.domain.system.events.StreamUpdate.New>, new:T of <redacted>.server.domain.system.events.StreamUpdate.New) returnType:<redacted>.server.domain.system.events.StreamUpdate.New<T of <redacted>.server.domain.system.events.StreamUpdate.New>
$this: VALUE_PARAMETER name:<this> type:<redacted>.server.domain.system.events.StreamUpdate.New<T of <redacted>.server.domain.system.events.StreamUpdate.New>
VALUE_PARAMETER name:new index:0 type:T of <redacted>.server.domain.system.events.StreamUpdate.New
EXPRESSION_BODY
ERROR_EXPR 'Default Stub' type=T of <redacted>.server.domain.system.events.StreamUpdate.New
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (new: T of <redacted>.server.domain.system.events.StreamUpdate.New): <redacted>.server.domain.system.events.StreamUpdate.New<T of <redacted>.server.domain.system.events.StreamUpdate.New> declared in <redacted>.server.domain.system.events.StreamUpdate.New'
CONSTRUCTOR_CALL 'public constructor <init> ($context_receiver_0: <redacted>.server.domain.BaseService<T of <redacted>.server.domain.system.events.StreamUpdate.New>, new: T of <redacted>.server.domain.system.events.StreamUpdate.New) [primary] declared in <redacted>.server.domain.system.events.StreamUpdate.New' type=<redacted>.server.domain.system.events.StreamUpdate.New<T of <redacted>.server.domain.system.events.StreamUpdate.New> origin=null
<class: T>: T of <redacted>.server.domain.system.events.StreamUpdate.New
$context_receiver_0: GET_VAR 'new: T of <redacted>.server.domain.system.events.StreamUpdate.New declared in <redacted>.server.domain.system.events.StreamUpdate.New.copy' type=T of <redacted>.server.domain.system.events.StreamUpdate.New origin=null
Relevant Code:
enum class UpdateType {
NEW,
UPDATE,
MOVE,
REMOVE
}
sealed class StreamUpdate<T: Any>(val type: UpdateType, open val old: T? = null) {
context(BaseService<T>)
data class New<T: Any>(val new: T): StreamUpdate<T>(UpdateType.NEW)
context(BaseService<T>)
data class Update<T: Any>(val new: T, override val old: T? = null): StreamUpdate<T>(UpdateType.UPDATE, old ?: getRepository().getEntity(new))
// data class Move<T: Any>(val old: T, val new: T): MqttUpdate<T>(UpdateType.MOVE) // We might need this later
context(BaseService<T>)
data class Remove<T: Any>(override val old: T): StreamUpdate<T>(UpdateType.REMOVE, old)
}
object EventStream {
val logger = KotlinLogging.logger { }
val triggerMap = mutableMapOf<KType, PublishSubject<StreamUpdate<*>>>()
inline fun <reified T : Any>publish(update: StreamUpdate<T>) =
triggerMap
.getOrPut(typeOf<T>()) { PublishSubject.create() }
.onNext(update)
@Suppress("UNCHECKED_CAST")
inline fun <reified T : Any> subscribe(): Flowable<StreamUpdate<T>> =
triggerMap
.getOrPut(typeOf<T>()) { PublishSubject.create() }
.toFlowable(BackpressureStrategy.LATEST)
.filter {
// We don't need updates without changes.
if(it is StreamUpdate.Update)
it.old != it.new
else
true
}
.map { it as StreamUpdate<T> }
.distinctUntilChanged()
.doOnError { logger.error("StreamUpdate Error on Trigger ${typeOf<T>()}:", it) }
}
Stefan de Kraker
04/18/2024, 11:39 AMrouting {
route("/product") {
get("/all") {
call.respond(
status = HttpStatusCode.OK,
message = service.getAll()
)
}
}
}
class ProductService(private val productRepository: ProductRepository) {
fun getAll(): List<ProductEntity> {
return productRepository.getAll()
}
}
interface ProductRepository {
fun getAll(): List<ProductEntity>
}
class ProductRepositoryImpl : ProductRepository {
private val dotenv = dotenv()
private val database = Database.connect(
url = "jdbc:mysql://${dotenv["DB_HOST"]}:${dotenv["DB_PORT"]}/${dotenv["DB_NAME"]}${dotenv["DB_TYPE"]}",
driver = "com.mysql.jdbc.Driver",
user = dotenv["MYSQL_USER"],
password = dotenv["MYSQL_PASSWORD"]
)
override fun getAll(): List<ProductEntity> {
return emptyList()
}
}
java.lang.NoSuchMethodError: 'java.lang.Object io.ktor.serialization.ContentConverter.serializeNullable(io.ktor.http.ContentType, java.nio.charset.Charset, io.ktor.util.reflect.TypeInfo, java.lang.Object, kotlin.coroutines.Continuation)'