public CacheRpcCommand readObject(ObjectInput input) throws IOException, ClassNotFoundException {
byte type = input.readByte();
byte methodId = (byte) input.readShort();
String cacheName = input.readUTF();
StreamingMarshaller marshaller = getCacheMarshaller(cacheName);
byte[] paramsRaw = new byte[UnsignedNumeric.readUnsignedInt(input)];
// This is not ideal cos it forces the code to read all parameters into
// memory and then splitting them, potentially leading to excessive
// buffering. An alternative solution is shown in SharedStreamMultiMarshallerTest
// but it requires some special treatment - iow, hacking :)
input.readFully(paramsRaw);
ByteArrayInputStream is = new ByteArrayInputStream(paramsRaw, 0, paramsRaw.length);
ObjectInput paramsInput = marshaller.startObjectInput(is, true);
// Not ideal, but the alternative (without changing API), would have been
// using thread locals which are expensive to retrieve.
// Remember that the aim with externalizers is for them to be stateless.
if (paramsInput instanceof ExtendedRiverUnmarshaller)
((ExtendedRiverUnmarshaller) paramsInput).setInfinispanMarshaller(marshaller);
try {
Object[] args = cmdExt.readParameters(paramsInput);
CacheRpcCommand cacheRpcCommand = cmdExt.fromStream(methodId, args, type, cacheName);
if (cacheRpcCommand instanceof TopologyAffectedCommand) {
int topologyId = input.readInt();
((TopologyAffectedCommand)cacheRpcCommand).setTopologyId(topologyId);
}
return cacheRpcCommand;
} finally {
marshaller.finishObjectInput(paramsInput);
}
}