|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream java.io.ObjectOutputStream orc.trace.handles.HandleOutputStream
public final class HandleOutputStream
Used in conjunction with Handle
to explicitly manage the lifetime of
serialized references. Use it like this:
Handle
.ObjectOutputStream.reset()
regularly to keep the output
stream from wasting memory.Handle
s are not affected by ObjectOutputStream.reset()
; instead, the
order in which Handle
s are constructed and serialized determines
when the output stream forgets about them.
Some background on the problem this solves: the standard
ObjectOutputStream
uses a cache of every object it has seen in order
to serialize pointers. This prevents the objects from being GCed. You can
clear the cache with a call to ObjectOutputStream.reset()
, but then
pointers will no longer be correct.
Why doesn't ObjectOutputStream
just use a weak hash map? That would
be fine for writing, but it wouldn't work for reading. Reading still needs to
cache pointer values to reconstruct the object graph, but it can't tell when
it has seen the last reference to an object in the input file.
The solution implemented here is to allow pointers to be reset on an individual basis, so that both the output and input streams can tell when they have seen the last pointer to an object and clear the object from their caches.
HandleOutputStream
,
Handle
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.io.ObjectOutputStream |
---|
java.io.ObjectOutputStream.PutField |
Field Summary |
---|
Fields inherited from interface java.io.ObjectStreamConstants |
---|
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING |
Constructor Summary | |
---|---|
HandleOutputStream(java.io.OutputStream out)
|
|
HandleOutputStream(java.io.OutputStream out,
int resetInterval)
The reset interval determines how often maybeReset() actually resets. |
Method Summary | |
---|---|
void |
freeHandle(java.lang.Object value)
Free the handle ID associated with the given value. |
int |
getHandle(java.lang.Object value)
Return the handle ID associated with a handle value. |
void |
maybeReset()
This uses the reset interval set by setResetInterval(int) or
HandleOutputStream(OutputStream, int) to decide whether to
reset the output stream. |
int |
newHandle(java.lang.Object value)
Create and return a new handle ID for the given value. |
void |
setResetInterval(int resetInterval)
Change the reset interval. |
Methods inherited from class java.io.ObjectOutputStream |
---|
annotateClass, annotateProxyClass, close, defaultWriteObject, drain, enableReplaceObject, flush, putFields, replaceObject, reset, useProtocolVersion, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeClassDescriptor, writeDouble, writeFields, writeFloat, writeInt, writeLong, writeObject, writeObjectOverride, writeShort, writeStreamHeader, writeUnshared, writeUTF |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HandleOutputStream(java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public HandleOutputStream(java.io.OutputStream out, int resetInterval) throws java.io.IOException
maybeReset()
actually resets.
java.io.IOException
Method Detail |
---|
public void setResetInterval(int resetInterval)
maybeReset()
.
public void maybeReset() throws java.io.IOException
setResetInterval(int)
or
HandleOutputStream(OutputStream, int)
to decide whether to
reset the output stream. The default (safe) behavior is to always reset.
java.io.IOException
public int getHandle(java.lang.Object value)
public int newHandle(java.lang.Object value) throws java.io.IOException
java.io.IOException
public void freeHandle(java.lang.Object value)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |