Showing the changes to java/pkg/sun/rmi/transport/ConnectionOutputStream.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,109 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package sun.rmi.transport; | ||
| 27 | |||
| 28 | import java.io.IOException; | ||
| 29 | import java.rmi.server.UID; | ||
| 30 | import sun.rmi.server.MarshalOutputStream; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Special stream to keep track of refs being marshaled as return | ||
| 34 | * results to determine whether a special ack needs to be sent | ||
| 35 | * to the distributed collector. | ||
| 36 | * | ||
| 37 | * @author Ann Wollrath | ||
| 38 | */ | ||
| 39 | class ConnectionOutputStream extends MarshalOutputStream { | ||
| 40 | |||
| 41 | /** connection associated with ConnectionOutputStream */ | ||
| 42 | private final Connection conn; | ||
| 43 | /** indicates whether output stream is used to marshal results */ | ||
| 44 | private final boolean resultStream; | ||
| 45 | /** identifier for gc ack*/ | ||
| 46 | private final UID ackID; | ||
| 47 | |||
| 48 | /** to store refs to returned remote object until DGC ack is received */ | ||
| 49 | private DGCAckHandler dgcAckHandler = null; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Constructs an marshal output stream using the underlying | ||
| 53 | * stream associated with the connection, the parameter c. | ||
| 54 | * @param c is the Connection object associated with the | ||
| 55 | * ConnectionOutputStream object being constructed | ||
| 56 | * @param resultStream indicates whether this stream is used | ||
| 57 | * to marshal return results | ||
| 58 | */ | ||
| 59 | ConnectionOutputStream(Connection conn, boolean resultStream) | ||
| 60 | throws IOException | ||
| 61 | { | ||
| 62 | super(conn.getOutputStream()); | ||
| 63 | this.conn = conn; | ||
| 64 | this.resultStream = resultStream; | ||
| 65 | ackID = resultStream ? new UID() : null; | ||
| 66 | } | ||
| 67 | |||
| 68 | void writeID() throws IOException { | ||
| 69 | assert resultStream; | ||
| 70 | ackID.write(this); | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Returns true if this output stream is used to marshal return | ||
| 75 | * results; otherwise returns false. | ||
| 76 | */ | ||
| 77 | boolean isResultStream() { | ||
| 78 | return resultStream; | ||
| 79 | } | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Saves a reference to the specified object in this stream's | ||
| 83 | * DGCAckHandler. | ||
| 84 | **/ | ||
| 85 | void saveObject(Object obj) { | ||
| 86 | // should always be accessed from same thread | ||
| 87 | if (dgcAckHandler == null) { | ||
| 88 | dgcAckHandler = new DGCAckHandler(ackID); | ||
| 89 | } | ||
| 90 | dgcAckHandler.add(obj); | ||
| 91 | } | ||
| 92 | |||
| 93 | /** | ||
| 94 | * Returns this stream's DGCAckHandler, or null if it doesn't have | ||
| 95 | * one (saveObject was not invoked). This method should only be | ||
| 96 | * invoked after all objects have been written to the stream, | ||
| 97 | * because future objects written may yet cause a DGCAckHandler to | ||
| 98 | * be created (by invoking saveObject). | ||
| 99 | **/ | ||
| 100 | DGCAckHandler getDGCAckHandler() { | ||
| 101 | return dgcAckHandler; | ||
| 102 | } | ||
| 103 | |||
| 104 | void done() { | ||
| 105 | if (dgcAckHandler != null) { | ||
| 106 | dgcAckHandler.startTimer(); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||