commit
e00bfcf21d
|
@ -14,17 +14,17 @@ public class ChannelClient {
|
|||
|
||||
public ChannelClient() {
|
||||
this.socket = RSocketFactory.connect()
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
|
||||
this.gameController = new GameController("Client Player");
|
||||
}
|
||||
|
||||
public void playGame() {
|
||||
socket.requestChannel(Flux.from(gameController))
|
||||
.doOnNext(gameController::processPayload)
|
||||
.blockLast();
|
||||
.doOnNext(gameController::processPayload)
|
||||
.blockLast();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
|
|
@ -25,9 +25,9 @@ public class FireNForgetClient {
|
|||
|
||||
public FireNForgetClient() {
|
||||
this.socket = RSocketFactory.connect()
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
this.data = Collections.unmodifiableList(generateData());
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,11 @@ public class FireNForgetClient {
|
|||
*/
|
||||
public void sendData() {
|
||||
Flux.interval(Duration.ofMillis(50))
|
||||
.take(data.size())
|
||||
.map(this::createFloatPayload)
|
||||
.map(socket::fireAndForget)
|
||||
.flatMap(Function.identity())
|
||||
.blockLast();
|
||||
.take(data.size())
|
||||
.map(this::createFloatPayload)
|
||||
.map(socket::fireAndForget)
|
||||
.flatMap(Function.identity())
|
||||
.blockLast();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,17 +13,17 @@ public class ReqResClient {
|
|||
|
||||
public ReqResClient() {
|
||||
this.socket = RSocketFactory.connect()
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
}
|
||||
|
||||
public String callBlocking(String string) {
|
||||
return socket
|
||||
.requestResponse(DefaultPayload.create(string))
|
||||
.map(Payload::getDataUtf8)
|
||||
.onErrorReturn(ERROR_MSG)
|
||||
.block();
|
||||
.requestResponse(DefaultPayload.create(string))
|
||||
.map(Payload::getDataUtf8)
|
||||
.onErrorReturn(ERROR_MSG)
|
||||
.block();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
|
|
@ -14,17 +14,17 @@ public class ReqStreamClient {
|
|||
|
||||
public ReqStreamClient() {
|
||||
this.socket = RSocketFactory.connect()
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
.transport(TcpClientTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.block();
|
||||
}
|
||||
|
||||
public Flux<Float> getDataStream() {
|
||||
return socket
|
||||
.requestStream(DefaultPayload.create(WIND_DATA_STREAM_NAME))
|
||||
.map(Payload::getData)
|
||||
.map(buf -> buf.getFloat())
|
||||
.onErrorReturn(null);
|
||||
.requestStream(DefaultPayload.create(WIND_DATA_STREAM_NAME))
|
||||
.map(Payload::getData)
|
||||
.map(buf -> buf.getFloat())
|
||||
.onErrorReturn(null);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
|
|
@ -24,11 +24,11 @@ public class Server {
|
|||
|
||||
public Server() {
|
||||
this.server = RSocketFactory.receive()
|
||||
.acceptor((setupPayload, reactiveSocket) -> Mono.just(new RSocketImpl()))
|
||||
.transport(TcpServerTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.doOnNext(x -> LOG.info("Server started"))
|
||||
.subscribe();
|
||||
.acceptor((setupPayload, reactiveSocket) -> Mono.just(new RSocketImpl()))
|
||||
.transport(TcpServerTransport.create("localhost", TCP_PORT))
|
||||
.start()
|
||||
.doOnNext(x -> LOG.info("Server started"))
|
||||
.subscribe();
|
||||
|
||||
this.gameController = new GameController("Server Player");
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class Server {
|
|||
@Override
|
||||
public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
|
||||
Flux.from(payloads)
|
||||
.subscribe(gameController::processPayload);
|
||||
.subscribe(gameController::processPayload);
|
||||
Flux<Payload> channel = Flux.from(gameController);
|
||||
return channel;
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ public class GameController implements Publisher<Payload> {
|
|||
*/
|
||||
private List<Long> generateShotList() {
|
||||
return Flux.range(1, SHOT_COUNT)
|
||||
.map(x -> (long) Math.ceil(Math.random() * 1000))
|
||||
.collectList()
|
||||
.block();
|
||||
.map(x -> (long) Math.ceil(Math.random() * 1000))
|
||||
.collectList()
|
||||
.block();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue