本文整理汇总了Java中org.apache.avro.Protocol.getNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java Protocol.getNamespace方法的具体用法?Java Protocol.getNamespace怎么用?Java Protocol.getNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.Protocol
的用法示例。
在下文中一共展示了Protocol.getNamespace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import org.apache.avro.Protocol; //导入方法依赖的package包/类
@Override
public Protocol resolve(Responder responder, Decoder in, Encoder out, Transceiver connection)
throws IOException {
Protocol serverProtocol = responder.getLocal();
byte[] serverMD5 = serverProtocol.getMD5();
String namespace = serverProtocol.getNamespace();
String name = serverProtocol.getName();
HandshakeRequest request = HANDSHAKE_READER.read(null, in);
MD5 clientHash = request.getClientHash();
HandshakeResponse response = new HandshakeResponse();
Protocol protocol = null;
if (clientHash == null) {
LOG.error("Client protocol MD5 is missing from request (namespace=" + namespace + ", name=" +
name + ")");
} else {
byte[] clientMD5 = clientHash.bytes();
if (Arrays.equals(clientMD5, serverMD5)) {
protocol = serverProtocol;
response.setMatch(HandshakeMatch.BOTH);
} else {
String clientMD5String = DatatypeConverter.printHexBinary(clientMD5);
protocol = getProtocol(namespace, name, clientMD5String);
if (protocol == null) {
try {
protocol = AvroD2Helper.readProtocolFromZk(
AvroD2Plugin.getInstance().getZooKeeper(), namespace, name, clientMD5String);
response.setMatch(HandshakeMatch.CLIENT);
setProtocol(namespace, name, clientMD5String, protocol);
} catch (InterruptedException | KeeperException e) {
LOG.error("Unable to read schema from ZooKeeper for protocol (namespace=" + namespace +
", name=" + name + ", MD5=" + clientMD5String + ")", e);
}
} else {
response.setMatch(HandshakeMatch.CLIENT);
}
}
}
if (protocol == null) {
response.setMatch(HandshakeMatch.NONE);
}
if (response.getMatch() != HandshakeMatch.BOTH) {
// Do not return the server protocol, because it is already in ZooKeeper.
// See AvroD2ResponseProcessor.
// response.setServerProtocol(serverProtocol.toString());
response.setServerHash(new MD5(serverMD5));
}
RPCContext context = new RPCContext();
context.setHandshakeRequest(request);
context.setHandshakeResponse(response);
HANDSHAKE_WRITER.write(response, out);
return protocol;
}