context.put("connection", connection);
context.setRemoteEntityID(connection.id);
try {
kryo.writeClassAndObject(tempWriteBuffer, object);
} catch (SerializationException ex) {
throw new SerializationException("Unable to serialize object of type: " + object.getClass().getName(), ex);
}
tempWriteBuffer.flip();
// Write data length.
int dataLength = tempWriteBuffer.limit() - 5;
int lengthLength = IntSerializer.length(dataLength, true);
int start = 5 - lengthLength;
tempWriteBuffer.position(start);
IntSerializer.put(tempWriteBuffer, dataLength, true);
tempWriteBuffer.position(start);
try {
if (writeBuffer.position() > 0) {
// Other data is already queued, append this data to be written later.
writeBuffer.put(tempWriteBuffer);
} else if (!writeToSocket(tempWriteBuffer)) {
// A partial write occurred, queue the remaining data to be written later.
writeBuffer.put(tempWriteBuffer);
// Set OP_WRITE to be notified when more writing can occur.
selectionKey.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
}
} catch (BufferOverflowException ex) {
throw new SerializationException(
"Write buffer limit exceeded writing object of type: " + object.getClass().getName(), ex);
}
if (DEBUG || TRACE) {
float percentage = writeBuffer.position() / (float)writeBuffer.capacity();