byte type = input.readByte();
byte methodId = (byte) input.readShort();
String cacheName = input.readUTF();
ComponentRegistry registry = gcr.getNamedComponentRegistry(cacheName);
StreamingMarshaller marshaller;
if (registry == null) {
// Even though the command is directed at a cache, it could happen
// that the cache is not yet started, so fallback on global marshaller.
marshaller = gcr.getComponent(
StreamingMarshaller.class, KnownComponentNames.GLOBAL_MARSHALLER);
} else {
marshaller = registry.getComponent(
StreamingMarshaller.class, KnownComponentNames.CACHE_MARSHALLER);
}
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 = commandExt.readParameters(paramsInput);
return commandExt.cmdFactory.fromStream(methodId, args, type, cacheName);
} catch (IOException e) {
throw e;
} finally {
marshaller.finishObjectInput(paramsInput);
}
}