Skip to content

Commit

Permalink
Revert "Simplify OutputStream constructor in Java - See zeroc-ice#2595"
Browse files Browse the repository at this point in the history
This reverts commit 6d845de.
  • Loading branch information
pepone committed Oct 2, 2024
1 parent 2f5bcff commit c9f2b1e
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public BatchRequestQueue(Instance instance, boolean datagram) {
_interceptor = initData.batchRequestInterceptor;
_batchStreamInUse = false;
_batchRequestNum = 0;
_batchStream =
new OutputStream(
Protocol.currentProtocolEncoding,
instance.defaultsAndOverrides().defaultFormat);
_batchStream = new OutputStream(instance, Protocol.currentProtocolEncoding);
_batchStream.writeBlob(Protocol.requestBatchHdr);
_batchMarker = _batchStream.size();
_batchCompress = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ private void dispatchAll(OutputStream os, int requestId, int requestCount) {
} else if (requestCount > 0) {
fillInValue(os, Protocol.headerSize, requestCount);
}
TraceUtil.traceSend(os, _reference.getInstance(), _logger, _traceLevels);
TraceUtil.traceSend(os, _logger, _traceLevels);
}

var is = new InputStream(_reference.getInstance(), os.getEncoding(), os.getBuffer(), false);
var is = new InputStream(os.instance(), os.getEncoding(), os.getBuffer(), false);

