Skip to content

Commit

Permalink
Format code base using palantir plugin (#1642)
Browse files Browse the repository at this point in the history
* Apply NeedBraces rule

* add palantir format plugin

* Format all

* Add missing overrides

* Fix bad override

* Remove unused recipes
  • Loading branch information
jguerra authored Sep 14, 2023
1 parent 7ff79a3 commit 7a375f5
Show file tree
Hide file tree
Showing 327 changed files with 5,300 additions and 4,569 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
buildscript {
dependencies {
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.36.0'
}
}

plugins {
id 'com.netflix.nebula.netflixoss' version '11.3.2'
id "com.google.osdetector" version "1.7.3"
Expand Down Expand Up @@ -32,6 +38,7 @@ subprojects {
apply plugin: 'com.netflix.nebula.dependency-lock'
apply plugin: 'me.champeau.jmh'
apply plugin: 'org.openrewrite.rewrite'
apply plugin: 'com.palantir.java-format'

license {
ignoreFailures = false
Expand Down Expand Up @@ -86,6 +93,7 @@ subprojects {

dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.2.1"))
rewrite("org.openrewrite.recipe:rewrite-static-analysis:1.0.7")
rewrite("org.openrewrite.recipe:rewrite-logging-frameworks")
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks")
}
Expand All @@ -94,6 +102,7 @@ rewrite {
failOnDryRunResults = true
activeRecipe("org.openrewrite.java.testing.junit5.JUnit5BestPractices")
activeRecipe("org.openrewrite.java.logging.slf4j.Slf4jBestPractices")

exclusion(
// Exclude all groovy files
"**/*.groovy")
Expand Down
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 @@ -35,9 +34,9 @@ public CategorizedThreadFactory(String category) {
this.category = category;
}

@Override
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 7a375f5

Please sign in to comment.