Skip to content

Commit

Permalink
Use correct waiting methods for shutdown futures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Dahler committed Jan 3, 2022
1 parent c895e9f commit ba598aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ logger.putProperty("RequestId", "422b1569-16f6-4a03-b8f0-fe3fd9b100f8");
logger.flush();

// flush the sink, waiting up to 10s before giving up
environment.getSink().shutdown().orTimeout(10_000L, TimeUnit.MILLISECONDS);
environment.getSink().shutdown().get(10_000L, TimeUnit.MILLISECONDS);
```

## API
Expand Down
6 changes: 4 additions & 2 deletions examples/agent/src/main/java/agent/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
import software.amazon.cloudwatchlogs.emf.model.Unit;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;

public class App {

public static void main(String[] args) {
public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
DefaultEnvironment environment = new DefaultEnvironment(EnvironmentConfigurationProvider.getConfig());
emitMetric(environment);
emitMetric(environment);
emitMetric(environment);
environment.getSink().shutdown().orTimeout(360_000L, TimeUnit.MILLISECONDS);
environment.getSink().shutdown().get(360_000L, TimeUnit.MILLISECONDS);
}

private static void emitMetric(Environment environment) {
Expand Down
13 changes: 12 additions & 1 deletion examples/ecs-firelens/src/main/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;

public class App {
Expand All @@ -48,7 +50,16 @@ public static void main(String[] args) throws Exception {
private static void registerShutdownHook() {
// https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/
Signal.handle(new Signal("TERM"), sig -> {
env.getSink().shutdown().orTimeout(1_000L, TimeUnit.MILLISECONDS);
try {
env.getSink().shutdown().get(1_000L, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}

e.printStackTrace();
}

System.exit(0);
});
}
Expand Down

0 comments on commit ba598aa

Please sign in to comment.