Exemplo n.º 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);
   }
 }
Exemplo n.º 2
0
 /** Touches the metric created timestamp */
 protected void touch() {
   UnsafeAdapter.putLong(address[0] + TIMESTAMP, System.currentTimeMillis());
 }
Exemplo n.º 3
0
 /**
  * Updates the id of this metric
  *
  * @param id the new id
  */
 protected void setId(long id) {
   UnsafeAdapter.putLong(address[0] + ID, id);
 }