Skip to content

Commit 153ebea

Browse files
NiteshKantstevegury
authored andcommitted
Additional flags in Frame.toString() (#197)
#### Problem Current `Frame.toString()` does not print the various flags associated with different frame types. eg: `requestN` value in `RequestN` frame. This limits the usefulness of frame logging. #### Modifications Added `additionalFlags` string which is generated per frame type. #### Result More insight for frame logging.
1 parent f87d508 commit 153ebea

File tree

1 file changed

+32
-2
lines changed
  • reactivesocket-core/src/main/java/io/reactivesocket

1 file changed

+32
-2
lines changed

reactivesocket-core/src/main/java/io/reactivesocket/Frame.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,11 @@ public String toString() {
541541
FrameType type = FrameType.UNDEFINED;
542542
StringBuilder payload = new StringBuilder();
543543
long streamId = -1;
544+
String additionalFlags = "";
544545

545546
try {
546547
type = FrameHeaderFlyweight.frameType(directBuffer, 0);
548+
547549
ByteBuffer byteBuffer;
548550
byte[] bytes;
549551

@@ -562,9 +564,37 @@ public String toString() {
562564
}
563565

564566
streamId = FrameHeaderFlyweight.streamId(directBuffer, 0);
567+
568+
switch (type) {
569+
case LEASE:
570+
additionalFlags = " Permits: " + Lease.numberOfRequests(this) + ", TTL: " + Lease.ttl(this);
571+
break;
572+
case REQUEST_N:
573+
additionalFlags = " RequestN: " + RequestN.requestN(this);
574+
break;
575+
case KEEPALIVE:
576+
additionalFlags = " Respond flag: " + Keepalive.hasRespondFlag(this);
577+
break;
578+
case REQUEST_STREAM:
579+
case REQUEST_CHANNEL:
580+
additionalFlags = " Initial Request N: " + Request.initialRequestN(this);
581+
break;
582+
case ERROR:
583+
additionalFlags = " Error code: " + Error.errorCode(this);
584+
break;
585+
case SETUP:
586+
additionalFlags = " Version: " + Setup.version(this)
587+
+ ", keep-alive interval: " + Setup.keepaliveInterval(this)
588+
+ ", max lifetime: " + Setup.maxLifetime(this)
589+
+ ", metadata mime type: " + Setup.metadataMimeType(this)
590+
+ ", data mime type: " + Setup.dataMimeType(this);
591+
break;
592+
}
565593
} catch (Exception e) {
566-
e.printStackTrace();
594+
logger.error("Error generating toString, ignored.", e);
567595
}
568-
return "Frame[" + offset + "] => Stream ID: " + streamId + " Type: " + type + " Payload: " + payload;
596+
return "Frame[" + offset + "] => Stream ID: " + streamId + " Type: " + type
597+
+ (!additionalFlags.isEmpty() ? additionalFlags : "")
598+
+ " Payload: " + payload;
569599
}
570600
}

0 commit comments

Comments
 (0)