Skip to content

Commit

Permalink
Format all
Browse files Browse the repository at this point in the history
  • Loading branch information
jguerra committed Sep 14, 2023
1 parent 9532f20 commit c272c65
Show file tree
Hide file tree
Showing 325 changed files with 5,120 additions and 4,516 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package com.netflix.zuul.message;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
Expand All @@ -29,6 +25,10 @@
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;

import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

@State(Scope.Thread)
public class HeadersBenchmark {
Expand All @@ -51,7 +51,9 @@ public void setUp() {
names = new HeaderName[stringNames.length];
values = new String[stringNames.length];
for (int i = 0; i < stringNames.length; i++) {
UUID uuid = new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong());
UUID uuid = new UUID(
ThreadLocalRandom.current().nextLong(),
ThreadLocalRandom.current().nextLong());
String name = uuid.toString();
assert name.length() >= nameLength;
name = name.substring(0, nameLength);
Expand Down Expand Up @@ -84,7 +86,6 @@ public Headers addHeaders_headerName() {
}
}


@State(Scope.Thread)
public static class GetSetHeaders {
@Param({"1", "5", "10", "30"})
Expand All @@ -105,7 +106,9 @@ public void setUp() {
names = new HeaderName[stringNames.length];
values = new String[stringNames.length];
for (int i = 0; i < stringNames.length; i++) {
UUID uuid = new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong());
UUID uuid = new UUID(
ThreadLocalRandom.current().nextLong(),
ThreadLocalRandom.current().nextLong());
String name = uuid.toString();
assert name.length() >= nameLength;
name = name.substring(0, nameLength);
Expand Down Expand Up @@ -152,9 +155,6 @@ public void entries(Blackhole blackhole) {
blackhole.consume(header);
}
}



}

@Benchmark
Expand All @@ -163,5 +163,4 @@ public void entries(Blackhole blackhole) {
public Headers newHeaders() {
return new Headers();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import java.util.Set;

public class DynamicIntegerSetProperty extends DynamicSetProperty<Integer>
{
public class DynamicIntegerSetProperty extends DynamicSetProperty<Integer> {
public DynamicIntegerSetProperty(String propName, String defaultValue) {
super(propName, defaultValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
* Date: 5/15/17
* Time: 4:38 PM
*/
public class PatternListStringProperty extends DerivedStringProperty<List<Pattern>>
{
public class PatternListStringProperty extends DerivedStringProperty<List<Pattern>> {
private static final Logger LOG = LoggerFactory.getLogger(PatternListStringProperty.class);

public PatternListStringProperty(String name, String defaultValue)
{
public PatternListStringProperty(String name, String defaultValue) {
super(name, defaultValue);
}

@Override
protected List<Pattern> derive(String value)
{
protected List<Pattern> derive(String value) {
ArrayList<Pattern> ptns = new ArrayList<>();
if (value != null) {
for (String ptnTxt : value.split(",")) {
try {
ptns.add(Pattern.compile(ptnTxt.trim()));
}
catch (Exception e) {
LOG.error("Error parsing regex pattern list from property! name = {}, value = {}, pattern = {}", String.valueOf(this.getName()), String.valueOf(this.getValue()), String.valueOf(value));
} catch (Exception e) {
LOG.error(
"Error parsing regex pattern list from property! name = {}, value = {}, pattern = {}",
String.valueOf(this.getName()),
String.valueOf(this.getValue()),
String.valueOf(value));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
* Date: 7/17/17
* Time: 10:54 AM
*/
public abstract class AbstrHttpConnectionExpiryHandler extends ChannelOutboundHandlerAdapter
{
protected final static Logger LOG = LoggerFactory.getLogger(AbstrHttpConnectionExpiryHandler.class);
protected final static CachedDynamicLongProperty MAX_EXPIRY_DELTA = new CachedDynamicLongProperty(
"server.connection.expiry.delta", 20 * 1000);
public abstract class AbstrHttpConnectionExpiryHandler extends ChannelOutboundHandlerAdapter {
protected static final Logger LOG = LoggerFactory.getLogger(AbstrHttpConnectionExpiryHandler.class);
protected static final CachedDynamicLongProperty MAX_EXPIRY_DELTA =
new CachedDynamicLongProperty("server.connection.expiry.delta", 20 * 1000);

protected final ConnectionCloseType connectionCloseType;
protected final int maxRequests;
Expand All @@ -48,8 +47,8 @@ public abstract class AbstrHttpConnectionExpiryHandler extends ChannelOutboundHa
protected int requestCount = 0;
protected int maxRequestsUnderBrownout = 0;

public AbstrHttpConnectionExpiryHandler(ConnectionCloseType connectionCloseType, int maxRequestsUnderBrownout, int maxRequests, int maxExpiry)
{
public AbstrHttpConnectionExpiryHandler(
ConnectionCloseType connectionCloseType, int maxRequestsUnderBrownout, int maxRequests, int maxExpiry) {
this.connectionCloseType = connectionCloseType;
this.maxRequestsUnderBrownout = maxRequestsUnderBrownout;
this.maxRequests = maxRequests;
Expand All @@ -61,43 +60,43 @@ public AbstrHttpConnectionExpiryHandler(ConnectionCloseType connectionCloseType,
}

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (isResponseHeaders(msg)) {
// Update the request count attribute for this channel.
requestCount++;

if (isConnectionExpired(ctx.channel())) {
// Flag this channel to be closed after response is written.
Channel channel = HttpUtils.getMainChannel(ctx);
ctx.channel().attr(ConnectionCloseChannelAttributes.CLOSE_AFTER_RESPONSE).set(ctx.newPromise());
ctx.channel()
.attr(ConnectionCloseChannelAttributes.CLOSE_AFTER_RESPONSE)
.set(ctx.newPromise());
ConnectionCloseType.setForChannel(channel, connectionCloseType);
}
}

super.write(ctx, msg, promise);
}

protected boolean isConnectionExpired(Channel channel)
{
boolean expired = requestCount >= maxRequests(channel) ||
System.currentTimeMillis() > connectionExpiryTime;
protected boolean isConnectionExpired(Channel channel) {
boolean expired = requestCount >= maxRequests(channel) || System.currentTimeMillis() > connectionExpiryTime;
if (expired) {
long lifetime = System.currentTimeMillis() - connectionStartTime;
LOG.info("Connection is expired. requestCount={}, lifetime={}, {}",
requestCount, lifetime, ChannelUtils.channelInfoForLogging(channel));
LOG.info(
"Connection is expired. requestCount={}, lifetime={}, {}",
requestCount,
lifetime,
ChannelUtils.channelInfoForLogging(channel));
}
return expired;
}

protected abstract boolean isResponseHeaders(Object msg);

protected int maxRequests(Channel ch)
{
protected int maxRequests(Channel ch) {
if (HttpChannelFlags.IN_BROWNOUT.get(ch)) {
return this.maxRequestsUnderBrownout;
}
else {
} else {
return this.maxRequests;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.netflix.netty.common;

import com.netflix.zuul.message.ZuulMessage;
import com.netflix.zuul.message.http.HttpRequestMessage;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.ReferenceCounted;
import io.netty.util.ResourceLeakDetector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* Date: 6/8/16
* Time: 11:49 AM
*/
public class CategorizedThreadFactory implements ThreadFactory
{
public class CategorizedThreadFactory implements ThreadFactory {
private String category;
private int num = 0;

Expand All @@ -36,8 +35,7 @@ public CategorizedThreadFactory(String category) {
}

public Thread newThread(final Runnable r) {
final FastThreadLocalThread t = new FastThreadLocalThread(r,
category + "-" + num++);
final FastThreadLocalThread t = new FastThreadLocalThread(r, category + "-" + num++);
return t;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
import io.netty.channel.ChannelPromise;
import io.netty.util.AttributeKey;

public class ConnectionCloseChannelAttributes
{
public static final AttributeKey<ChannelPromise> CLOSE_AFTER_RESPONSE = AttributeKey.newInstance("CLOSE_AFTER_RESPONSE");
public class ConnectionCloseChannelAttributes {
public static final AttributeKey<ChannelPromise> CLOSE_AFTER_RESPONSE =
AttributeKey.newInstance("CLOSE_AFTER_RESPONSE");
public static final AttributeKey<ConnectionCloseType> CLOSE_TYPE = AttributeKey.newInstance("CLOSE_TYPE");

public static int gracefulCloseDelay(Channel channel)
{
ChannelConfig channelConfig = channel.attr(BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG).get();
public static int gracefulCloseDelay(Channel channel) {
ChannelConfig channelConfig =
channel.attr(BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG).get();
Integer gracefulCloseDelay = channelConfig.get(CommonChannelConfigKeys.connCloseDelay);
return gracefulCloseDelay == null ? 0 : gracefulCloseDelay;
}

public static boolean allowGracefulDelayed(Channel channel)
{
ChannelConfig channelConfig = channel.attr(BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG).get();
public static boolean allowGracefulDelayed(Channel channel) {
ChannelConfig channelConfig =
channel.attr(BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG).get();
Boolean value = channelConfig.get(CommonChannelConfigKeys.http2AllowGracefulDelayed);
return value == null ? false : value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
* Date: 2/8/17
* Time: 2:04 PM
*/
public enum ConnectionCloseType
{
IMMEDIATE, GRACEFUL, DELAYED_GRACEFUL;
public enum ConnectionCloseType {
IMMEDIATE,
GRACEFUL,
DELAYED_GRACEFUL;

public static ConnectionCloseType fromChannel(Channel ch)
{
ConnectionCloseType type = ch.attr(ConnectionCloseChannelAttributes.CLOSE_TYPE).get();
public static ConnectionCloseType fromChannel(Channel ch) {
ConnectionCloseType type =
ch.attr(ConnectionCloseChannelAttributes.CLOSE_TYPE).get();
if (type == null) {
// Default to immediate.
type = ConnectionCloseType.IMMEDIATE;
}
return type;
}

public static void setForChannel(Channel ch, ConnectionCloseType type)
{
public static void setForChannel(Channel ch, ConnectionCloseType type) {
ch.attr(ConnectionCloseChannelAttributes.CLOSE_TYPE).set(type);
}
}
Loading

0 comments on commit c272c65

Please sign in to comment.