/* VETk - A Virtual Environment Toolkit.
 * Package BAMI, Bidirectional Asynchronous Method Invocation.
 * VETk is distributed under the BSD license.  No warranty; see `LICENSE' for
 * more details.  Created by B.W. van Schooten (schooten@cs.utwente.nl)
 *
 * (pre-CVS updates)
 * Created approx. 6 jul 2000
 */

package vetk.bami;
import java.io.*;

/** Variant of ObjectOutputStream that resets the stream periodically, to
* avoid the horrid memory leak resulting from constantly passing new
* objects. This does mean that passing the same object twice does not imply
* that the recipient gets the same reference twice.
*/
public class ValueObjectOutputStream extends ObjectOutputStream {

	int reset_threshold;
	int reset_count=0;

	public ValueObjectOutputStream(OutputStream out, int reset_threshold)
	throws IOException {
		super(out);
		this.reset_threshold=reset_threshold;
	}
/* not needed, not found in jdk1.1 either...
	public ValueObjectOutputStream(int reset_threshold)
	throws IOException {
		super();
		this.reset_threshold=reset_threshold;
	}
*/
	public void writeValueObject(Object obj) throws IOException {
		writeObject(obj);
		if (reset_count++ >= reset_threshold) {
			reset();
			reset_count=0;
		}
	}
}


