io.quarkus.load.shedding.runtime.HttpRequestClassifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-load-shedding Show documentation
Show all versions of quarkus-load-shedding Show documentation
Shed excess load and keep your service available
package io.quarkus.load.shedding.runtime;
import jakarta.inject.Singleton;
import io.quarkus.load.shedding.RequestClassifier;
import io.vertx.core.http.HttpServerRequest;
@Singleton
public class HttpRequestClassifier implements RequestClassifier {
@Override
public boolean appliesTo(Object request) {
return request instanceof HttpServerRequest;
}
@Override
public int cohort(HttpServerRequest request) {
int hour = (int) (System.currentTimeMillis() >> 22); // roughly 1 hour
String host = request.remoteAddress().hostAddress();
if (host == null) {
host = "";
}
return hour + host.hashCode();
}
}