Skip to content

Commit

Permalink
Merge branch 'release/0.9.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
mostroverkhov committed Sep 14, 2019
2 parents 34653b4 + 909e365 commit a7616f0
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 106 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ It enables following symmetric interaction models:
* channel (bi-directional streams)
* per-stream and per-RSocket metadata

#### RPC style interactions support is provided by [RSOCKET RPC - KOTLIN](https://github.com/rsocket/rsocket-rpc-kotlin)

## Build and Binaries

```groovy
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ subprojects {
api 'io.netty:netty-buffer'
api 'io.reactivex.rxjava2:rxjava'
api 'org.jetbrains.kotlin:kotlin-stdlib-jdk7'
api 'org.slf4j:slf4j-api'

compileOnly 'com.google.code.findbugs:jsr305'

testImplementation 'org.slf4j:slf4j-api'
testImplementation 'junit:junit'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.hamcrest:hamcrest-library'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

group=io.rsocket.kotlin
version=0.9.7
version=0.9.8

buildScanPluginVersion=2.4.1
dependencyManagementPluginVersion=1.0.8.RELEASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50
org.jetbrains.kotlin:kotlin-stdlib:1.3.50
org.jetbrains:annotations:13.0
org.reactivestreams:reactive-streams:1.0.2
org.slf4j:slf4j-api:1.7.28
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.reactivex.processors.UnicastProcessor
import io.rsocket.kotlin.*
import io.rsocket.kotlin.exceptions.ApplicationException
import io.rsocket.kotlin.exceptions.ChannelRequestException
import io.rsocket.kotlin.internal.util.reactiveStreamsRequestN
import org.reactivestreams.Publisher
import org.reactivestreams.Subscriber
import org.reactivestreams.Subscription
Expand Down Expand Up @@ -121,10 +122,11 @@ internal class RSocketRequester(
val streamId = streamIds.nextStreamId(receivers)
val receiver = StreamReceiver.create()
receivers[streamId] = receiver
val reqN = Cond()
var isFirstRequestN = true

receiver.doOnRequestIfActive { requestN ->
val frame = if (reqN.first()) {
val frame = if (isFirstRequestN) {
isFirstRequestN = false
Frame.Request.from(
streamId,
FrameType.REQUEST_STREAM,
Expand All @@ -148,35 +150,37 @@ internal class RSocketRequester(
return Flowable.defer {
val receiver = StreamReceiver.create()
val streamId = streamIds.nextStreamId(receivers)
val reqN = Cond()
var firstReqN = true
var firstReqPayload = true

receiver.doOnRequestIfActive { requestN ->

if (reqN.first()) {
val wrappedRequest = request.compose {
val sender = RequestingPublisher.wrap(it)
sender.request(1)
senders[streamId] = sender
receivers[streamId] = receiver
sender
}.publish().autoConnect(2)
if (firstReqN) {
firstReqN = false

val first = wrappedRequest.take(1)
.map { payload ->
Frame.Request.from(
streamId,
FrameType.REQUEST_CHANNEL,
payload,
requestN)
val requestFrames = request
.compose {
val sender = RequestingPublisher.wrap(it)
sender.request(1)
senders[streamId] = sender
receivers[streamId] = receiver
sender
}
val rest = wrappedRequest.skip(1)
.map { payload ->
Frame.PayloadFrame.from(
streamId,
FrameType.NEXT,
payload)
if (firstReqPayload) {
firstReqPayload = false
Frame.Request.from(
streamId,
FrameType.REQUEST_CHANNEL,
payload,
requestN)
} else {
Frame.PayloadFrame.from(
streamId,
FrameType.NEXT,
payload)
}
}
val requestFrames = Flowable.concatArrayEager(first, rest)
requestFrames.subscribe(
ChannelRequestSubscriber(
{ payload -> frameSender.send(payload) },
Expand Down Expand Up @@ -248,10 +252,7 @@ internal class RSocketRequester(
FrameType.NEXT -> receiver.onNext(DefaultPayload(frame))
FrameType.REQUEST_N -> {
val sender = senders[streamId]
sender?.let {
val n = Frame.RequestN.requestN(frame).toLong()
it.request(n)
}
sender?.request(reactiveStreamsRequestN(Frame.RequestN.requestN(frame)))
}
FrameType.COMPLETE -> {
receiver.onComplete()
Expand Down Expand Up @@ -320,18 +321,6 @@ internal class RSocketRequester(
}
}

private class Cond {
private var first = true

fun first(): Boolean =
if (first) {
first = false
true
} else {
false
}
}

private class ChannelRequestSubscriber(private val next: (Frame) -> Unit,
private val error: (Throwable) -> Unit,
private val complete: (Boolean) -> Unit)
Expand Down
Loading

0 comments on commit a7616f0

Please sign in to comment.