smiklosovic commented on code in PR #2058: URL: https://github.com/apache/cassandra/pull/2058#discussion_r1065083290
########## src/java/org/apache/cassandra/db/streaming/FileStreamMetricsListener.java: ########## @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.db.streaming; + +import javax.annotation.Nonnull; + +import com.google.common.annotations.VisibleForTesting; + +import com.codahale.metrics.Counter; +import org.apache.cassandra.locator.InetAddressAndPort; +import org.apache.cassandra.metrics.StreamingMetrics; +import org.apache.cassandra.streaming.ProgressInfo; + +/** + * Used to keep track of the bytes streamed for a given file as bytes of the file are transferred and report them to StreamingMetrics. + */ +public class FileStreamMetricsListener +{ + @VisibleForTesting + static final FileStreamMetricsListener NO_OP = new FileStreamMetricsListener() + { + @Override + public void onStreamingBytesTransferred(long cumulativeBytesTransferred) + { + //no-op + } + + @Override + public void onStreamSuccessful() + { + //no-op + } + }; + + private final long totalSize; + private final Counter totalOutgoingBytesStreamed; + private final Counter peerOutgoingBytesStreamed; + private long lastSeenBytes = 0L; + + public FileStreamMetricsListener(long totalSize, InetAddressAndPort peer, @Nonnull ProgressInfo.Direction direction) + { + this.totalSize = totalSize; + if (direction == ProgressInfo.Direction.OUT) + { + this.totalOutgoingBytesStreamed = StreamingMetrics.totalOutgoingBytes; + this.peerOutgoingBytesStreamed = StreamingMetrics.get(peer).outgoingBytes; + } + else + { + this.totalOutgoingBytesStreamed = StreamingMetrics.totalIncomingBytes; + this.peerOutgoingBytesStreamed = StreamingMetrics.get(peer).incomingBytes; + } + } + + @VisibleForTesting + public FileStreamMetricsListener(long totalSize, Counter totalOutgoingBytesStreamed, Counter peerOutgoingBytesStreamed) Review Comment: @isaacreath just checking if this needs to be explicitly `public` or it may be package protected. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

