Skip to content

Commit 93fd9aa

Browse files
Feature/destroy filter method (#133)
* Create destroy method * Create stop method * Add stop method to ShutdownHook * Add try/catch/finally to shutdownhook
1 parent a5321d2 commit 93fd9aa

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/org/juv25d/App.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.juv25d.router.SimpleRouter;
88
import org.juv25d.util.ConfigLoader;
99

10+
import java.util.logging.Level;
1011
import java.util.logging.Logger;
1112

1213
public class App {
@@ -32,7 +33,15 @@ public static void main(String[] args) {
3233
);
3334

3435
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
35-
logger.info("Server shutting down...");
36+
logger.info("Shutting down...");
37+
try {
38+
pipeline.stop();
39+
logger.info("Shutdown successful");
40+
}catch (Exception ex){
41+
logger.log(Level.SEVERE, "Error stopping server", ex);
42+
}finally {
43+
logger.info("Shutdown hook finished");
44+
}
3645
}));
3746

3847
server.start();

src/main/java/org/juv25d/Pipeline.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ public FilterChainImpl createChain(HttpRequest request) {
2222
List<Filter> filters = matcher.match(request);
2323
return new FilterChainImpl(filters, router);
2424
}
25+
26+
public void stop() {
27+
matcher.destroy();
28+
}
2529
}

src/main/java/org/juv25d/filter/FilterMatcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ private boolean matches(String pattern, String path) {
4242

4343
return false;
4444
}
45+
46+
public void destroy() {
47+
registry.shutdown();
48+
}
4549
}

0 commit comments

Comments
 (0)