Skip to content

Commit 58be575

Browse files
committed
make AutoValue work in PubSub
This commit digs us out of the AutoValue dependency hell. Previously - We require Guava 20 for its Stats class. - Guava source has a `@CanIgnoreReturnValue` annotation, this annotation is in errorprone package. - Errorprone package required Java8 to run. So, I just took dependency on it without running to make the build pass in both 7 and 8. - Errorprone shades class javax.lang.model.type.IntersectionType. This class is Java8-only, but because it wasn't run, it didn't cause a problem. - AutoValue conditionally loads IntersectionType. It catches Exception and behaves properly if the class is not found; this is why it works on Java 7. However, because of the previous step, we have the class in our path. Because the class is 8-only, JVM7 loading it results in UnsupportedVersionError. This is an Error and not an Exception, and so AutoValue (probably wisely) ignore it and crashes. The fix is simple. Since #1480 already removed Stats, we can just go back to Guava 19. @garrettjonesgoogle is full of wisdom!
1 parent a254293 commit 58be575

File tree

3 files changed

+20
-81
lines changed

3 files changed

+20
-81
lines changed

google-cloud-pubsub/pom.xml

+1-14
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@
5353
<artifactId>grpc-auth</artifactId>
5454
<version>${grpc.version}</version>
5555
</dependency>
56-
<dependency>
57-
<groupId>com.google.guava</groupId>
58-
<artifactId>guava</artifactId>
59-
<version>20.0</version>
60-
</dependency>
61-
<dependency>
62-
<groupId>com.google.errorprone</groupId>
63-
<artifactId>error_prone_core</artifactId>
64-
<version>2.0.15</version>
65-
</dependency>
6656
<dependency>
6757
<groupId>joda-time</groupId>
6858
<artifactId>joda-time</artifactId>
@@ -164,10 +154,7 @@
164154
</plugin>
165155
<plugin>
166156
<artifactId>maven-compiler-plugin</artifactId>
167-
<!-- Downgrading to 3.1 because of https://issues.apache.org/jira/browse/MCOMPILER-236 -->
168-
<!-- Upgrade to 3.5.1 which fixes the problem when available -->
169-
<!-- <version>3.5.1</version> -->
170-
<version>3.1</version>
157+
<version>3.5.1</version>
171158
<configuration>
172159
<source>1.7</source>
173160
<target>1.7</target>

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/PublisherStats.java

+7-27
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,24 @@
1616

1717
package com.google.cloud.pubsub;
1818

19-
import javax.annotation.concurrent.Immutable;
19+
import com.google.auto.value.AutoValue;
2020

2121
/**
2222
* A snapshot of the publisher statistics at the time they were requested from the {@link
2323
* Publisher}.
2424
*/
2525
//TODO: Finish implementation.
26-
@Immutable
27-
public class PublisherStats {
28-
private final long sentMessages;
29-
private final long ackedMessages;
30-
private final long failedMessages;
31-
private final long pendingMessages;
32-
33-
PublisherStats(long sentMessages, long ackedMessages, long failedMessages, long pendingMessages) {
34-
this.sentMessages = sentMessages;
35-
this.ackedMessages = ackedMessages;
36-
this.failedMessages = failedMessages;
37-
this.pendingMessages = pendingMessages;
38-
}
39-
26+
@AutoValue
27+
public abstract class PublisherStats {
4028
/** Number of successfully published messages. */
41-
public long getAckedMessages() {
42-
return ackedMessages;
43-
}
29+
public abstract long getAckedMessages();
4430

4531
/** Number of messages that failed to publish. */
46-
public long getFailedMessages() {
47-
return failedMessages;
48-
}
32+
public abstract long getFailedMessages();
4933

5034
/** Number of messages pending to publish, includes message in-flight. */
51-
public long getPendingMessages() {
52-
return pendingMessages;
53-
}
35+
public abstract long getPendingMessages();
5436

5537
/** Total messages sent, equal to pending + acked + failed messages. */
56-
public long getSentMessages() {
57-
return sentMessages;
58-
}
38+
public abstract long getSentMessages();
5939
}

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/SubscriberStats.java

+12-40
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,39 @@
1616

1717
package com.google.cloud.pubsub;
1818

19-
import javax.annotation.concurrent.Immutable;
19+
import com.google.auto.value.AutoValue;
2020

2121
/**
2222
* A snapshot of the subscriber statistics at the time they were requested from the {@link
2323
* Subscriber}.
2424
*/
2525
//TODO: Finish implementation.
26-
@Immutable
27-
public class SubscriberStats {
28-
@Immutable
29-
public static class Stats {}
30-
31-
private final long totalReceivedMessages;
32-
private final long totalAckedMessages;
33-
private final Stats endToEndLatency;
34-
private final Stats ackLatency;
35-
private final long numberOfAutoExtendedAckDeadlines;
36-
37-
SubscriberStats() {
38-
this.totalReceivedMessages = 0;
39-
this.totalAckedMessages = 0;
40-
this.numberOfAutoExtendedAckDeadlines = 0;
41-
this.endToEndLatency = null;
42-
this.ackLatency = null;
43-
}
26+
@AutoValue
27+
public abstract class SubscriberStats {
28+
@AutoValue
29+
public abstract static class Stats {}
4430

4531
/** Number of successfully published messages. */
46-
public long getReceivedMessages() {
47-
return totalReceivedMessages;
48-
}
32+
public abstract long getReceivedMessages();
4933

5034
/** Number of successfully published messages. */
51-
public long getAckedMessages() {
52-
return totalAckedMessages;
53-
}
35+
public abstract long getAckedMessages();
5436

5537
/** Number of received messages. */
56-
public long getTotalReceivedMessages() {
57-
return totalReceivedMessages;
58-
}
38+
public abstract long getTotalReceivedMessages();
5939

6040
/** Number messages acked. */
61-
public long getTotalAckedMessages() {
62-
return totalAckedMessages;
63-
}
41+
public abstract long getTotalAckedMessages();
6442

6543
/** End to end latency. */
66-
public Stats getEndToEndLatency() {
67-
return endToEndLatency;
68-
}
44+
public abstract Stats getEndToEndLatency();
6945

7046
/**
7147
* Acknowledgement latency; time in between the message has been received and then acknowledged or
7248
* rejected.
7349
*/
74-
public Stats getAckLatency() {
75-
return ackLatency;
76-
}
50+
public abstract Stats getAckLatency();
7751

7852
/** Number of messages for which we have auto extended its acknowledgement deadline. */
79-
public long getNumberOfAutoExtendedAckDeadlines() {
80-
return numberOfAutoExtendedAckDeadlines;
81-
}
53+
public abstract long getNumberOfAutoExtendedAckDeadlines();
8254
}

0 commit comments

Comments
 (0)