Skip to content

Commit b7b3e1e

Browse files
committed
Update jars and cleanup
1 parent 62c1543 commit b7b3e1e

File tree

11 files changed

+76
-162
lines changed

11 files changed

+76
-162
lines changed

build-applications.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ repositories {
1919
maven { // The google mirror is less flaky than mavenCentral()
2020
url = "https://maven-central.storage-download.googleapis.com/repos/central/data/"
2121
}
22-
jcenter()
2322
maven { url = "https://jitpack.io" }
2423
}
2524

@@ -43,14 +42,10 @@ dependencies {
4342
implementation "io.opencensus:opencensus-exporter-stats-prometheus:${opencensus_version}"
4443
implementation "io.prometheus:simpleclient_httpserver:${prometheus_version}"
4544

46-
// examples/advanced need this for JsonFormat
47-
implementation "com.google.protobuf:protobuf-java-util:${protobuf_version}"
48-
4945
testImplementation "io.grpc:grpc-testing:${grpc_version}"
5046
testImplementation "org.mockito:mockito-core:3.3.1"
5147

5248
testImplementation "junit:junit:${junit_version}"
53-
testCompile group: 'junit', name: 'junit', version: junit_version
5449
}
5550

5651
// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.

build.gradle

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,8 @@ dependencies {
4040

4141
compileOnly "javax.annotation:javax.annotation-api:$annotation_version"
4242

43-
implementation "io.opencensus:opencensus-impl:$opencensus_version"
44-
implementation "io.opencensus:opencensus-contrib-grpc-metrics:$opencensus_version"
45-
implementation "io.opencensus:opencensus-exporter-stats-prometheus:$opencensus_version"
46-
implementation "io.prometheus:simpleclient_httpserver:$prometheus_version"
47-
4843
// examples/advanced need this for JsonFormat
49-
implementation "com.google.protobuf:protobuf-java-util:$protobuf_version"
44+
//implementation "com.google.protobuf:protobuf-java-util:$protobuf_version"
5045

5146
implementation "io.github.microutils:kotlin-logging:$logging_version"
5247
implementation "ch.qos.logback:logback-classic:$logback_version"
@@ -55,7 +50,6 @@ dependencies {
5550
testImplementation "org.mockito:mockito-core:$mockito_version"
5651

5752
testImplementation "junit:junit:$junit_version"
58-
//testCompile "junit:junit:$junit_version"
5953
}
6054

6155
// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
@@ -109,8 +103,6 @@ compileKotlin {
109103
compileTestKotlin {
110104
kotlinOptions {
111105
jvmTarget = "1.8"
112-
freeCompilerArgs += ["-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
113-
"-Xopt-in=kotlinx.coroutines.InternalCoroutinesApi"]
114106
}
115107
}
116108

etc/prometheus.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

gradle.properties

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ kotlin_version=1.6.10-RC
1414
logback_version=1.2.7
1515
logging_version=2.1.16
1616
mockito_version=4.1.0
17-
opencensus_version=0.28.3
18-
prometheus_version=0.12.0
19-
protobuf_version=3.19.1
2017
protoc_version=3.17.3

src/main/java/org/athenian/java_helloworld/HelloWorldClient.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void main(String... args)
5555
public void sayHello(String name) {
5656
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
5757
HelloReply response = this.blockingStub.sayHello(request);
58-
System.out.println(format("sayHello() response: %s\n", response.getMessage()));
58+
System.out.printf("sayHello() response: %s\n%n", response.getMessage());
5959
}
6060

6161
public void sayHelloWithManyRequests(String name) {
@@ -66,14 +66,14 @@ public void sayHelloWithManyRequests(String name) {
6666
new StreamObserver<HelloReply>() {
6767
@Override
6868
public void onNext(HelloReply reply) {
69-
System.out.println(format("sayHelloWithManyRequests() response: %s\n", reply.getMessage()));
69+
System.out.printf("sayHelloWithManyRequests() response: %s\n%n", reply.getMessage());
7070
}
7171

7272
@Override
7373
public void onError(Throwable t) {
7474
Status status = Status.fromThrowable(t);
75-
System.out.println(format("sayHelloWithMayRequests() failed: %s", status));
76-
finishLatch.countDown();
75+
System.out.printf("sayHelloWithMayRequests() failed: %s%n", status);
76+
finishLatch.countDown();
7777
}
7878

7979
@Override
@@ -130,14 +130,14 @@ public void sayHelloWithManyRequestsAndReplies(String name) {
130130
new StreamObserver<HelloReply>() {
131131
@Override
132132
public void onNext(HelloReply reply) {
133-
System.out.println(format("sayHelloWithManyRequestsAndReplies() response: %s", reply.getMessage()));
133+
System.out.printf("sayHelloWithManyRequestsAndReplies() response: %s%n", reply.getMessage());
134134
}
135135

136136
@Override
137137
public void onError(Throwable t) {
138138
Status status = Status.fromThrowable(t);
139-
System.out.println(format("sayHelloWithManyRequestsAndReplies() failed: %s", status));
140-
finishLatch.countDown();
139+
System.out.printf("sayHelloWithManyRequestsAndReplies() failed: %s%n", status);
140+
finishLatch.countDown();
141141
}
142142

143143
@Override
@@ -151,8 +151,8 @@ public void onCompleted() {
151151
try {
152152
for (int i = 0; i < 5; i++) {
153153
HelloRequest request = HelloRequest.newBuilder().setName(format("%s-%d", name, i)).build();
154-
System.out.println(format("sayHelloWithManyRequestsAndReplies() request: %s", request.getName()));
155-
requestObserver.onNext(request);
154+
System.out.printf("sayHelloWithManyRequestsAndReplies() request: %s%n", request.getName());
155+
requestObserver.onNext(request);
156156

157157
if (finishLatch.getCount() == 0) {
158158
// RPC completed or errored before we finished sending.

src/main/java/org/athenian/java_helloworld/HelloWorldServer.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import java.io.IOException;
77

8-
import static java.lang.String.format;
9-
108
public class HelloWorldServer {
119
private Server server;
1210

@@ -22,17 +20,17 @@ private void start()
2220
/* The port on which the server should run */
2321
int port = 50051;
2422
server = ServerBuilder.forPort(port)
25-
.addService(new GreeterImpl())
26-
.build()
27-
.start();
28-
System.out.println(format("Server started, listening on %d", port));
23+
.addService(new GreeterImpl())
24+
.build()
25+
.start();
26+
System.out.printf("Server started, listening on %d%n", port);
2927
Runtime.getRuntime().addShutdownHook(
30-
new Thread(() -> {
31-
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
32-
System.err.println("*** shutting down gRPC server since JVM is shutting down");
33-
HelloWorldServer.this.stop();
34-
System.err.println("*** server shut down");
35-
}));
28+
new Thread(() -> {
29+
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
30+
System.err.println("*** shutting down gRPC server since JVM is shutting down");
31+
HelloWorldServer.this.stop();
32+
System.err.println("*** server shut down");
33+
}));
3634
}
3735

3836
private void stop() {

src/main/kotlin/org/athenian/kotlin_helloworld/withCR/HelloWorldClient.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package org.athenian.kotlin_helloworld.withCR
22

33
import io.grpc.ManagedChannel
44
import io.grpc.ManagedChannelBuilder
5-
import io.opencensus.contrib.grpc.metrics.RpcViews
6-
import io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector
7-
import io.prometheus.client.exporter.HTTPServer
85
import kotlinx.coroutines.coroutineScope
96
import kotlinx.coroutines.delay
107
import kotlinx.coroutines.flow.flow
@@ -84,10 +81,6 @@ class HelloWorldClient internal constructor(private val channel: ManagedChannel)
8481

8582
@JvmStatic
8683
fun main(args: Array<String>) {
87-
PrometheusStatsCollector.createAndRegister()
88-
RpcViews.registerClientGrpcViews()
89-
val http = HTTPServer("localhost", 8889, true)
90-
9184
val name = if (args.isNotEmpty()) args[0] else "world"
9285

9386
HelloWorldClient("localhost")
@@ -101,8 +94,6 @@ class HelloWorldClient internal constructor(private val channel: ManagedChannel)
10194
}
10295
}
10396
}
104-
105-
http.stop()
10697
}
10798
}
10899
}

src/main/kotlin/org/athenian/kotlin_helloworld/withCR/HelloWorldServer.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ package org.athenian.kotlin_helloworld.withCR
22

33
import io.grpc.Server
44
import io.grpc.ServerBuilder
5-
import io.opencensus.contrib.grpc.metrics.RpcViews
6-
import io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector
7-
import io.opencensus.trace.Tracer
8-
import io.opencensus.trace.Tracing
9-
import io.prometheus.client.exporter.HTTPServer
105

116

127
class HelloWorldServer {
@@ -27,14 +22,9 @@ class HelloWorldServer {
2722

2823
companion object {
2924
val port = System.getenv("PORT")?.toInt() ?: 50051
30-
val tracer: Tracer = Tracing.getTracer()
3125

3226
@JvmStatic
3327
fun main(args: Array<String>) {
34-
PrometheusStatsCollector.createAndRegister()
35-
RpcViews.registerServerGrpcViews()
36-
HTTPServer("localhost", 8888, true)
37-
3828
HelloWorldServer()
3929
.apply {
4030
start()

src/main/kotlin/org/athenian/kotlin_helloworld/withoutCR/GreeterImpl.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.athenian.helloworld.HelloRequest
88
class GreeterImpl : GreeterGrpc.GreeterImplBase() {
99

1010
override fun sayHello(request: HelloRequest, responseObserver: StreamObserver<HelloReply>) {
11-
//val scope = HelloWorldServer.tracer.spanBuilder("$PREFIX.sayHello").startScopedSpan()!!
1211
val reply =
1312
HelloReply.newBuilder()
1413
.run {
@@ -17,22 +16,19 @@ class GreeterImpl : GreeterGrpc.GreeterImplBase() {
1716
}
1817
responseObserver.apply {
1918
onNext(reply)
20-
//scope.close()
2119
onCompleted()
2220
}
2321
}
2422

2523
override fun sayHelloWithManyRequests(responseObserver: StreamObserver<HelloReply>) =
2624
object : StreamObserver<HelloRequest> {
2725
val names: MutableList<String> = mutableListOf()
28-
//val scope = HelloWorldServer.tracer.spanBuilder("$PREFIX.sayHelloWithManyRequests").startScopedSpan()!!
2926

3027
override fun onNext(request: HelloRequest) {
3128
names.add(request.name)
3229
}
3330

3431
override fun onError(t: Throwable) {
35-
//scope.close()
3632
println("Encountered error in sayHelloWithManyRequests()")
3733
t.printStackTrace()
3834
}
@@ -47,14 +43,12 @@ class GreeterImpl : GreeterGrpc.GreeterImplBase() {
4743
responseObserver
4844
.apply {
4945
onNext(msg)
50-
//scope.close()
5146
onCompleted()
5247
}
5348
}
5449
}
5550

5651
override fun sayHelloWithManyReplies(request: HelloRequest, responseObserver: StreamObserver<HelloReply>) {
57-
//val scope = HelloWorldServer.tracer.spanBuilder("$PREFIX.sayHelloWithManyReplies").startScopedSpan()!!
5852
repeat(5) {
5953
val reply =
6054
HelloReply.newBuilder()
@@ -64,13 +58,11 @@ class GreeterImpl : GreeterGrpc.GreeterImplBase() {
6458
}
6559
responseObserver.onNext(reply)
6660
}
67-
//scope.close()
6861
responseObserver.onCompleted()
6962
}
7063

7164
override fun sayHelloWithManyRequestsAndReplies(responseObserver: StreamObserver<HelloReply>) =
7265
object : StreamObserver<HelloRequest> {
73-
//val scope = HelloWorldServer.tracer.spanBuilder("$PREFIX.sayHelloWithManyRequestsAndReplies").startScopedSpan()!!
7466
override fun onNext(request: HelloRequest) {
7567
repeat(5) {
7668
val reply =
@@ -84,18 +76,12 @@ class GreeterImpl : GreeterGrpc.GreeterImplBase() {
8476
}
8577

8678
override fun onError(t: Throwable) {
87-
//scope.close()
8879
println("Encountered error in sayHelloWithManyRequestsAndReplies()")
8980
t.printStackTrace()
9081
}
9182

9283
override fun onCompleted() {
93-
//scope.close()
9484
responseObserver.onCompleted()
9585
}
9686
}
97-
98-
companion object {
99-
const val PREFIX = "grpc-helloworld.GreeterImpl"
100-
}
10187
}

0 commit comments

Comments
 (0)