mirror of https://github.com/grpc/grpc-java.git
core: reverse dependency from core/internal classes, so that it is now one directional.
This commit is contained in:
parent
0207354994
commit
6c589e1933
|
|
@ -33,6 +33,8 @@ package io.grpc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All known transports.
|
* All known transports.
|
||||||
|
*
|
||||||
|
* <p>Make sure to update MethodDescriptor.rawMethodNames if this is changed.
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public enum InternalKnownTransport {
|
public enum InternalKnownTransport {
|
||||||
|
|
|
||||||
|
|
@ -46,27 +46,11 @@ public final class InternalMetadata {
|
||||||
/**
|
/**
|
||||||
* A specialized plain ASCII marshaller. Both input and output are assumed to be valid header
|
* A specialized plain ASCII marshaller. Both input and output are assumed to be valid header
|
||||||
* ASCII.
|
* ASCII.
|
||||||
|
*
|
||||||
|
* <p>Extended here to break the dependency.
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public interface TrustedAsciiMarshaller<T> {
|
public interface TrustedAsciiMarshaller<T> extends Metadata.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy of StandardCharsets, which is only available on Java 1.7 and above.
|
* 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);
|
return Metadata.Key.of(name, marshaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public static Metadata newMetadata(byte[]... binaryValues) {
|
public static Metadata newMetadata(byte[]... binaryValues) {
|
||||||
return new Metadata(binaryValues);
|
return new Metadata(binaryValues);
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ public final class InternalMethodDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object geRawMethodName(MethodDescriptor<?, ?> md) {
|
public Object geRawMethodName(MethodDescriptor<?, ?> md) {
|
||||||
return md.getRawMethodName(transport);
|
return md.getRawMethodName(transport.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRawMethodName(MethodDescriptor<?, ?> md, Object o) {
|
public void setRawMethodName(MethodDescriptor<?, ?> md, Object o) {
|
||||||
md.setRawMethodName(transport, o);
|
md.setRawMethodName(transport.ordinal(), o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,6 @@ import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.io.BaseEncoding;
|
import com.google.common.io.BaseEncoding;
|
||||||
|
|
||||||
import io.grpc.InternalMetadata.TrustedAsciiMarshaller;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
@ -785,4 +783,28 @@ public final class Metadata {
|
||||||
return marshaller.parseAsciiString(serialized);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,15 +57,16 @@ public class MethodDescriptor<ReqT, RespT> {
|
||||||
private final boolean idempotent;
|
private final boolean idempotent;
|
||||||
private final boolean safe;
|
private final boolean safe;
|
||||||
|
|
||||||
private final AtomicReferenceArray<Object> rawMethodNames =
|
// Must be set to InternalKnownTransport.values().length
|
||||||
new AtomicReferenceArray<Object>(InternalKnownTransport.values().length);
|
// Not referenced to break the dependency.
|
||||||
|
private final AtomicReferenceArray<Object> rawMethodNames = new AtomicReferenceArray<Object>(1);
|
||||||
|
|
||||||
final Object getRawMethodName(InternalKnownTransport t) {
|
final Object getRawMethodName(int transportOrdinal) {
|
||||||
return rawMethodNames.get(t.ordinal());
|
return rawMethodNames.get(transportOrdinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
final void setRawMethodName(InternalKnownTransport t, Object o) {
|
final void setRawMethodName(int transportOrdinal, Object o) {
|
||||||
rawMethodNames.lazySet(t.ordinal(), o);
|
rawMethodNames.lazySet(transportOrdinal, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue