Пример #1
0
 /**
  * Creates a new UnsafeMetricDefinition
  *
  * @param globalId The global id of the metric
  * @param timestamp The creation timestamp of this metric, or -1L if the metric is new, in which
  *     case the currnt time will be substituted
  * @param name The metric name
  * @param opaqueKey The opaque key
  */
 public UnsafeMetricDefinition(long globalId, long timestamp, String name, byte[] opaqueKey) {
   byte[] nameBytes = getBytes(name);
   byte[] opaqueBytes = getBytes(opaqueKey);
   int size = BASE_SIZE + nameBytes.length + opaqueBytes.length;
   address[0] = UnsafeAdapter.allocateAlignedMemory(size);
   UnsafeAdapter.registerForDeAlloc(this);
   UnsafeAdapter.putByte(address[0], DELETE_FLAG);
   UnsafeAdapter.putInt(address[0] + SIZE, size);
   UnsafeAdapter.putLong(address[0] + ID, globalId);
   UnsafeAdapter.putLong(
       address[0] + TIMESTAMP, timestamp != -1L ? timestamp : System.currentTimeMillis());
   UnsafeAdapter.putInt(address[0] + NAME_SIZE, nameBytes.length);
   UnsafeAdapter.putInt(address[0] + OPAQUE_SIZE, opaqueBytes.length);
   if (nameBytes.length > 0) {
     UnsafeAdapter.copyMemory(
         nameBytes,
         UnsafeAdapter.BYTE_ARRAY_OFFSET,
         null,
         address[0] + NAME_BYTES,
         nameBytes.length);
   }
   if (opaqueBytes.length > 0) {
     UnsafeAdapter.copyMemory(
         opaqueBytes,
         UnsafeAdapter.BYTE_ARRAY_OFFSET,
         null,
         address[0] + NAME_BYTES + nameBytes.length,
         opaqueBytes.length);
   }
 }
Пример #2
0
 /**
  * Updates the byte size of this metric
  *
  * @return the new byte size of this metric
  */
 protected int updateByteSize() {
   int size = BASE_SIZE + getNameSize() + getOpaqueSize();
   UnsafeAdapter.putInt(address[0] + SIZE, size);
   return size;
 }