Skip to content

Commit

Permalink
Refactor static import members to use qualified references (#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinbunney authored Nov 7, 2023
1 parent 5807c1f commit 36e5729
Show file tree
Hide file tree
Showing 38 changed files with 292 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
import io.netty.handler.codec.http2.Http2Settings;
import io.netty.handler.logging.LogLevel;
import io.netty.util.AttributeKey;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.logging.InternalLogLevel;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

import static io.netty.util.internal.ObjectUtil.checkNotNull;

public class DynamicHttp2FrameLogger extends Http2FrameLogger {
public static final AttributeKey<Object> ATTR_ENABLE = AttributeKey.valueOf("http2.frame.logger.enabled");
private static final int BUFFER_LENGTH_THRESHOLD = 64;
Expand All @@ -44,8 +43,8 @@ public class DynamicHttp2FrameLogger extends Http2FrameLogger {

public DynamicHttp2FrameLogger(LogLevel level, Class<?> clazz) {
super(level, clazz);
this.level = checkNotNull(level.toInternalLevel(), "level");
this.logger = checkNotNull(InternalLoggerFactory.getInstance(clazz), "logger");
this.level = ObjectUtil.checkNotNull(level.toInternalLevel(), "level");
this.logger = ObjectUtil.checkNotNull(InternalLoggerFactory.getInstance(clazz), "logger");
}

protected boolean enabled(ChannelHandlerContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.netty.common.proxyprotocol;

import com.google.common.base.Preconditions;
import com.netflix.netty.common.SourceAddressChannelHandler;
import com.netflix.spectator.api.Registry;
import io.netty.buffer.ByteBuf;
Expand All @@ -25,8 +26,6 @@
import io.netty.handler.codec.ProtocolDetectionState;
import io.netty.handler.codec.haproxy.HAProxyMessageDecoder;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Decides if we need to decode a HAProxyMessage. If so, adds the decoder followed by the handler.
* Else, removes itself from the pipeline.
Expand All @@ -39,7 +38,7 @@ public final class ElbProxyProtocolChannelHandler extends ChannelInboundHandlerA

public ElbProxyProtocolChannelHandler(Registry registry, boolean withProxyProtocol) {
this.withProxyProtocol = withProxyProtocol;
this.registry = checkNotNull(registry);
this.registry = Preconditions.checkNotNull(registry);
}

public void addProxyProtocol(ChannelPipeline pipeline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.netty.common.throttle;

import com.netflix.netty.common.ConnectionCloseChannelAttributes;
import com.netflix.netty.common.proxyprotocol.HAProxyMessageChannelHandler;
import com.netflix.zuul.passport.CurrentPassport;
import com.netflix.zuul.passport.PassportState;
import com.netflix.zuul.stats.status.StatusCategory;
Expand All @@ -42,8 +43,6 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.netflix.netty.common.proxyprotocol.HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION;

/**
* A collection of rejection related utilities useful for failing requests. These are tightly coupled with the channel
* pipeline, but can be called from different handlers.
Expand Down Expand Up @@ -304,9 +303,10 @@ private static void notifyHandlers(
}

private static boolean closeConnectionAfterReject(Channel channel) {
if (channel.hasAttr(ATTR_HAPROXY_VERSION)) {
if (channel.hasAttr(HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION)) {
return HAProxyProtocolVersion.V2
== channel.attr(ATTR_HAPROXY_VERSION).get();
== channel.attr(HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION)
.get();
} else {
return false;
}
Expand Down
23 changes: 10 additions & 13 deletions zuul-core/src/main/java/com/netflix/zuul/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@
import com.netflix.zuul.filters.ZuulFilter;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Identifies a {@link ZuulFilter}.
*/
@Target({TYPE})
@Retention(RUNTIME)
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Filter {

Expand All @@ -57,8 +54,8 @@
*/
FilterSyncType sync() default FilterSyncType.SYNC;

@Target({PACKAGE})
@Retention(CLASS)
@Target({ElementType.PACKAGE})
@Retention(RetentionPolicy.CLASS)
@Documented
@interface FilterPackageName {
String value();
Expand All @@ -71,8 +68,8 @@
* this annotation should be used on homogeneous filter types. Additionally, this should not be applied to endpoint
* filters.
*/
@Target({TYPE})
@Retention(RUNTIME)
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface ApplyAfter {
Class<? extends ZuulFilter<?, ?>>[] value();
Expand All @@ -90,8 +87,8 @@
*
* @see ApplyAfter
*/
@Target({TYPE})
@Retention(RUNTIME)
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface ApplyBefore {
Class<? extends ZuulFilter<?, ?>>[] value();
Expand Down
5 changes: 2 additions & 3 deletions zuul-core/src/main/java/com/netflix/zuul/FilterLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
import java.io.File;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.SortedSet;

import static java.util.Objects.requireNonNull;

/**
* This class is one of the core classes in Zuul. It compiles, loads from a File, and checks if source code changed.
* It also holds ZuulFilters by filterType.
Expand Down Expand Up @@ -63,7 +62,7 @@ public interface FilterLoader {

Comparator<Class<? extends ZuulFilter<?, ?>>> FILTER_CLASS_COMPARATOR =
Comparator.<Class<? extends ZuulFilter<?, ?>>>comparingInt(
c -> requireNonNull(c.getAnnotation(Filter.class), () -> "missing annotation: " + c)
c -> Objects.requireNonNull(c.getAnnotation(Filter.class), () -> "missing annotation: " + c)
.order())
.thenComparing(Class::getName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,7 @@

import com.netflix.client.ClientException;
import com.netflix.zuul.stats.status.StatusCategory;

import static com.netflix.client.ClientException.ErrorType.CLIENT_THROTTLED;
import static com.netflix.client.ClientException.ErrorType.CONNECT_EXCEPTION;
import static com.netflix.client.ClientException.ErrorType.GENERAL;
import static com.netflix.client.ClientException.ErrorType.READ_TIMEOUT_EXCEPTION;
import static com.netflix.client.ClientException.ErrorType.SERVER_THROTTLED;
import static com.netflix.client.ClientException.ErrorType.SOCKET_TIMEOUT_EXCEPTION;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_CLIENT_CANCELLED;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_LOCAL;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_LOCAL_THROTTLED_ORIGIN_CONCURRENCY;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_LOCAL_THROTTLED_ORIGIN_SERVER_MAXCONN;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_ORIGIN;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_ORIGIN_CONNECTIVITY;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_ORIGIN_NO_SERVERS;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_ORIGIN_READ_TIMEOUT;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_ORIGIN_RESET_CONNECTION;
import static com.netflix.zuul.stats.status.ZuulStatusCategory.FAILURE_ORIGIN_THROTTLED;
import com.netflix.zuul.stats.status.ZuulStatusCategory;

/**
* Outbound Error Type
Expand All @@ -43,22 +27,40 @@
* Date: November 28, 2017
*/
public enum OutboundErrorType implements ErrorType {
READ_TIMEOUT(ERROR_TYPE_READ_TIMEOUT_STATUS.get(), FAILURE_ORIGIN_READ_TIMEOUT, READ_TIMEOUT_EXCEPTION),
CONNECT_ERROR(ERROR_TYPE_CONNECT_ERROR_STATUS.get(), FAILURE_ORIGIN_CONNECTIVITY, CONNECT_EXCEPTION),
SERVICE_UNAVAILABLE(ERROR_TYPE_SERVICE_UNAVAILABLE_STATUS.get(), FAILURE_ORIGIN_THROTTLED, SERVER_THROTTLED),
ERROR_STATUS_RESPONSE(ERROR_TYPE_ERROR_STATUS_RESPONSE_STATUS.get(), FAILURE_ORIGIN, GENERAL),
NO_AVAILABLE_SERVERS(ERROR_TYPE_NOSERVERS_STATUS.get(), FAILURE_ORIGIN_NO_SERVERS, CONNECT_EXCEPTION),
READ_TIMEOUT(
ERROR_TYPE_READ_TIMEOUT_STATUS.get(),
ZuulStatusCategory.FAILURE_ORIGIN_READ_TIMEOUT,
ClientException.ErrorType.READ_TIMEOUT_EXCEPTION),
CONNECT_ERROR(
ERROR_TYPE_CONNECT_ERROR_STATUS.get(),
ZuulStatusCategory.FAILURE_ORIGIN_CONNECTIVITY,
ClientException.ErrorType.CONNECT_EXCEPTION),
SERVICE_UNAVAILABLE(
ERROR_TYPE_SERVICE_UNAVAILABLE_STATUS.get(),
ZuulStatusCategory.FAILURE_ORIGIN_THROTTLED,
ClientException.ErrorType.SERVER_THROTTLED),
ERROR_STATUS_RESPONSE(
ERROR_TYPE_ERROR_STATUS_RESPONSE_STATUS.get(),
ZuulStatusCategory.FAILURE_ORIGIN,
ClientException.ErrorType.GENERAL),
NO_AVAILABLE_SERVERS(
ERROR_TYPE_NOSERVERS_STATUS.get(),
ZuulStatusCategory.FAILURE_ORIGIN_NO_SERVERS,
ClientException.ErrorType.CONNECT_EXCEPTION),
ORIGIN_SERVER_MAX_CONNS(
ERROR_TYPE_ORIGIN_SERVER_MAX_CONNS_STATUS.get(),
FAILURE_LOCAL_THROTTLED_ORIGIN_SERVER_MAXCONN,
CLIENT_THROTTLED),
RESET_CONNECTION(ERROR_TYPE_ORIGIN_RESET_CONN_STATUS.get(), FAILURE_ORIGIN_RESET_CONNECTION, CONNECT_EXCEPTION),
CANCELLED(400, FAILURE_CLIENT_CANCELLED, SOCKET_TIMEOUT_EXCEPTION),
ZuulStatusCategory.FAILURE_LOCAL_THROTTLED_ORIGIN_SERVER_MAXCONN,
ClientException.ErrorType.CLIENT_THROTTLED),
RESET_CONNECTION(
ERROR_TYPE_ORIGIN_RESET_CONN_STATUS.get(),
ZuulStatusCategory.FAILURE_ORIGIN_RESET_CONNECTION,
ClientException.ErrorType.CONNECT_EXCEPTION),
CANCELLED(400, ZuulStatusCategory.FAILURE_CLIENT_CANCELLED, ClientException.ErrorType.SOCKET_TIMEOUT_EXCEPTION),
ORIGIN_CONCURRENCY_EXCEEDED(
ERROR_TYPE_ORIGIN_CONCURRENCY_EXCEEDED_STATUS.get(),
FAILURE_LOCAL_THROTTLED_ORIGIN_CONCURRENCY,
SERVER_THROTTLED),
OTHER(ERROR_TYPE_OTHER_STATUS.get(), FAILURE_LOCAL, GENERAL);
ZuulStatusCategory.FAILURE_LOCAL_THROTTLED_ORIGIN_CONCURRENCY,
ClientException.ErrorType.SERVER_THROTTLED),
OTHER(ERROR_TYPE_OTHER_STATUS.get(), ZuulStatusCategory.FAILURE_LOCAL, ClientException.ErrorType.GENERAL);

private static final String NAME_PREFIX = "ORIGIN_";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,28 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import static java.util.Objects.requireNonNull;

@Singleton
public final class MutableFilterRegistry implements FilterRegistry {
private final ConcurrentHashMap<String, ZuulFilter<?, ?>> filters = new ConcurrentHashMap<>();

@Nullable
@Override
public ZuulFilter<?, ?> remove(String key) {
return filters.remove(requireNonNull(key, "key"));
return filters.remove(Objects.requireNonNull(key, "key"));
}

@Override
@Nullable
public ZuulFilter<?, ?> get(String key) {
return filters.get(requireNonNull(key, "key"));
return filters.get(Objects.requireNonNull(key, "key"));
}

@Override
public void put(String key, ZuulFilter<?, ?> filter) {
filters.putIfAbsent(requireNonNull(key, "key"), requireNonNull(filter, "filter"));
filters.putIfAbsent(Objects.requireNonNull(key, "key"), Objects.requireNonNull(filter, "filter"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import io.netty.handler.codec.http.HttpContent;
import rx.Observable;

import static com.netflix.zuul.filters.FilterSyncType.SYNC;
import static com.netflix.zuul.filters.FilterType.ENDPOINT;

/**
* Base class to help implement SyncZuulFilter. Note that the class BaseSyncFilter does exist but it derives from
* BaseFilter which in turn creates a new instance of CachedDynamicBooleanProperty for "filterDisabled" every time you
Expand Down Expand Up @@ -59,7 +56,7 @@ public int filterOrder() {

@Override
public FilterType filterType() {
return ENDPOINT;
return FilterType.ENDPOINT;
}

@Override
Expand All @@ -74,7 +71,7 @@ public Observable<O> applyAsync(I input) {

@Override
public FilterSyncType getSyncType() {
return SYNC;
return FilterSyncType.SYNC;
}

@Override
Expand Down
Loading

0 comments on commit 36e5729

Please sign in to comment.