Created
July 9, 2020 16:56
-
-
Save ken-tune/adda49e10bd440f7a9331148122767f3 to your computer and use it in GitHub Desktop.
Retrieve logical object from within a physical object stored by Aerospike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final int BIT_MASK_SIZE = 25; | |
public static final BigInteger BIT_MASK = (new BigInteger("2")).pow(BIT_MASK_SIZE).subtract(new BigInteger("1")); | |
public static final String METADATA_BIN_NAME = "deviceMetaData"; | |
public static final AerospikeClient aeroClient = new AerospikeClient(hostName,aerospikeServicePort); | |
/** | |
* Get device meta data from Aerospike having employed 'blocking' technique | |
* @param deviceIDasUUID - device id | |
* @return device meta data | |
*/ | |
public Map<String,Object> getDeviceMetaData(UUID deviceIDasUUID){ | |
// Turn UUID into a BigInteger to help with bit masking | |
BigInteger deviceID = new BigInteger(deviceIDasUUID.toString().replace("-",""),32); | |
// Do bit masking | |
BigInteger physicalKey = deviceID.and(BIT_MASK); | |
// Construct Aerospike key using key built using bit masking | |
Key aerospikeKey= new Key(deviceDataNamespace,deviceDataSetName,physicalKey.toString()); | |
// Retrieve record from map. We use the 'physical' aerospikeKey to identify the object | |
// and the device id to retrieve the metadata from the map | |
Record r = aeroClient.operate(null,aerospikeKey, | |
MapOperation.getByKey(METADATA_BIN_NAME,Value.get(deviceIDasUUID.toString()), MapReturnType.VALUE)); | |
return (Map<String, Object>) r.getMap(METADATA_BIN_NAME); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment