public Data writeObject(final Object obj) { if (obj == null) { return null; } if (obj instanceof Data) { return (Data) obj; } byte[] bytes = toByteArray(obj); if (bytes == null) { return null; } else { Data data = new Data(bytes); if (obj instanceof PartitionAware) { Data partitionKey = writeObject(((PartitionAware) obj).getPartitionKey()); int partitionHash = (partitionKey == null) ? -1 : partitionKey.getPartitionHash(); data.setPartitionHash(partitionHash); } return data; } }
private <T> int getTaskPartitionId(Callable<T> task) { int partitionId; if (task instanceof PartitionAware) { final Object partitionKey = ((PartitionAware) task).getPartitionKey(); partitionId = getNodeEngine().getPartitionService().getPartitionId(partitionKey); } else { partitionId = random.nextInt(partitionCount); } return partitionId; }