Skip to content

Commit

Permalink
Merge 6072c15 into d86d3dd
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelkollus committed May 24, 2019
2 parents d86d3dd + 6072c15 commit daba8ea
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/io/grpc/Attributes.java
Expand Up @@ -252,7 +252,7 @@ public <T> Builder discard(Key<T> key) {
return this;
}

public <T> Builder setAll(Attributes other) {
public Builder setAll(Attributes other) {
data(other.data.size()).putAll(other.data);
return this;
}
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/java/io/grpc/InternalMethodDescriptor.java
Expand Up @@ -30,11 +30,11 @@ public InternalMethodDescriptor(InternalKnownTransport transport) {
this.transport = checkNotNull(transport, "transport");
}

public Object geRawMethodName(MethodDescriptor<?, ?> md) {
return md.getRawMethodName(transport.ordinal());
public Object geRawMethodName(MethodDescriptor<?, ?> descriptor) {
return descriptor.getRawMethodName(transport.ordinal());
}

public void setRawMethodName(MethodDescriptor<?, ?> md, Object o) {
md.setRawMethodName(transport.ordinal(), o);
public void setRawMethodName(MethodDescriptor<?, ?> descriptor, Object o) {
descriptor.setRawMethodName(transport.ordinal(), o);
}
}
37 changes: 37 additions & 0 deletions api/src/main/java/io/grpc/NameResolverComparator.java
@@ -0,0 +1,37 @@
/*
* Copyright 2018 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.grpc;

import java.util.Comparator;

/**
* The {@link NameResolverComparator} class compares two {@link NameResolverProvider} arguments
* for order. Returns a negative integer, zero, or a positive integer as the first argument
* is less than, equal to, or greater than the second.
*
* @author Manuel Kollus
* @version 1.21.1
*/
public final class NameResolverComparator implements Comparator<NameResolverProvider> {

@Override
public int compare(
NameResolverProvider nameResolverProvider,
NameResolverProvider otherNameResolverProvider) {
return nameResolverProvider.priority() - otherNameResolverProvider.priority();
}
}
8 changes: 1 addition & 7 deletions api/src/main/java/io/grpc/NameResolverRegistry.java
Expand Up @@ -22,7 +22,6 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.logging.Level;
Expand Down Expand Up @@ -84,12 +83,7 @@ private synchronized void refreshProviders() {
List<NameResolverProvider> providers = new ArrayList<>(allProviders);
// Sort descending based on priority.
// sort() must be stable, as we prefer first-registered providers
Collections.sort(providers, Collections.reverseOrder(new Comparator<NameResolverProvider>() {
@Override
public int compare(NameResolverProvider p1, NameResolverProvider p2) {
return p1.priority() - p2.priority();
}
}));
Collections.sort(providers, Collections.reverseOrder(new NameResolverComparator()));
effectiveProviders = Collections.unmodifiableList(providers);
}

Expand Down
Expand Up @@ -97,8 +97,8 @@ public static <T extends MessageLite> Metadata.BinaryMarshaller<T> metadataMarsh
/** Copies the data from input stream to output stream. */
static long copy(InputStream from, OutputStream to) throws IOException {
// Copied from guava com.google.common.io.ByteStreams because its API is unstable (beta)
checkNotNull(from);
checkNotNull(to);
checkNotNull(from, "inputStream cannot be null!");
checkNotNull(to, "outputStream cannot be null!");
byte[] buf = new byte[BUF_SIZE];
long total = 0;
while (true) {
Expand Down Expand Up @@ -162,7 +162,7 @@ public T parse(InputStream stream) {
@SuppressWarnings("unchecked")
T message = (T) ((ProtoInputStream) stream).message();
return message;
} catch (IllegalStateException ex) {
} catch (IllegalStateException ignored) {
// Stream must have been read from, which is a strange state. Since the point of this
// optimization is to be transparent, instead of throwing an error we'll continue,
// even though it seems likely there's a bug.
Expand Down

0 comments on commit daba8ea

Please sign in to comment.