if (requestCount > 0) {
is.pos(Protocol.requestBatchHdr.length);
Expand Down Expand Up @@ -248,7 +248,7 @@ private void sendResponse(OutgoingResponse response, int requestId, boolean amd)
// Adopt the OutputStream's buffer.
var inputStream =
new InputStream(
_reference.getInstance(),
outputStream.instance(),
outputStream.getEncoding(),
outputStream.getBuffer(),
true); // adopt: true
Expand Down
24 changes: 16 additions & 8 deletions java/src/Ice/src/main/java/com/zeroc/Ice/ConnectionI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ public synchronized void sendHeartbeat() {
// As a result of this optimization, the only possible heartbeat in _sendStreams is the
// first _sendStreams message.
if (_sendStreams.isEmpty()) {
OutputStream os = new OutputStream(Protocol.currentProtocolEncoding);
OutputStream os = new OutputStream(_instance, Protocol.currentProtocolEncoding);
os.writeBlob(Protocol.magic);
Protocol.currentProtocol.ice_writeMembers(os);
Protocol.currentProtocolEncoding.ice_writeMembers(os);
Expand Down Expand Up @@ -1280,7 +1280,7 @@ public ConnectionI(
_readStream = new InputStream(instance, Protocol.currentProtocolEncoding);
_readHeader = false;
_readStreamPos = -1;
_writeStream = new OutputStream(); // temporary stream
_writeStream = new OutputStream(instance, Protocol.currentProtocolEncoding);
_writeStreamPos = -1;
_upcallCount = 0;
_state = StateNotInitialized;
Expand Down Expand Up @@ -1586,7 +1586,7 @@ private void initiateShutdown() {
//
// Before we shut down, we send a close connection message.
//
OutputStream os = new OutputStream(Protocol.currentProtocolEncoding);
OutputStream os = new OutputStream(_instance, Protocol.currentProtocolEncoding);
os.writeBlob(Protocol.magic);
Protocol.currentProtocol.ice_writeMembers(os);
Protocol.currentProtocolEncoding.ice_writeMembers(os);
Expand Down Expand Up @@ -1670,7 +1670,7 @@ private boolean validate(int operation) {
// (always zero for
// validate connection).
_writeStream.writeInt(Protocol.headerSize); // Message size.
TraceUtil.traceSend(_writeStream, _instance, _logger, _traceLevels);
TraceUtil.traceSend(_writeStream, _logger, _traceLevels);
_writeStream.prepareWrite();
}

Expand Down Expand Up @@ -1861,7 +1861,7 @@ private int sendNextMessage(java.util.List<OutgoingMessage> callbacks) {
message.stream.prepareWrite();
message.prepared = true;

TraceUtil.traceSend(stream, _instance, _logger, _traceLevels);
TraceUtil.traceSend(stream, _logger, _traceLevels);

//
// Send the message.
Expand Down Expand Up @@ -1927,7 +1927,7 @@ private int sendMessage(OutgoingMessage message) {
message.stream.prepareWrite();
message.prepared = true;
int op;
TraceUtil.traceSend(stream, _instance, _logger, _traceLevels);
TraceUtil.traceSend(stream, _logger, _traceLevels);

// Send the message without blocking.
if (_observer != null) {
Expand Down Expand Up @@ -1981,7 +1981,9 @@ private OutputStream doCompress(OutputStream uncompressed, boolean compress) {
BZip2.compress(
uncompressed.getBuffer(), Protocol.headerSize, _compressionLevel);
if (cbuf != null) {
var cstream = new OutputStream(new Buffer(cbuf, true), uncompressed.getEncoding());
OutputStream cstream =
new OutputStream(
uncompressed.instance(), uncompressed.getEncoding(), cbuf, true);

//
// Set compression status.
Expand Down Expand Up @@ -2248,11 +2250,16 @@ private void dispatchAll(
}
} else {
// Received request on a connection without an object adapter.
// TODO: fix #2595
System.err.println(
"*************** Received request on a connection without an object adapter.");
/*
sendResponse(
request.current.createOutgoingResponse(
new com.zeroc.Ice.ObjectNotExistException()),
isTwoWay,
(byte) 0);
*/
}
--requestCount;
}
Expand Down Expand Up @@ -2604,7 +2611,8 @@ public void canceled() {

public void adopt() {
if (adopt) {
var stream = new OutputStream(Protocol.currentProtocolEncoding);
OutputStream stream =
new OutputStream(this.stream.instance(), Protocol.currentProtocolEncoding);
stream.swap(this.stream);
this.stream = stream;
adopt = false;
Expand Down
12 changes: 2 additions & 10 deletions java/src/Ice/src/main/java/com/zeroc/Ice/Current.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ private OutgoingResponse createOutgoingResponseCore(Throwable exc) {
OutputStream ostr;

if (requestId != 0) {
// The default class format doesn't matter since we always encode user exceptions in
// Sliced format.
ostr = new OutputStream(Protocol.currentProtocolEncoding);
ostr = new OutputStream(adapter.getCommunicator(), Protocol.currentProtocolEncoding);
ostr.writeBlob(Protocol.replyHdr);
ostr.writeInt(requestId);
} else {
Expand Down Expand Up @@ -327,13 +325,7 @@ private OutputStream startReplyStream(ReplyStatus replyStatus) {
return new OutputStream();
} else {
var ostr =
new OutputStream(
Protocol.currentProtocolEncoding,
this.adapter
.getCommunicator()
.getInstance()
.defaultsAndOverrides()
.defaultFormat);
new OutputStream(adapter.getCommunicator(), Protocol.currentProtocolEncoding);
ostr.writeBlob(Protocol.replyHdr);
ostr.writeInt(requestId);
ostr.writeByte(replyStatus.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public synchronized EndpointI create(String str, boolean oaEndpoint) {
// and ask the factory to read the endpoint data from that stream to create
// the actual endpoint.
//
var os = new OutputStream(Protocol.currentProtocolEncoding);
var os = new OutputStream(_instance, Protocol.currentProtocolEncoding, false);
os.writeShort(ue.type());
ue.streamWrite(os);
var is =
Expand Down
5 changes: 1 addition & 4 deletions java/src/Ice/src/main/java/com/zeroc/Ice/OutgoingAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public OutgoingAsync(
}
}
if (_os == null) {
_os =
new OutputStream(
Protocol.currentProtocolEncoding,
_instance.defaultsAndOverrides().defaultFormat);
_os = new OutputStream(_instance, Protocol.currentProtocolEncoding);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ public T waitForResponse() {

protected OutgoingAsyncBase(Communicator com, Instance instance, String op) {
super(com, instance, op);
_os =
new OutputStream(
Protocol.currentProtocolEncoding,
instance.defaultsAndOverrides().defaultFormat);
_os = new OutputStream(instance, Protocol.currentProtocolEncoding);
}

protected OutgoingAsyncBase(Communicator com, Instance instance, String op, OutputStream os) {
Expand Down
Loading

0 comments on commit c9f2b1e

Please sign in to comment.