-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of kotlin version with service proxy #28
Comments
I ran into the same issue when experimenting with service proxies. A possible workaround: @ProxyGen
@VertxGen
interface MyService {
fun myMethod(param: String)
}
object MyServiceFactory {
fun create(vertx: Vertx): MyService{
return MyServiceImpl(vertx)
}
fun createProxy(vertx: Vertx, address: String, options: DeliveryOptions = DeliveryOptions()): MyService {
return MyServiceVertxEBProxy(vertx, address, options)
}
} |
Is it also possible to generate the rx version of the proxy? |
I have the same problem on rx version of the service proxy.. |
I also get the same problem, and then based on @abelhegedus' idea, here my workaround: @ProxyGen
interface WikiDatabaseService {
@Fluent
fun fetchAllPages(resultHandler: Handler<AsyncResult<JsonArray>>): WikiDatabaseService
@Fluent
fun fetchPage(name: String, resultHandler: Handler<AsyncResult<JsonObject>>): WikiDatabaseService
@Fluent
fun createPage(title: String, markdown: String, resultHandler: Handler<AsyncResult<Void>>): WikiDatabaseService
@Fluent
fun savePage(id: Int, markdown: String, resultHandler: Handler<AsyncResult<Void>>): WikiDatabaseService
@Fluent
fun deletePage(id: Int, resultHandler: Handler<AsyncResult<Void>>): WikiDatabaseService
@GenIgnore
companion object {
fun create(dbClient: JDBCClient, sqlQueries: Map<SqlQuery, String>,
readyHandler: Handler<AsyncResult<WikiDatabaseService>>): WikiDatabaseService =
WikiDatabaseServiceImpl(dbClient, sqlQueries, readyHandler)
fun createProxy(vertx: Vertx, address: String): WikiDatabaseService =
WikiDatabaseServiceVertxEBProxy(vertx, address)
}
} I added |
@desmondtzq @mustafakibar To my knowledge there is no way to do this in 1.2.x as interfaces are not allowed to have However, support for this is added in 1.3 (https://youtrack.jetbrains.com/issue/KT-6301) meaning that the following should work:
(You can actually use this feature now, as per Michael Bogdanov's comment, though since it's pre-release it's technically not stable.) |
@rgmz , I've tried adding @JvmStatic like you did on Kotlin 1.3.21n and I still have this error ".Companion is not legal for use for a constant type in code generation" Any other workarounds that you might suggest? |
@raghumulukutla A change introduced in Vert.x 3.6.x inadvertently broke this. I created a pull request to fix this—hopefully it makes it into the next release, or a viable workaround is provided. @gmariotti do you have any suggested workarounds to mimic this behaviour? |
@gmariotti @rgmz Thanks! I've also tried using a Vertx version < 3.6.x. Reproduces the same error. |
@raghumulukutla Can you provide a reproducer? I do not get the error in version 3.5.4. Try this ad-hoc example: https://github.com/rgmz/vertx-kotlin-service-proxy |
@rgmz I'm sorry, I should correct myself. I do not get the same error. But I do get a kaptKotlin error. Here's the reproducer: WikiDatabaseService.kt
Error:
|
just use java interface in kotlin project |
Is extension function a possible workaround? So that we won't need to setup companion object
|
Unfortunately Kotlin does not support static extension functions; in order to call Additionally, non-static methods are not picked up by codegen so you would need to manually define factory methods for everything, e.g. the rxified API. |
FYI, once Vert.x 4.1.0 is released this issue should be resolved.
4.1.0 isn't released yet, but this is now updated to 4.1.0.CR2. |
Hi, can anybody provide kotlin version of this tutorial with service proxies? I couldn't manage it to work;
Every time I get such error on build:
Here is my interface:
And, added kapt plugin to build.gradle:
The text was updated successfully, but these errors were encountered: