-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-16621. [pb-upgrade] Remove Protobuf classes from signatures of Public APIs. #1803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7cdd02e
e5db427
f8fc1b8
7e24758
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,15 @@ | |
| package org.apache.hadoop.ipc; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.io.Text; | ||
| import org.apache.hadoop.security.proto.SecurityProtos; | ||
| import org.apache.hadoop.security.token.Token; | ||
| import org.apache.hadoop.security.token.TokenIdentifier; | ||
|
|
||
| import com.google.protobuf.ByteString; | ||
| import com.google.protobuf.ServiceException; | ||
|
|
||
| /** | ||
|
|
@@ -46,4 +52,67 @@ public static IOException getRemoteException(ServiceException se) { | |
| } | ||
| return e instanceof IOException ? (IOException) e : new IOException(se); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Map used to cache fixed strings to ByteStrings. Since there is no | ||
| * automatic expiration policy, only use this for strings from a fixed, small | ||
| * set. | ||
| * <p/> | ||
| * This map should not be accessed directly. Used the getFixedByteString | ||
| * methods instead. | ||
| */ | ||
| private static ConcurrentHashMap<Object, ByteString> fixedByteStringCache = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| /** | ||
| * Get the ByteString for frequently used fixed and small set strings. | ||
| * @param key string | ||
| * @return | ||
| */ | ||
| public static ByteString getFixedByteString(Text key) { | ||
steveloughran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ByteString value = fixedByteStringCache.get(key); | ||
| if (value == null) { | ||
| value = ByteString.copyFromUtf8(key.toString()); | ||
| fixedByteStringCache.put(new Text(key.copyBytes()), value); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Get the ByteString for frequently used fixed and small set strings. | ||
| * @param key string | ||
| * @return | ||
| */ | ||
| public static ByteString getFixedByteString(String key) { | ||
| ByteString value = fixedByteStringCache.get(key); | ||
| if (value == null) { | ||
| value = ByteString.copyFromUtf8(key); | ||
| fixedByteStringCache.put(key, value); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| public static ByteString getByteString(byte[] bytes) { | ||
| // return singleton to reduce object allocation | ||
| return (bytes.length == 0) ? ByteString.EMPTY : ByteString.copyFrom(bytes); | ||
| } | ||
|
|
||
| public static Token<? extends TokenIdentifier> convert( | ||
|
||
| SecurityProtos.TokenProto tokenProto) { | ||
| Token<? extends TokenIdentifier> token = new Token<>( | ||
| tokenProto.getIdentifier().toByteArray(), | ||
| tokenProto.getPassword().toByteArray(), new Text(tokenProto.getKind()), | ||
| new Text(tokenProto.getService())); | ||
| return token; | ||
| } | ||
|
|
||
| public static SecurityProtos.TokenProto convert(Token<?> tok) { | ||
| SecurityProtos.TokenProto.Builder builder = SecurityProtos.TokenProto.newBuilder(). | ||
| setIdentifier(getByteString(tok.getIdentifier())). | ||
| setPassword(getByteString(tok.getPassword())). | ||
| setKindBytes(getFixedByteString(tok.getKind())). | ||
| setServiceBytes(getFixedByteString(tok.getService())); | ||
| return builder.build(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.