Skip to content

Commit

Permalink
Revert changes to metrics interface
Browse files Browse the repository at this point in the history
  • Loading branch information
SupremeMortal committed Jul 23, 2024
1 parent 99e3c51 commit 8128edb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,43 @@

package org.cloudburstmc.netty.channel.raknet.config;

import io.netty.channel.Channel;
import org.cloudburstmc.netty.channel.raknet.RakState;

public interface RakChannelMetrics {

default void bytesIn(Channel channel, int count) {
default void bytesIn(int count) {
}

default void bytesOut(Channel channel, int count) {
default void bytesOut(int count) {
}

default void rakDatagramsIn(Channel channel, int count) {
default void rakDatagramsIn(int count) {
}

default void rakDatagramsOut(Channel channel, int count) {
default void rakDatagramsOut(int count) {
}

default void encapsulatedIn(Channel channel, int count) {
default void encapsulatedIn(int count) {
}

default void encapsulatedOut(Channel channel, int count) {
default void encapsulatedOut(int count) {
}

default void rakStaleDatagrams(Channel channel, int count) {
default void rakStaleDatagrams(int count) {
}

default void ackIn(Channel channel, int count) {
default void ackIn(int count) {
}

default void ackOut(Channel channel, int count) {
default void ackOut(int count) {
}

default void nackIn(Channel channel, int count) {
default void nackOut(int count) {
}

default void nackOut(Channel channel, int count) {
default void nackIn(int count) {
}

default void stateChange(Channel channel, RakState state) {
default void stateChange(RakState state) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
DatagramPacket packet = (DatagramPacket) msg;
RakChannelMetrics metrics = this.channel.config().getMetrics();
if (metrics != null) {
metrics.bytesIn(ctx.channel(), packet.content().readableBytes());
metrics.bytesIn(packet.content().readableBytes());
}

DatagramPacket datagram = packet.retain();
Expand All @@ -69,7 +69,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
DatagramPacket datagram = isDatagram ? (DatagramPacket) msg : new DatagramPacket((ByteBuf) msg, this.channel.remoteAddress());
RakChannelMetrics metrics = this.channel.config().getMetrics();
if (metrics != null) {
metrics.bytesOut(ctx.channel(), datagram.content().readableBytes());
metrics.bytesOut(datagram.content().readableBytes());
}

ctx.write(datagram, promise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buffer) throws Ex
RakChannelMetrics metrics = this.sessionCodec.getMetrics();
if (metrics != null) {
if (nack) {
metrics.nackIn(ctx.channel(), entriesCount);
metrics.nackIn(entriesCount);
} else {
metrics.ackIn(ctx.channel(), entriesCount);
metrics.ackIn(entriesCount);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private void send(ChannelHandlerContext ctx, RakMessage message) {
throw new IllegalArgumentException();
}

getMetrics().encapsulatedOut(ctx.channel(), 1);
getMetrics().encapsulatedOut(1);
EncapsulatedPacket[] packets = this.createEncapsulated(message);
if (message.priority() == RakPriority.IMMEDIATE) {
this.sendImmediate(ctx, packets);
Expand All @@ -259,7 +259,7 @@ private void handleDatagram(ChannelHandlerContext ctx, RakDatagramPacket packet)
this.touch();
RakChannelMetrics metrics = this.getMetrics();
if (metrics != null) {
metrics.rakDatagramsIn(ctx.channel(), 1);
metrics.rakDatagramsIn(1);
}

this.slidingWindow.onPacketReceived(packet.getSendTime());
Expand Down Expand Up @@ -317,14 +317,14 @@ private void handleDatagram(ChannelHandlerContext ctx, RakDatagramPacket packet)
// Not reassembled
continue;
}
getMetrics().encapsulatedIn(ctx.channel(), 1);
getMetrics().encapsulatedIn(1);
try {
this.checkForOrdered(ctx, reassembled);
} finally {
reassembled.release();
}
} else {
getMetrics().encapsulatedIn(ctx.channel(), 1);
getMetrics().encapsulatedIn(1);
this.checkForOrdered(ctx, encapsulated);
}
}
Expand Down Expand Up @@ -468,9 +468,9 @@ private void internalFlush(ChannelHandlerContext ctx) {

RakChannelMetrics metrics = this.getMetrics();
if (metrics != null) {
metrics.nackOut(ctx.channel(), writtenNacks);
metrics.ackOut(ctx.channel(), writtenAcks);
metrics.rakStaleDatagrams(ctx.channel(), resendCount);
metrics.nackOut(writtenNacks);
metrics.ackOut(writtenAcks);
metrics.rakStaleDatagrams(resendCount);
}
}

Expand Down Expand Up @@ -613,7 +613,7 @@ private void sendDatagram(ChannelHandlerContext ctx, RakDatagramPacket datagram,

RakChannelMetrics metrics = this.getMetrics();
if (metrics != null) {
metrics.rakDatagramsOut(ctx.channel(), 1);
metrics.rakDatagramsOut(1);
}

int oldIndex = datagram.getSequenceIndex();
Expand Down Expand Up @@ -796,7 +796,7 @@ private void setState(RakState state) {

RakChannelMetrics metrics = this.getMetrics();
if (metrics != null) {
metrics.stateChange(channel, state);
metrics.stateChange(state);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

RakChannelMetrics metrics = this.channel.config().getMetrics();
if (metrics != null) {
metrics.bytesOut(ctx.channel(), datagram.content().readableBytes());
metrics.bytesOut(datagram.content().readableBytes());
}

Channel parent = this.channel.parent().parent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

RakChannelMetrics metrics = channel.config().getMetrics();
if (metrics != null) {
metrics.bytesIn(ctx.channel(), packet.content().readableBytes());
metrics.bytesIn(packet.content().readableBytes());
}

// In this case remote address is already known from ChannelHandlerContext
Expand Down

0 comments on commit 8128edb

Please sign in to comment.