Skip to content

Commit 405f40d

Browse files
committed
change.
1 parent 90aefb2 commit 405f40d

File tree

5 files changed

+86
-4
lines changed

5 files changed

+86
-4
lines changed

core/src/main/java/io/grpc/internal/ClientCallImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ public void runInContext() {
275275
}
276276
if (effectiveDeadline != null) {
277277
stream.setDeadline(effectiveDeadline);
278-
}
278+
};
279+
stream.setDeadline(Deadline.after(1, TimeUnit.SECONDS));
279280
stream.setCompressor(compressor);
280281
if (fullStreamDecompression) {
281282
stream.setFullStreamDecompression(fullStreamDecompression);

examples/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies {
4545
protobuf {
4646
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
4747
plugins {
48-
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
48+
grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.70.0" }
4949
}
5050
generateProtoTasks {
5151
all()*.plugins { grpc {} }

examples/src/main/java/io/grpc/examples/deadline/DeadlineClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static void main(String[] args) throws Exception {
8585
client.greet("deadline client", 1000);
8686

8787
// A smaller deadline will result in us getting a DEADLINE_EXCEEDED error.
88-
logger.info(
88+
/*logger.info(
8989
"Calling server with an unrealistic (300ms) deadline, expecting a DEADLINE_EXCEEDED");
9090
client.greet("deadline client", 300);
9191
@@ -102,7 +102,7 @@ public static void main(String[] args) throws Exception {
102102
// runs out of time waiting for the propagated call to finish.
103103
logger.info(
104104
"Calling server with propagation and a generous deadline, expecting a DEADLINE_EXCEEDED");
105-
client.greet("deadline client [propagate]", 1000);
105+
client.greet("deadline client [propagate]", 1000);*/
106106
} finally {
107107
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
108108
}

examples/src/main/java/io/grpc/examples/deadline/DeadlineServer.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
import io.grpc.Grpc;
2020
import io.grpc.InsecureChannelCredentials;
2121
import io.grpc.InsecureServerCredentials;
22+
import io.grpc.Metadata;
2223
import io.grpc.Server;
24+
import io.grpc.ServerCall;
25+
import io.grpc.ServerCall.Listener;
26+
import io.grpc.ServerCallHandler;
27+
import io.grpc.ServerInterceptor;
2328
import io.grpc.examples.helloworld.GreeterGrpc;
2429
import io.grpc.examples.helloworld.HelloReply;
2530
import io.grpc.examples.helloworld.HelloRequest;
@@ -38,6 +43,39 @@ private void start() throws IOException {
3843
int port = 50051;
3944
SlowGreeter slowGreeter = new SlowGreeter();
4045
server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
46+
.intercept(new ServerInterceptor() {
47+
@Override
48+
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
49+
Metadata headers, ServerCallHandler<ReqT, RespT> next) {
50+
Listener<ReqT> fwkReqListener = next.startCall(call, headers);
51+
return new Listener<ReqT>() {
52+
@Override
53+
public void onMessage(ReqT message) {
54+
fwkReqListener.onMessage(message);
55+
}
56+
57+
@Override
58+
public void onHalfClose() {
59+
fwkReqListener.onHalfClose();
60+
}
61+
62+
@Override
63+
public void onCancel() {
64+
fwkReqListener.onCancel();
65+
}
66+
67+
@Override
68+
public void onComplete() {
69+
fwkReqListener.onComplete();
70+
}
71+
72+
@Override
73+
public void onReady() {
74+
fwkReqListener.onReady();
75+
}
76+
};
77+
}
78+
})
4179
.addService(slowGreeter)
4280
.build()
4381
.start();

examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818

1919
import io.grpc.Grpc;
2020
import io.grpc.InsecureServerCredentials;
21+
import io.grpc.Metadata;
2122
import io.grpc.Server;
23+
import io.grpc.ServerCall;
24+
import io.grpc.ServerCall.Listener;
25+
import io.grpc.ServerCallHandler;
26+
import io.grpc.ServerInterceptor;
2227
import io.grpc.stub.StreamObserver;
2328
import java.io.IOException;
2429
import java.util.concurrent.TimeUnit;
@@ -36,6 +41,39 @@ private void start() throws IOException {
3641
/* The port on which the server should run */
3742
int port = 50051;
3843
server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
44+
.intercept(new ServerInterceptor() {
45+
@Override
46+
public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
47+
Metadata headers, ServerCallHandler<ReqT, RespT> next) {
48+
Listener<ReqT> fwkReqListener = next.startCall(call, headers);
49+
return new Listener<ReqT>() {
50+
@Override
51+
public void onMessage(ReqT message) {
52+
fwkReqListener.onMessage(message);
53+
}
54+
55+
@Override
56+
public void onHalfClose() {
57+
fwkReqListener.onHalfClose();
58+
}
59+
60+
@Override
61+
public void onCancel() {
62+
fwkReqListener.onCancel();
63+
}
64+
65+
@Override
66+
public void onComplete() {
67+
fwkReqListener.onComplete();
68+
}
69+
70+
@Override
71+
public void onReady() {
72+
fwkReqListener.onReady();
73+
}
74+
};
75+
}
76+
})
3977
.addService(new GreeterImpl())
4078
.build()
4179
.start();
@@ -83,6 +121,11 @@ static class GreeterImpl extends GreeterGrpc.GreeterImplBase {
83121

84122
@Override
85123
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
124+
try {
125+
Thread.sleep(10000);
126+
} catch (InterruptedException e) {
127+
throw new RuntimeException(e);
128+
}
86129
HelloReply reply = HelloReply.newBuilder().setMessage("Hello " + req.getName()).build();
87130
responseObserver.onNext(reply);
88131
responseObserver.onCompleted();

0 commit comments

Comments
 (0)