Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add palantir-java-format via spotless. #1332

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
63ff312818a5f70eab9ec5bf80b53bdd7bf80248
22 changes: 22 additions & 0 deletions amazon-kinesis-client-multilang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.30.0</version> <!--last version to support java 8-->
<configuration>
<java>
<palantirJavaFormat />
<importOrder>
<order>java,,\#</order>
</importOrder>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>

</build>

<profiles>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*/
@Slf4j
class DrainChildSTDERRTask extends LineReaderTask<Boolean> {
DrainChildSTDERRTask() {
}
DrainChildSTDERRTask() {}

@Override
protected HandleLineResult<Boolean> handleLine(String line) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@
* This class is used to drain the STDOUT of the child process. After the child process has been given a shutdown
* message and responded indicating that it is shutdown, we attempt to close the input and outputs of that process so
* that the process can exit.
*
*
* To understand why this is necessary, consider the following scenario:
*
*
* <ol>
* <li>Child process responds that it is done with shutdown.</li>
* <li>Child process prints debugging text to STDOUT that fills the pipe buffer so child becomes blocked.</li>
* <li>Parent process doesn't drain child process's STDOUT.</li>
* <li>Child process remains blocked.</li>
* </ol>
*
*
* To prevent the child process from becoming blocked in this way, it is the responsibility of the parent process to
* drain the child process's STDOUT. We reprint each drained line to our log to permit debugging.
*/
@Slf4j
class DrainChildSTDOUTTask extends LineReaderTask<Boolean> {
DrainChildSTDOUTTask() {
}
DrainChildSTDOUTTask() {}

@Override
protected HandleLineResult<Boolean> handleLine(String line) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import java.io.BufferedReader;
import java.io.IOException;

import software.amazon.kinesis.multilang.messages.Message;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.multilang.messages.Message;

/**
* Gets the next message off the STDOUT of the child process. Throws an exception if a message is not found before the
Expand All @@ -34,7 +33,7 @@ class GetNextMessageTask extends LineReaderTask<Message> {

/**
* Constructor.
*
*
* @param objectMapper An object mapper for decoding json messages from the input stream.
*/
GetNextMessageTask(ObjectMapper objectMapper) {
Expand All @@ -43,7 +42,7 @@ class GetNextMessageTask extends LineReaderTask<Message> {

/**
* Checks if a line is an empty line.
*
*
* @param line A string
* @return True if the line is an empty string, i.e. "", false otherwise.
*/
Expand Down Expand Up @@ -71,8 +70,10 @@ protected HandleLineResult<Message> handleLine(String line) {

@Override
protected Message returnAfterException(Exception e) {
throw new RuntimeException("Encountered an error while reading a line from STDIN for shard " + getShardId()
+ " so won't be able to return a message.", e);
throw new RuntimeException(
"Encountered an error while reading a line from STDIN for shard " + getShardId()
+ " so won't be able to return a message.",
e);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* <li> {@link #returnAfterEndOfInput()}</li>
* <li> {@link #returnAfterException(Exception)}</li>
* </ol>
*
*
* @param <T>
*/
@Slf4j
Expand All @@ -41,8 +41,7 @@ abstract class LineReaderTask<T> implements Callable<T> {

private String shardId;

LineReaderTask() {
}
LineReaderTask() {}

/**
* Reads lines off the input stream until a return value is set, or an exception is encountered, or the end of the
Expand Down Expand Up @@ -72,7 +71,7 @@ public T call() throws Exception {
* return from the {@link #call()} function by having a value, indicating that value should be returned immediately
* without reading further, or not having a value, indicating that more lines of input need to be read before
* returning.
*
*
* @param line A line read from the input stream.
* @return HandleLineResult<T> which may or may not have a has return value, indicating to return or not return yet
* respectively.
Expand All @@ -83,7 +82,7 @@ public T call() throws Exception {
* This method will be called if there is an error while reading from the input stream. The return value of this
* method will be returned as the result of this Callable unless an Exception is thrown. If an Exception is thrown
* then that exception will be thrown by the Callable.
*
*
* @param e An exception that occurred while reading from the input stream.
* @return What to return.
*/
Expand All @@ -93,15 +92,15 @@ public T call() throws Exception {
* This method will be called once the end of the input stream is reached. The return value of this method will be
* returned as the result of this Callable. Implementations of this method are welcome to throw a runtime exception
* to indicate that the task was unsuccessful.
*
*
* @return What to return.
*/
protected abstract T returnAfterEndOfInput();

/**
* Allows subclasses to provide more detailed logs. Specifically, this allows the drain tasks and GetNextMessageTask
* to log which shard they're working on.
*
*
* @return The shard id
*/
public String getShardId() {
Expand All @@ -110,7 +109,7 @@ public String getShardId() {

/**
* The description should be a string explaining what this particular LineReader class does.
*
*
* @return The description.
*/
public String getDescription() {
Expand All @@ -121,7 +120,7 @@ public String getDescription() {
* The result of a call to {@link LineReaderTask#handleLine(String)}. Allows implementations of that method to
* indicate whether a particular invocation of that method produced a return for this task or not. If a return value
* doesn't exist the {@link #call()} method will continue to the next line.
*
*
* @param <V>
*/
protected class HandleLineResult<V> {
Expand Down Expand Up @@ -158,7 +157,7 @@ V returnValue() {
* {@link MultiLangShardRecordProcessor#initialize(String)} is called. So we follow a pattern where the attributes are
* set inside this method instead of the constructor so that this object will be initialized when all its attributes
* are known to the record processor.
*
*
* @param stream
* @param shardId
* @param description
Expand All @@ -180,5 +179,4 @@ protected LineReaderTask<T> initialize(BufferedReader reader, String shardId, St
this.description = description;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

import software.amazon.kinesis.multilang.messages.Message;
import com.fasterxml.jackson.databind.ObjectMapper;
import software.amazon.kinesis.multilang.messages.Message;

/**
* Provides methods for interacting with the child process's STDOUT.
*
*
* {@link #getNextMessageFromSTDOUT()} reads lines from the child process's STDOUT and attempts to decode a
* {@link Message} object from each line. A child process's STDOUT could have lines that don't contain data related to
* the multi-language protocol, such as when the child process prints debugging information to its STDOUT (instead of
* logging to a file), also when a child processes writes a Message it is expected to prepend and append a new line
* character to their message to help ensure that it is isolated on a line all by itself which results in empty lines
* being present in STDOUT. Lines which cannot be decoded to a Message object are ignored.
*
*
* {@link #drainSTDOUT()} simply reads all data from the child process's STDOUT until the stream is closed.
*/
class MessageReader {
Expand All @@ -48,19 +48,18 @@ class MessageReader {
/**
* Use the initialize methods after construction.
*/
MessageReader() {
}
MessageReader() {}

/**
* Returns a future which represents an attempt to read the next message in the child process's STDOUT. If the task
* is successful, the result of the future will be the next message found in the child process's STDOUT, if the task
* is unable to find a message before the child process's STDOUT is closed, or reading from STDOUT causes an
* IOException, then an execution exception will be generated by this future.
*
*
* The task employed by this method reads from the child process's STDOUT line by line. The task attempts to decode
* each line into a {@link Message} object. Lines that fail to decode to a Message are ignored and the task
* continues to the next line until it finds a Message.
*
*
* @return
*/
Future<Message> getNextMessageFromSTDOUT() {
Expand All @@ -73,7 +72,7 @@ Future<Message> getNextMessageFromSTDOUT() {
* Returns a future that represents a computation that drains the STDOUT of the child process. That future's result
* is true if the end of the child's STDOUT is reached, its result is false if there was an error while reading from
* the stream. This task will log all the lines it drains to permit debugging.
*
*
* @return
*/
Future<Boolean> drainSTDOUT() {
Expand All @@ -89,19 +88,16 @@ Future<Boolean> drainSTDOUT() {
* {@link MultiLangShardRecordProcessor#initialize(String)} is called. So we follow a pattern where the attributes are
* set inside this method instead of the constructor so that this object will be initialized when all its attributes
* are known to the record processor.
*
*
* @param stream Used to read messages from the subprocess.
* @param shardId The shard we're working on.
* @param objectMapper The object mapper to decode messages.
* @param executorService An executor service to run tasks in.
*/
MessageReader initialize(InputStream stream,
String shardId,
ObjectMapper objectMapper,
ExecutorService executorService) {
return this.initialize(new BufferedReader(new InputStreamReader(stream)), shardId, objectMapper,
executorService);

MessageReader initialize(
InputStream stream, String shardId, ObjectMapper objectMapper, ExecutorService executorService) {
return this.initialize(
new BufferedReader(new InputStreamReader(stream)), shardId, objectMapper, executorService);
}

/**
Expand All @@ -110,10 +106,8 @@ MessageReader initialize(InputStream stream,
* @param objectMapper The object mapper to decode messages.
* @param executorService An executor service to run tasks in.
*/
MessageReader initialize(BufferedReader reader,
String shardId,
ObjectMapper objectMapper,
ExecutorService executorService) {
MessageReader initialize(
BufferedReader reader, String shardId, ObjectMapper objectMapper, ExecutorService executorService) {
this.reader = reader;
this.shardId = shardId;
this.objectMapper = objectMapper;
Expand Down
Loading
Loading