Path: blob/master/src/java.rmi/share/classes/sun/rmi/transport/ConnectionOutputStream.java
41154 views
/*1* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.rmi.transport;2627import java.io.IOException;28import java.rmi.server.UID;29import sun.rmi.server.MarshalOutputStream;3031/**32* Special stream to keep track of refs being marshaled as return33* results to determine whether a special ack needs to be sent34* to the distributed collector.35*36* @author Ann Wollrath37*/38class ConnectionOutputStream extends MarshalOutputStream {3940/** connection associated with ConnectionOutputStream */41private final Connection conn;42/** indicates whether output stream is used to marshal results */43private final boolean resultStream;44/** identifier for gc ack*/45private final UID ackID;4647/** to store refs to returned remote object until DGC ack is received */48private DGCAckHandler dgcAckHandler = null;4950/**51* Constructs an marshal output stream using the underlying52* stream associated with the connection, the parameter c.53* @param c is the Connection object associated with the54* ConnectionOutputStream object being constructed55* @param resultStream indicates whether this stream is used56* to marshal return results57*/58ConnectionOutputStream(Connection conn, boolean resultStream)59throws IOException60{61super(conn.getOutputStream());62this.conn = conn;63this.resultStream = resultStream;64ackID = resultStream ? new UID() : null;65}6667void writeID() throws IOException {68assert resultStream;69ackID.write(this);70}7172/**73* Returns true if this output stream is used to marshal return74* results; otherwise returns false.75*/76boolean isResultStream() {77return resultStream;78}7980/**81* Saves a reference to the specified object in this stream's82* DGCAckHandler.83**/84void saveObject(Object obj) {85// should always be accessed from same thread86if (dgcAckHandler == null) {87dgcAckHandler = new DGCAckHandler(ackID);88}89dgcAckHandler.add(obj);90}9192/**93* Returns this stream's DGCAckHandler, or null if it doesn't have94* one (saveObject was not invoked). This method should only be95* invoked after all objects have been written to the stream,96* because future objects written may yet cause a DGCAckHandler to97* be created (by invoking saveObject).98**/99DGCAckHandler getDGCAckHandler() {100return dgcAckHandler;101}102103void done() {104if (dgcAckHandler != null) {105dgcAckHandler.startTimer();106}107}108}109110111