Skip to content

Commit f7cf70a

Browse files
committed
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
1 parent 18c432c commit f7cf70a

File tree

5 files changed

+21
-87
lines changed

5 files changed

+21
-87
lines changed

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcCall.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -295,9 +295,9 @@ public void startTLS() throws IOException {
295295
public void reject(int status, XdrAble reason) {
296296
XdrEncodingStream xdr = _xdr;
297297
try {
298-
RpcMessage replyMessage = new RpcMessage(_xid, RpcMessageType.REPLY);
299298
xdr.beginEncoding();
300-
replyMessage.xdrEncode(_xdr);
299+
xdr.xdrEncodeInt(_xid);
300+
xdr.xdrEncodeInt(RpcMessageType.REPLY);
301301
xdr.xdrEncodeInt(RpcReplyStatus.MSG_DENIED);
302302
xdr.xdrEncodeInt(status);
303303
reason.xdrEncode(_xdr);
@@ -324,9 +324,9 @@ public void acceptedReply(int state, XdrAble reply) {
324324

325325
XdrEncodingStream xdr = _xdr;
326326
try {
327-
RpcMessage replyMessage = new RpcMessage(_xid, RpcMessageType.REPLY);
328327
xdr.beginEncoding();
329-
replyMessage.xdrEncode(_xdr);
328+
xdr.xdrEncodeInt(_xid);
329+
xdr.xdrEncodeInt(RpcMessageType.REPLY);
330330
xdr.xdrEncodeInt(RpcReplyStatus.MSG_ACCEPTED);
331331
_cred.getVerifier().xdrEncode(xdr);
332332
xdr.xdrEncodeInt(state);
@@ -459,8 +459,8 @@ private int callInternal(int procedure, XdrAble args, CompletionHandler<RpcReply
459459

460460
Xdr xdr = new Xdr(Xdr.INITIAL_XDR_SIZE);
461461
xdr.beginEncoding();
462-
RpcMessage rpcMessage = new RpcMessage(xid, RpcMessageType.CALL);
463-
rpcMessage.xdrEncode(xdr);
462+
xdr.xdrEncodeInt(xid);
463+
xdr.xdrEncodeInt(RpcMessageType.CALL);
464464
xdr.xdrEncodeInt(RPCVERS);
465465
xdr.xdrEncodeInt(_prog);
466466
xdr.xdrEncodeInt(_version);

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcMessage.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -50,17 +50,19 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException {
5050

5151
xdr.beginDecoding();
5252

53-
RpcMessage message = new RpcMessage(xdr);
53+
final int xid = xdr.xdrDecodeInt();
54+
final int type = xdr.xdrDecodeInt();
55+
5456
/**
5557
* In case of UDP grizzly does not populates connection with correct destination address.
5658
* We have to get peer address from the request context, which will contain SocketAddress where from
5759
* request was coming.
5860
*/
5961
RpcTransport transport = new GrizzlyRpcTransport(ctx.getConnection(), (InetSocketAddress)ctx.getAddress(), _replyQueue);
6062

61-
switch (message.type()) {
63+
switch (type) {
6264
case RpcMessageType.CALL:
63-
RpcCall call = new RpcCall(message.xid(), xdr, transport);
65+
RpcCall call = new RpcCall(xid, xdr, transport);
6466
try {
6567
call.accept();
6668
ctx.setMessage(call);
@@ -76,8 +78,8 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException {
7678
return ctx.getInvokeAction();
7779
case RpcMessageType.REPLY:
7880
try {
79-
RpcReply reply = new RpcReply(message.xid(), xdr, transport);
80-
CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(message.xid());
81+
RpcReply reply = new RpcReply(xid, xdr, transport);
82+
CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(xid);
8183
if (callback != null) {
8284
if (!reply.isAccepted()) {
8385
callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport);

oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcMessageParserTCPTest.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -19,13 +19,6 @@
1919
*/
2020
package org.dcache.oncrpc4j.rpc;
2121

22-
import org.dcache.oncrpc4j.rpc.RpcAuth;
23-
import org.dcache.oncrpc4j.rpc.RpcMessageParserTCP;
24-
import org.dcache.oncrpc4j.rpc.RpcMessage;
25-
import org.dcache.oncrpc4j.rpc.ReplyQueue;
26-
import org.dcache.oncrpc4j.rpc.RpcMessageType;
27-
import org.dcache.oncrpc4j.rpc.RpcAuthTypeNone;
28-
import org.dcache.oncrpc4j.rpc.RpcProtocolFilter;
2922
import org.dcache.oncrpc4j.xdr.XdrVoid;
3023
import org.dcache.oncrpc4j.xdr.XdrAble;
3124
import org.dcache.oncrpc4j.xdr.XdrString;
@@ -147,8 +140,8 @@ public Xdr build() throws OncRpcException, IOException {
147140
Xdr xdr = new Xdr(Xdr.MAX_XDR_SIZE);
148141
xdr.beginEncoding();
149142

150-
RpcMessage rpcMessage = new RpcMessage(xid, RpcMessageType.CALL);
151-
rpcMessage.xdrEncode(xdr);
143+
xdr.xdrEncodeInt(xid);
144+
xdr.xdrEncodeInt(RpcMessageType.CALL);
152145
xdr.xdrEncodeInt(rpcvers);
153146
xdr.xdrEncodeInt(prog);
154147
xdr.xdrEncodeInt(vers);

oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilterTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -19,9 +19,6 @@
1919
*/
2020
package org.dcache.oncrpc4j.rpc;
2121

22-
import org.dcache.oncrpc4j.rpc.RpcMessage;
23-
import org.dcache.oncrpc4j.rpc.ReplyQueue;
24-
import org.dcache.oncrpc4j.rpc.RpcProtocolFilter;
2522
import org.dcache.oncrpc4j.xdr.Xdr;
2623
import java.io.IOException;
2724
import org.glassfish.grizzly.Connection;
@@ -58,8 +55,8 @@ public void testSomeMethod() throws IOException {
5855
private Xdr createBadXdr() {
5956
Xdr xdr = new Xdr(32);
6057
xdr.beginEncoding();
61-
RpcMessage rpcMessage = new RpcMessage(1, 2); // xdr, type 0 = call, 1 = reply, 2 = not allowed
62-
rpcMessage.xdrEncode(xdr);
58+
xdr.xdrEncodeInt(1); // xid
59+
xdr.xdrEncodeInt(2); // type: 0 = call, 1 = reply, x = invalid
6360
return xdr;
6461
}
6562
}

0 commit comments

Comments
 (0)