byte[] retval=null;
try {
if(generateTransient) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream out = new MarshalledValueOutputStream(baos);
marshallTransientState(rootNode, out);
out.close();
states[0] = baos.toByteArray();
if (debug) {
log.debug("returning the in-memory state (" + states[0].length +
" bytes)");
}
// Return any state associated with the subtree but not stored in it
if (cache instanceof PojoCache) {
baos = new ByteArrayOutputStream(1024);
out = new MarshalledValueOutputStream(baos);
marshallAssociatedState(fqn, out);
out.close();
states[1] = baos.toByteArray();
if (debug) {
log.debug("returning the associated state (" +
states[1].length + " bytes)");
}
}
}
}
catch(Throwable t) {
log.error("failed getting the in-memory (transient) state", t);
if (!suppressErrors)
throw t;
}
if (generatePersistent) {
try {
if (debug)
log.debug("getting the persistent state");
if (fqn.size() == 0)
states[2] = cache.getCacheLoader().loadEntireState();
else
states[2] = ((ExtendedCacheLoader)cache.getCacheLoader()).loadState(fqn);
if (debug) {
log.debug("returning the persistent state (" +
states[2].length + " bytes)");
}
}
catch(Throwable t) {
log.error("failed getting the persistent state", t);
if (!suppressErrors)
throw t;
}
}
// Package everything into one byte[]
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
MarshalledValueOutputStream out = new MarshalledValueOutputStream(baos);
// Write out the version for reader can know how to integrate
out.writeShort(STATE_TRANSFER_VERSION);
out.writeObject(states);
out.close();
retval = baos.toByteArray();
log.info("returning the state for tree rooted in " + fqn.toString() +
"(" + retval.length + " bytes)");