in myriad-scheduler/src/main/java/org/apache/myriad/state/utils/ByteBufferSupport.java [107:166]
public static ByteBuffer toByteBuffer(NodeTask nt) {
// Determine the size of ByteBuffer to allocate
// The ServiceResourceProfile toString() returns Json, if this ever changes then this
// will fail. Json is expected.
byte[] profile = toBytes(nt.getProfile().toString());
int size = profile.length + INT_SIZE;
Constraint constraint = nt.getConstraint();
Constraint.Type type = constraint == null ? Type.NULL : constraint.getType();
size += INT_SIZE;
byte[] constraintBytes = ZERO_BYTES;
if (constraint != null) {
constraintBytes = toBytes(constraint.toString());
size += constraintBytes.length + INT_SIZE;
} else {
size += INT_SIZE;
}
byte[] hostname = toBytes(nt.getHostname());
size += hostname.length + INT_SIZE;
if (nt.getSlaveId() != null) {
size += nt.getSlaveId().getSerializedSize() + INT_SIZE;
} else {
size += INT_SIZE;
}
if (nt.getTaskStatus() != null) {
size += nt.getTaskStatus().getSerializedSize() + INT_SIZE;
} else {
size += INT_SIZE;
}
if (nt.getExecutorInfo() != null) {
size += nt.getExecutorInfo().getSerializedSize() + INT_SIZE;
} else {
size += INT_SIZE;
}
byte[] taskPrefixBytes = ZERO_BYTES;
if (nt.getTaskPrefix() != null) {
taskPrefixBytes = toBytes(nt.getTaskPrefix());
size += taskPrefixBytes.length + INT_SIZE;
}
// Allocate and populate the buffer.
ByteBuffer bb = createBuffer(size);
putBytes(bb, profile);
bb.putInt(type.ordinal());
putBytes(bb, constraintBytes);
putBytes(bb, hostname);
putBytes(bb, getSlaveBytes(nt));
putBytes(bb, getTaskBytes(nt));
putBytes(bb, getExecutorInfoBytes(nt));
putBytes(bb, taskPrefixBytes);
// Make sure the buffer is at the beginning
bb.rewind();
return bb;
}