Skip to content

Commit 029db63

Browse files
Merge branch 'grpc:master' into master
2 parents 5140beb + 26bd0ee commit 029db63

File tree

17 files changed

+814
-1151
lines changed

17 files changed

+814
-1151
lines changed

binder/src/main/java/io/grpc/binder/internal/BinderTransport.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ protected boolean setOutgoingBinder(OneWayBinderProxy binder) {
300300

301301
@Override
302302
public synchronized void binderDied() {
303-
shutdownInternal(Status.UNAVAILABLE.withDescription("Peer process crashed, exited or was killed (binderDied)"), true);
303+
shutdownInternal(
304+
Status.UNAVAILABLE.withDescription(
305+
"Peer process crashed, exited or was killed (binderDied)"),
306+
true);
304307
}
305308

306309
@GuardedBy("this")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private void gotoState(final ConnectivityStateInfo newState) {
346346

347347
if (state.getState() != newState.getState()) {
348348
Preconditions.checkState(state.getState() != SHUTDOWN,
349-
"Cannot transition out of SHUTDOWN to " + newState);
349+
"Cannot transition out of SHUTDOWN to %s", newState.getState());
350350
if (reconnectDisabled && newState.getState() == TRANSIENT_FAILURE) {
351351
state = ConnectivityStateInfo.forNonError(IDLE);
352352
} else {

java_grpc_library.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ def _java_rpc_library_impl(ctx):
9191
srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name)
9292

9393
args = ctx.actions.args()
94-
args.add(toolchain.plugin.files_to_run.executable, format = "--plugin=protoc-gen-rpc-plugin=%s")
94+
args.add(toolchain.plugin[DefaultInfo].files_to_run.executable, format = "--plugin=protoc-gen-rpc-plugin=%s")
9595
args.add("--rpc-plugin_out={0}:{1}".format(toolchain.plugin_arg, srcjar.path))
9696
args.add_joined("--descriptor_set_in", descriptor_set_in, join_with = ctx.configuration.host_path_separator)
9797
args.add_all(srcs, map_each = _path_ignoring_repository)
9898

9999
ctx.actions.run(
100-
inputs = depset(srcs, transitive = [descriptor_set_in, toolchain.plugin.files]),
100+
inputs = depset(srcs, transitive = [descriptor_set_in, toolchain.plugin[DefaultInfo].files]),
101101
outputs = [srcjar],
102-
executable = toolchain.protoc.files_to_run,
102+
executable = toolchain.protoc[DefaultInfo].files_to_run,
103103
arguments = [args],
104104
use_default_shell_env = True,
105105
toolchain = None,

rls/src/main/java/io/grpc/rls/LinkedHashLruCache.java

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ abstract class LinkedHashLruCache<K, V> implements LruCache<K, V> {
4343

4444
private final LinkedHashMap<K, SizedValue> delegate;
4545
private final Ticker ticker;
46-
private final EvictionListener<K, SizedValue> evictionListener;
46+
@Nullable
47+
private final EvictionListener<K, V> evictionListener;
4748
private long estimatedSizeBytes;
4849
private long estimatedMaxSizeBytes;
4950

@@ -53,7 +54,7 @@ abstract class LinkedHashLruCache<K, V> implements LruCache<K, V> {
5354
final Ticker ticker) {
5455
checkState(estimatedMaxSizeBytes > 0, "max estimated cache size should be positive");
5556
this.estimatedMaxSizeBytes = estimatedMaxSizeBytes;
56-
this.evictionListener = new SizeHandlingEvictionListener(evictionListener);
57+
this.evictionListener = evictionListener;
5758
this.ticker = checkNotNull(ticker, "ticker");
5859
delegate = new LinkedHashMap<K, SizedValue>(
5960
// rough estimate or minimum hashmap default
@@ -135,7 +136,7 @@ public final V cache(K key, V value) {
135136
estimatedSizeBytes += size;
136137
existing = delegate.put(key, new SizedValue(size, value));
137138
if (existing != null) {
138-
evictionListener.onEviction(key, existing, EvictionType.REPLACED);
139+
fireOnEviction(key, existing, EvictionType.REPLACED);
139140
}
140141
return existing == null ? null : existing.value;
141142
}
@@ -174,7 +175,7 @@ private V invalidate(K key, EvictionType cause) {
174175
checkNotNull(cause, "cause");
175176
SizedValue existing = delegate.remove(key);
176177
if (existing != null) {
177-
evictionListener.onEviction(key, existing, cause);
178+
fireOnEviction(key, existing, cause);
178179
}
179180
return existing == null ? null : existing.value;
180181
}
@@ -185,7 +186,7 @@ public final void invalidateAll() {
185186
while (iterator.hasNext()) {
186187
Map.Entry<K, SizedValue> entry = iterator.next();
187188
if (entry.getValue() != null) {
188-
evictionListener.onEviction(entry.getKey(), entry.getValue(), EvictionType.EXPLICIT);
189+
fireOnEviction(entry.getKey(), entry.getValue(), EvictionType.EXPLICIT);
189190
}
190191
iterator.remove();
191192
}
@@ -215,23 +216,22 @@ public final List<V> values() {
215216
protected final boolean fitToLimit() {
216217
boolean removedAnyUnexpired = false;
217218
if (estimatedSizeBytes <= estimatedMaxSizeBytes) {
218-
// new size is larger no need to do cleanup
219219
return false;
220220
}
221221
// cleanup expired entries
222222
long now = ticker.read();
223223
cleanupExpiredEntries(now);
224224

225-
// cleanup eldest entry until new size limit
225+
// cleanup eldest entry until the size of all entries fits within the limit
226226
Iterator<Map.Entry<K, SizedValue>> lruIter = delegate.entrySet().iterator();
227227
while (lruIter.hasNext() && estimatedMaxSizeBytes < this.estimatedSizeBytes) {
228228
Map.Entry<K, SizedValue> entry = lruIter.next();
229229
if (!shouldInvalidateEldestEntry(entry.getKey(), entry.getValue().value, now)) {
230230
break; // Violates some constraint like minimum age so stop our cleanup
231231
}
232232
lruIter.remove();
233-
// eviction listener will update the estimatedSizeBytes
234-
evictionListener.onEviction(entry.getKey(), entry.getValue(), EvictionType.SIZE);
233+
// fireOnEviction will update the estimatedSizeBytes
234+
fireOnEviction(entry.getKey(), entry.getValue(), EvictionType.SIZE);
235235
removedAnyUnexpired = true;
236236
}
237237
return removedAnyUnexpired;
@@ -270,7 +270,7 @@ private boolean cleanupExpiredEntries(int maxExpiredEntries, long now) {
270270
Map.Entry<K, SizedValue> entry = lruIter.next();
271271
if (isExpired(entry.getKey(), entry.getValue().value, now)) {
272272
lruIter.remove();
273-
evictionListener.onEviction(entry.getKey(), entry.getValue(), EvictionType.EXPIRED);
273+
fireOnEviction(entry.getKey(), entry.getValue(), EvictionType.EXPIRED);
274274
removedAny = true;
275275
maxExpiredEntries--;
276276
}
@@ -283,21 +283,10 @@ public final void close() {
283283
invalidateAll();
284284
}
285285

286-
/** A {@link EvictionListener} keeps track of size. */
287-
private final class SizeHandlingEvictionListener implements EvictionListener<K, SizedValue> {
288-
289-
private final EvictionListener<K, V> delegate;
290-
291-
SizeHandlingEvictionListener(@Nullable EvictionListener<K, V> delegate) {
292-
this.delegate = delegate;
293-
}
294-
295-
@Override
296-
public void onEviction(K key, SizedValue value, EvictionType cause) {
297-
estimatedSizeBytes -= value.size;
298-
if (delegate != null) {
299-
delegate.onEviction(key, value.value, cause);
300-
}
286+
private void fireOnEviction(K key, SizedValue value, EvictionType cause) {
287+
estimatedSizeBytes -= value.size;
288+
if (evictionListener != null) {
289+
evictionListener.onEviction(key, value.value, cause);
301290
}
302291
}
303292

0 commit comments

Comments
 (0)