HADOOP-9821. ClientId should have getMsb/getLsb methods. Contributed by Tsuyoshi OZAWA.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1511058 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0cb2fdc3b4
commit
cb7c15cd37
|
@ -331,6 +331,9 @@ Release 2.1.1-beta - UNRELEASED
|
||||||
HADOOP-9803. Add a generic type parameter to RetryInvocationHandler.
|
HADOOP-9803. Add a generic type parameter to RetryInvocationHandler.
|
||||||
(szetszwo)
|
(szetszwo)
|
||||||
|
|
||||||
|
HADOOP-9821. ClientId should have getMsb/getLsb methods.
|
||||||
|
(Tsuyoshi OZAWA via jing9)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class ClientId {
|
||||||
|
|
||||||
/** The byte array of a UUID should be 16 */
|
/** The byte array of a UUID should be 16 */
|
||||||
public static final int BYTE_LENGTH = 16;
|
public static final int BYTE_LENGTH = 16;
|
||||||
|
private static final int shiftWidth = 8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return clientId as byte[]
|
* Return clientId as byte[]
|
||||||
|
@ -53,17 +54,27 @@ public class ClientId {
|
||||||
}
|
}
|
||||||
// otherwise should be 16 bytes
|
// otherwise should be 16 bytes
|
||||||
Preconditions.checkArgument(clientId.length == BYTE_LENGTH);
|
Preconditions.checkArgument(clientId.length == BYTE_LENGTH);
|
||||||
long msb = 0;
|
long msb = getMsb(clientId);
|
||||||
long lsb = 0;
|
long lsb = getLsb(clientId);
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
msb = (msb << 8) | (clientId[i] & 0xff);
|
|
||||||
}
|
|
||||||
for (int i = 8; i < 16; i++) {
|
|
||||||
lsb = (lsb << 8) | (clientId[i] & 0xff);
|
|
||||||
}
|
|
||||||
return (new UUID(msb, lsb)).toString();
|
return (new UUID(msb, lsb)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getMsb(byte[] clientId) {
|
||||||
|
long msb = 0;
|
||||||
|
for (int i = 0; i < BYTE_LENGTH/2; i++) {
|
||||||
|
msb = (msb << shiftWidth) | (clientId[i] & 0xff);
|
||||||
|
}
|
||||||
|
return msb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long getLsb(byte[] clientId) {
|
||||||
|
long lsb = 0;
|
||||||
|
for (int i = BYTE_LENGTH/2; i < BYTE_LENGTH; i++) {
|
||||||
|
lsb = (lsb << shiftWidth) | (clientId[i] & 0xff);
|
||||||
|
}
|
||||||
|
return lsb;
|
||||||
|
}
|
||||||
|
|
||||||
/** Convert from clientId string byte[] representation of clientId */
|
/** Convert from clientId string byte[] representation of clientId */
|
||||||
public static byte[] toBytes(String id) {
|
public static byte[] toBytes(String id) {
|
||||||
if (id == null || "".equals(id)) {
|
if (id == null || "".equals(id)) {
|
||||||
|
|
|
@ -70,16 +70,8 @@ public class RetryCache {
|
||||||
"Invalid clientId - length is " + clientId.length
|
"Invalid clientId - length is " + clientId.length
|
||||||
+ " expected length " + ClientId.BYTE_LENGTH);
|
+ " expected length " + ClientId.BYTE_LENGTH);
|
||||||
// Convert UUID bytes to two longs
|
// Convert UUID bytes to two longs
|
||||||
long tmp = 0;
|
clientIdMsb = ClientId.getMsb(clientId);
|
||||||
for (int i=0; i<8; i++) {
|
clientIdLsb = ClientId.getLsb(clientId);
|
||||||
tmp = (tmp << 8) | (clientId[i] & 0xff);
|
|
||||||
}
|
|
||||||
clientIdMsb = tmp;
|
|
||||||
tmp = 0;
|
|
||||||
for (int i=8; i<16; i++) {
|
|
||||||
tmp = (tmp << 8) | (clientId[i] & 0xff);
|
|
||||||
}
|
|
||||||
clientIdLsb = tmp;
|
|
||||||
this.callId = callId;
|
this.callId = callId;
|
||||||
this.expirationTime = expirationTime;
|
this.expirationTime = expirationTime;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue