core: reverse dependency from core/internal classes, so that it is now one directional.

This commit is contained in:
Carl Mastrangelo 2016-11-28 10:27:51 -08:00 committed by GitHub
parent 0207354994
commit 6c589e1933
5 changed files with 38 additions and 30 deletions

View File

@ -33,6 +33,8 @@ package io.grpc;
/**
* All known transports.
*
* <p>Make sure to update MethodDescriptor.rawMethodNames if this is changed.
*/
@Internal
public enum InternalKnownTransport {

View File

@ -46,27 +46,11 @@ public final class InternalMetadata {
/**
* A specialized plain ASCII marshaller. Both input and output are assumed to be valid header
* ASCII.
*
* <p>Extended here to break the dependency.
*/
@Internal
public interface TrustedAsciiMarshaller<T> {
/**
* Serialize a metadata value to a ASCII string that contains only the characters listed in the
* class comment of {@link io.grpc.Metadata.AsciiMarshaller}. Otherwise the output may be
* considered invalid and discarded by the transport, or the call may fail.
*
* @param value to serialize
* @return serialized version of value, or null if value cannot be transmitted.
*/
byte[] toAsciiString(T value);
/**
* Parse a serialized metadata value from an ASCII string.
*
* @param serialized value of metadata to parse
* @return a parsed instance of type T
*/
T parseAsciiString(byte[] serialized);
}
public interface TrustedAsciiMarshaller<T> extends Metadata.TrustedAsciiMarshaller<T> {}
/**
* Copy of StandardCharsets, which is only available on Java 1.7 and above.
@ -79,7 +63,6 @@ public final class InternalMetadata {
return Metadata.Key.of(name, marshaller);
}
@Internal
public static Metadata newMetadata(byte[]... binaryValues) {
return new Metadata(binaryValues);

View File

@ -46,10 +46,10 @@ public final class InternalMethodDescriptor {
}
public Object geRawMethodName(MethodDescriptor<?, ?> md) {
return md.getRawMethodName(transport);
return md.getRawMethodName(transport.ordinal());
}
public void setRawMethodName(MethodDescriptor<?, ?> md, Object o) {
md.setRawMethodName(transport, o);
md.setRawMethodName(transport.ordinal(), o);
}
}

View File

@ -39,8 +39,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.io.BaseEncoding;
import io.grpc.InternalMetadata.TrustedAsciiMarshaller;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.BitSet;
@ -785,4 +783,28 @@ public final class Metadata {
return marshaller.parseAsciiString(serialized);
}
}
/**
* A specialized plain ASCII marshaller. Both input and output are assumed to be valid header
* ASCII.
*/
interface TrustedAsciiMarshaller<T> {
/**
* Serialize a metadata value to a ASCII string that contains only the characters listed in the
* class comment of {@link io.grpc.Metadata.AsciiMarshaller}. Otherwise the output may be
* considered invalid and discarded by the transport, or the call may fail.
*
* @param value to serialize
* @return serialized version of value, or null if value cannot be transmitted.
*/
byte[] toAsciiString(T value);
/**
* Parse a serialized metadata value from an ASCII string.
*
* @param serialized value of metadata to parse
* @return a parsed instance of type T
*/
T parseAsciiString(byte[] serialized);
}
}

View File

@ -57,15 +57,16 @@ public class MethodDescriptor<ReqT, RespT> {
private final boolean idempotent;
private final boolean safe;
private final AtomicReferenceArray<Object> rawMethodNames =
new AtomicReferenceArray<Object>(InternalKnownTransport.values().length);
// Must be set to InternalKnownTransport.values().length
// Not referenced to break the dependency.
private final AtomicReferenceArray<Object> rawMethodNames = new AtomicReferenceArray<Object>(1);
final Object getRawMethodName(InternalKnownTransport t) {
return rawMethodNames.get(t.ordinal());
final Object getRawMethodName(int transportOrdinal) {
return rawMethodNames.get(transportOrdinal);
}
final void setRawMethodName(InternalKnownTransport t, Object o) {
rawMethodNames.lazySet(t.ordinal(), o);
final void setRawMethodName(int transportOrdinal, Object o) {
rawMethodNames.lazySet(transportOrdinal, o);
}
/**