-
Notifications
You must be signed in to change notification settings - Fork 20
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
Framework-less, generalized, annotation-based RPC #57
Changes from all commits
232ddff
185195d
a3b8418
1f7fd1c
fd0f2f4
e2c358e
aa17fc0
3793232
a905611
5720e63
ab3df30
f77610d
1034c03
1e222e1
16af0a3
f7a1db5
6077ebf
9e6901a
5021726
d2f48ac
ee288b3
2269f55
6c317ad
6f63589
bfd2c1d
e3686a6
e69153b
7f07abe
bd362e6
30834e5
4979225
8566a5e
4e388f2
ecd4da2
9deaa76
38d52b1
e9f6fdb
ac03a81
b330faa
a8573d8
69baa34
37fc886
b48230d
a9bc652
2269a96
dcd58af
f98f72a
899a5ff
2b65b11
7d465a3
51ff4e2
6a43f49
b7e4215
8dc6510
4f9642b
ba2123c
3620fd0
15ccd49
eb6d656
dd0a515
ee8e578
675cf21
eb9f678
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
package com.avsystem.commons | ||
package rpc.akka | ||
|
||
import com.avsystem.commons.rpc.RPCFramework | ||
import com.avsystem.commons.rpc._ | ||
import monix.reactive.Observable | ||
|
||
trait MonixRPCFramework extends RPCFramework { | ||
override type RawRPC <: MonixRawRPC | ||
|
||
trait MonixRawRPC {this: RawRPC => | ||
def observe(rpcName: String, argLists: List[List[RawValue]]): Observable[RawValue] | ||
trait MonixRawRPC { this: RawRPC => | ||
@multi def observe(rpcName: String)(@multi args: List[RawValue]): Observable[RawValue] | ||
} | ||
|
||
implicit def ObservableRealHandler[A: Writer]: RealInvocationHandler[Observable[A], Observable[RawValue]] = | ||
RealInvocationHandler[Observable[A], Observable[RawValue]](_.map(write[A])) | ||
|
||
implicit def ObservableRawHandler[A: Reader]: RawInvocationHandler[Observable[A]] = | ||
RawInvocationHandler[Observable[A]]((rawRpc, rpcName, argLists) => rawRpc.observe(rpcName, argLists).map(read[A])) | ||
implicit def readerBasedObservableAsReal[T: Reader]: AsReal[Observable[RawValue], Observable[T]] = | ||
AsReal.create(_.map(read[T])) | ||
implicit def writerBasedObservableAsRaw[T: Writer]: AsRaw[Observable[RawValue], Observable[T]] = | ||
AsRaw.create(_.map(write[T])) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
package com.avsystem.commons | ||
package rpc.akka | ||
|
||
import com.avsystem.commons.rpc.RPC | ||
import com.avsystem.commons.rpc.akka.AkkaRPCFramework._ | ||
import monix.reactive.Observable | ||
|
||
|
||
/** | ||
* @author Wojciech Milewski | ||
*/ | ||
@RPC | ||
trait TestRPC { | ||
def fireAndForget(): Unit | ||
def echoAsString(int: Int): Future[String] | ||
def stream: Observable[Int] | ||
def inner: InnerRPC | ||
} | ||
object TestRPC { | ||
implicit val fullRPCInfo: BaseFullRPCInfo[TestRPC] = materializeFullInfo | ||
} | ||
object TestRPC extends RPCCompanion[TestRPC] | ||
|
||
@RPC | ||
trait InnerRPC { | ||
def innerFire(): Unit | ||
} | ||
object InnerRPC { | ||
implicit val fullRPCInfo: BaseFullRPCInfo[InnerRPC] = materializeFullInfo | ||
} | ||
object InnerRPC extends RPCCompanion[InnerRPC] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,47 @@ package annotation | |
import scala.annotation.StaticAnnotation | ||
|
||
/** | ||
* When an annotation class extends this trait, annotation processing macros (e.g. for `GenCodec` materialization) | ||
* will look into annotations of the aggregating annotation itself and apply these annotations as if they were | ||
* applied directly on the same target as the aggregating annotation. Example: | ||
* Base trait for annotations which aggregate multiple other annotations. This way annotation aggregates | ||
* work like "annotation functions" - they are annotations that yield more annotations. | ||
* | ||
* In order to specify aggregated annotations, the class that extends `AnnotationAggregate` must | ||
* redefine the `Implied` dummy type member and apply the aggregated annotations on it. Macro engines | ||
* used in `GenCodec` materialization and RPC framework will automatically pick up these annotations. | ||
* | ||
* {{{ | ||
* import com.avsystem.commons.serialization._ | ||
* | ||
* @name("_id") @outOfOrder | ||
* class mongoId extends AnnotationAggregate | ||
* class mongoId extends AnnotationAggregate { | ||
* @name("_id") @outOfOrder | ||
* type Implied | ||
* } | ||
* | ||
* case class SomeMongoEntity(@mongoId id: String, data: String) | ||
* }}} | ||
* | ||
* In the above example, applying `@mongoId` annotation on the `id` field has the same effect as if | ||
* annotations `@name("_id") @outOfOrder` were applied directly on that field. | ||
* | ||
* NOTE: thanks to the fact that aggregated annotations are applied on a type member | ||
* you can pass the arguments of original annotation to aggregated annotations, e.g. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I need to know why when I ctrl+q for a quick overview? The type member note should be a comment on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IntelliJ cannot into Scaladoc. Among other problems, it removes annotations from code snippets, like in this case. I'm not going to work around it. Just read the sources or API reference. |
||
* | ||
* {{{ | ||
* class rpcNameAndDescription(name: String, description: String) extends AnnotationAggregate { | ||
* @rpcName(name) // passing `name` to aggregated annotation | ||
* type Implied | ||
* } | ||
* }}} | ||
*/ | ||
trait AnnotationAggregate extends StaticAnnotation | ||
trait AnnotationAggregate extends StaticAnnotation { | ||
/** | ||
* Dummy type member meant to be redefined in order to have aggregated annotations applied on it. | ||
* These annotations will be automatically picked up by macro engines each time they encounter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Macro engines or our macros? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely not all macro engines in the world. |
||
* the aggregating annotation itself. | ||
* Other than being an "anchor" for annotations, this type member has no actual meaning and there is no | ||
* reason to ever actually use it. | ||
* NOTE: a less weird solution would be to put aggregated annotations on the | ||
* aggregating annotation class itself, but this would make it impossible to access the arguments | ||
* of aggregating annotation in aggregated annotations. | ||
*/ | ||
type Implied | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we start with the fact that other macros won't, or move this to a more GenCodec-specific package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Annotation processing is a part of
MacroCommons
and it should work everywhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-AVSystem macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I specifically listed
GenCodec
macros and RPC macros - what's the problem?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must have misread something 😢