From f7cf70a2f19d341e2bf71d69444b4d8bef4c1dc2 Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Thu, 21 Jul 2022 13:34:23 +0200 Subject: [PATCH] rpc: drop RpcMessage class Motivation: The RpcMessage class used only the encode message xid and type and always right at the beginning of the xdr stream. As the use case is very limited, the direct encoding of xid ant type can be applyed to avoid additional object allocation. Modification: Drop RpcMessage. Replace RpcMessage#xdrEncode with direct encoding of xid and type. Result: less object alocation Acked-by: Alber Rossi Target: master --- .../java/org/dcache/oncrpc4j/rpc/RpcCall.java | 14 ++--- .../org/dcache/oncrpc4j/rpc/RpcMessage.java | 58 ------------------- .../oncrpc4j/rpc/RpcProtocolFilter.java | 14 +++-- .../oncrpc4j/rpc/RpcMessageParserTCPTest.java | 13 +---- .../oncrpc4j/rpc/RpcProtocolFilterTest.java | 9 +-- 5 files changed, 21 insertions(+), 87 deletions(-) delete mode 100644 oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcMessage.java diff --git a/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcCall.java b/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcCall.java index 53fba203..71f899bf 100644 --- a/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcCall.java +++ b/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcCall.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton, + * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton, * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY * * This library is free software; you can redistribute it and/or modify @@ -295,9 +295,9 @@ public void startTLS() throws IOException { public void reject(int status, XdrAble reason) { XdrEncodingStream xdr = _xdr; try { - RpcMessage replyMessage = new RpcMessage(_xid, RpcMessageType.REPLY); xdr.beginEncoding(); - replyMessage.xdrEncode(_xdr); + xdr.xdrEncodeInt(_xid); + xdr.xdrEncodeInt(RpcMessageType.REPLY); xdr.xdrEncodeInt(RpcReplyStatus.MSG_DENIED); xdr.xdrEncodeInt(status); reason.xdrEncode(_xdr); @@ -324,9 +324,9 @@ public void acceptedReply(int state, XdrAble reply) { XdrEncodingStream xdr = _xdr; try { - RpcMessage replyMessage = new RpcMessage(_xid, RpcMessageType.REPLY); xdr.beginEncoding(); - replyMessage.xdrEncode(_xdr); + xdr.xdrEncodeInt(_xid); + xdr.xdrEncodeInt(RpcMessageType.REPLY); xdr.xdrEncodeInt(RpcReplyStatus.MSG_ACCEPTED); _cred.getVerifier().xdrEncode(xdr); xdr.xdrEncodeInt(state); @@ -459,8 +459,8 @@ private int callInternal(int procedure, XdrAble args, CompletionHandler callback = _replyQueue.get(message.xid()); + RpcReply reply = new RpcReply(xid, xdr, transport); + CompletionHandler callback = _replyQueue.get(xid); if (callback != null) { if (!reply.isAccepted()) { callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport); diff --git a/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcMessageParserTCPTest.java b/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcMessageParserTCPTest.java index 0ac55a00..f270a37d 100644 --- a/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcMessageParserTCPTest.java +++ b/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcMessageParserTCPTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton, + * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton, * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY * * This library is free software; you can redistribute it and/or modify @@ -19,13 +19,6 @@ */ package org.dcache.oncrpc4j.rpc; -import org.dcache.oncrpc4j.rpc.RpcAuth; -import org.dcache.oncrpc4j.rpc.RpcMessageParserTCP; -import org.dcache.oncrpc4j.rpc.RpcMessage; -import org.dcache.oncrpc4j.rpc.ReplyQueue; -import org.dcache.oncrpc4j.rpc.RpcMessageType; -import org.dcache.oncrpc4j.rpc.RpcAuthTypeNone; -import org.dcache.oncrpc4j.rpc.RpcProtocolFilter; import org.dcache.oncrpc4j.xdr.XdrVoid; import org.dcache.oncrpc4j.xdr.XdrAble; import org.dcache.oncrpc4j.xdr.XdrString; @@ -147,8 +140,8 @@ public Xdr build() throws OncRpcException, IOException { Xdr xdr = new Xdr(Xdr.MAX_XDR_SIZE); xdr.beginEncoding(); - RpcMessage rpcMessage = new RpcMessage(xid, RpcMessageType.CALL); - rpcMessage.xdrEncode(xdr); + xdr.xdrEncodeInt(xid); + xdr.xdrEncodeInt(RpcMessageType.CALL); xdr.xdrEncodeInt(rpcvers); xdr.xdrEncodeInt(prog); xdr.xdrEncodeInt(vers); diff --git a/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilterTest.java b/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilterTest.java index 71fb0059..0e442884 100644 --- a/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilterTest.java +++ b/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton, + * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton, * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY * * This library is free software; you can redistribute it and/or modify @@ -19,9 +19,6 @@ */ package org.dcache.oncrpc4j.rpc; -import org.dcache.oncrpc4j.rpc.RpcMessage; -import org.dcache.oncrpc4j.rpc.ReplyQueue; -import org.dcache.oncrpc4j.rpc.RpcProtocolFilter; import org.dcache.oncrpc4j.xdr.Xdr; import java.io.IOException; import org.glassfish.grizzly.Connection; @@ -58,8 +55,8 @@ public void testSomeMethod() throws IOException { private Xdr createBadXdr() { Xdr xdr = new Xdr(32); xdr.beginEncoding(); - RpcMessage rpcMessage = new RpcMessage(1, 2); // xdr, type 0 = call, 1 = reply, 2 = not allowed - rpcMessage.xdrEncode(xdr); + xdr.xdrEncodeInt(1); // xid + xdr.xdrEncodeInt(2); // type: 0 = call, 1 = reply, x = invalid return xdr; } }