Skip to content

Commit

Permalink
Merge pull request #47 from herts-stack/fix-checkbyte
Browse files Browse the repository at this point in the history
Fix to check byte size
  • Loading branch information
tomoyane authored Oct 11, 2023
2 parents bc045f4 + 3b2159a commit d8da293
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import org.hertsstack.core.annotation.HertsRpcService;
import org.hertsstack.core.context.HertsType;
import org.hertsstack.core.service.HertsService;
import org.hertsstack.example.commonmodel.Hoo;

@HertsRpcService(value = HertsType.BidirectionalStreaming)
public interface BidStreamingService extends HertsService {
StreamObserver<String> helloWorld(StreamObserver<String> responseObserver);
StreamObserver<Hoo> hoo(StreamObserver<Hoo> responseObserver);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.grpc.stub.StreamObserver;
import org.hertsstack.core.service.HertsServiceBidirectionalStreaming;
import org.hertsstack.example.commonmodel.Hoo;

public class BidStreamingServiceImpl extends HertsServiceBidirectionalStreaming<BidStreamingService> implements BidStreamingService {
@Override
Expand All @@ -23,4 +24,24 @@ public void onCompleted() {
}
};
}

@Override
public StreamObserver<Hoo> hoo(StreamObserver<Hoo> responseObserver) {
return new StreamObserver<>() {
@Override
public void onNext(Hoo value) {
System.out.println("Received hoo data on server: " + value);
responseObserver.onNext(new Hoo());
}

@Override
public void onError(Throwable t) {
}

@Override
public void onCompleted() {
responseObserver.onCompleted();
}
};
}
}
28 changes: 25 additions & 3 deletions example/src/main/java/org/hertsstack/example/bidsteaming/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hertsstack.example.bidsteaming;

import io.grpc.stub.StreamObserver;
import org.hertsstack.example.commonmodel.Hoo;
import org.hertsstack.rpc.HertsRpcServerEngine;
import org.hertsstack.rpc.HertsRpcServerEngineBuilder;
import org.hertsstack.rpcclient.HertsRpcClient;
Expand All @@ -10,7 +11,7 @@ public class Main {
public static void main(String[] args) throws InterruptedException {
startServer();
startClient();
Thread.sleep(2000);
Thread.sleep(5000);
System.exit(0);
}

Expand All @@ -31,7 +32,7 @@ private static void startClient() {
.connect();

BidStreamingService service = client.createHertsRpcService(BidStreamingService.class);
var res = service.helloWorld(new StreamObserver<String>() {
var res01 = service.helloWorld(new StreamObserver<String>() {
@Override
public void onNext(String value) {
System.out.println("Received data on client: " + value);
Expand All @@ -47,7 +48,28 @@ public void onCompleted() {
});

for (var i = 0;i < 10; i++) {
res.onNext("hello from client " + i);
res01.onNext("hello from client " + i);
}
res01.onCompleted();

var res02 = service.hoo(new StreamObserver<Hoo>() {
@Override
public void onNext(Hoo value) {
System.out.println("Received hoo data on client: " + value);
}

@Override
public void onError(Throwable t) {
}

@Override
public void onCompleted() {
}
});

for (var i = 0;i < 10; i++) {
res02.onNext(new Hoo());
}
res02.onCompleted();
}
}
15 changes: 15 additions & 0 deletions example/src/main/java/org/hertsstack/example/commonmodel/Hoo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.hertsstack.example.commonmodel;

import org.hertsstack.core.modelx.HertsMessage;

public class Hoo extends HertsMessage {
private String hoo;

public String getHoo() {
return hoo;
}

public void setHoo(String hoo) {
this.hoo = hoo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.hertsstack.core.annotation.HertsRpcService;
import org.hertsstack.core.context.HertsType;
import org.hertsstack.core.service.HertsReactiveService;
import org.hertsstack.example.commonmodel.Hoo;

@HertsRpcService(value = HertsType.Reactive)
public interface ReactiveService extends HertsReactiveService {
String helloWorld(String value);
Hoo getHoo();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hertsstack.example.reactivesteaming;

import org.hertsstack.core.service.HertsServiceReactiveStreaming;
import org.hertsstack.example.commonmodel.Hoo;

public class ReactiveServiceImpl extends HertsServiceReactiveStreaming<ReactiveService, ReactiveReceiver> implements ReactiveService {
@Override
Expand All @@ -12,4 +13,9 @@ public String helloWorld(String value) {
}
return "hello";
}

@Override
public Hoo getHoo() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hertsstack.example.reactivesteaming.local;

import org.hertsstack.example.commonmodel.Hoo;
import org.hertsstack.example.reactivesteaming.ReactiveReceiverImpl;
import org.hertsstack.example.reactivesteaming.ReactiveService;
import org.hertsstack.example.reactivesteaming.ReactiveServiceImpl;
Expand Down Expand Up @@ -36,5 +37,8 @@ private static void startClient() {
ReactiveService service = client.createHertsRpcService(ReactiveService.class);
var res = service.helloWorld("hello");
System.out.println("Received data on client: " + res);

Hoo hoo = service.getHoo();
System.out.println(hoo);
}
}
2 changes: 1 addition & 1 deletion herts-rpc-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
apply plugin: 'application'

def pkgName = 'org.hertsstack'
def pkgVersion = '1.1.1'
def pkgVersion = '1.1.2'
def javaVersion = project.hasProperty('javaVersion') ? project.getProperty('javaVersion') : '11'
def artifactId = 'rpc-client'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
if (returnType.getName().equals("void")) {
return null;
}
if (res == null || res.length == 0) {
return null;
}
return this.serializer.deserialize(res, returnType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
if (returnType.getName().equals("void")) {
return null;
}
if (res == null || res.length == 0) {
return null;
}
return this.serializer.deserialize(res, returnType);
}

Expand Down

0 comments on commit d8da293

Please sign in to comment.