ohnoitsyou commented on code in PR #11945:
URL: https://github.com/apache/nifi/pull/11945#discussion_r4668978504
##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ControlRate.java:
##########
@@ -470,56 +527,26 @@ protected long getCurrentTimeMillis() {
* flowfile attribute, the specified attribute must be present and must be
a long integer.
*/
private boolean isRateAttributeValid(FlowFile flowFile) {
- if (rateControlCriteria == RateControlCriteria.ATTRIBUTE_RATE) {
- final String attributeValue =
flowFile.getAttribute(rateControlAttribute);
+ if (configuration.rateControlCriteria ==
RateControlCriteria.ATTRIBUTE_RATE) {
+ final String attributeValue =
flowFile.getAttribute(configuration.rateControlAttribute);
return attributeValue != null &&
POSITIVE_LONG_PATTERN.matcher(attributeValue).matches();
}
return true;
}
- /*
- * Determine the amount this FlowFile will incur against the maximum
allowed rate.
- * This is applicable to data size accrual only
- */
- private long getDataSizeAccrual(FlowFile flowFile) {
- return flowFile.getSize();
- }
-
- /*
- * Determine the amount this FlowFile will incur against the maximum
allowed rate.
- * This is applicable to counting accruals, FlowFiles or attributes
- */
- private long getCountAccrual(FlowFile flowFile) {
- return switch (rateControlCriteria) {
- case DATA_RATE -> DEFAULT_ACCRUAL_COUNT;
- case FLOWFILE_RATE, DATA_OR_FLOWFILE_RATE -> 1;
- case ATTRIBUTE_RATE -> {
- final String attributeValue =
flowFile.getAttribute(rateControlAttribute);
- if (attributeValue == null) {
- yield DEFAULT_ACCRUAL_COUNT;
- }
-
- if (!POSITIVE_LONG_PATTERN.matcher(attributeValue).matches()) {
- yield DEFAULT_ACCRUAL_COUNT;
- }
- yield Long.parseLong(attributeValue);
- }
- };
- }
-
- private boolean dataThrottleRequired() {
- return rateControlCriteria != null && switch (rateControlCriteria) {
- case DATA_RATE, DATA_OR_FLOWFILE_RATE -> true;
- default -> false;
- };
- }
-
- private boolean countThrottleRequired() {
- return rateControlCriteria != null && switch (rateControlCriteria) {
- case FLOWFILE_RATE, DATA_OR_FLOWFILE_RATE, ATTRIBUTE_RATE -> true;
- default -> false;
- };
- }
+ private record ThrottleConfiguration(
+ RateControlCriteria rateControlCriteria,
+ boolean dataThrottleRequired,
+ boolean countThrottleRequired,
+ long maximumDataRate,
+ long maximumCountRate,
+ String rateControlAttribute,
+ String groupingAttributeName,
+ int timePeriodSeconds,
+ long timePeriodMillis,
Review Comment:
You know, it isn't actually used at at all, correct.
I think this is where my question about the `timePeriod` being used for the
`timedBuffer` in the `Throttle` constructor stemmed from. Both values are
needed in it, but I was hoping to avoid calculating it every time a `Throttle`
was constructed.
It's a tiny enough calculation I'm not going to worry about it.
--
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]