-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from avaje/feature/preDestroy-priority
Add support for PreDestroy priority to control ordering
- Loading branch information
Showing
21 changed files
with
188 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
public interface HelloData { | ||
|
||
String helloData(); | ||
|
||
default void shutdown() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
blackbox-test-inject/src/main/java/org/example/myapp/MyDestroyOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.example.myapp; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class MyDestroyOrder { | ||
|
||
private static final List<String> ordering = Collections.synchronizedList(new ArrayList<>()); | ||
|
||
public static void add(String val){ | ||
ordering.add(val); | ||
} | ||
|
||
public static List<String> ordering() { | ||
return ordering; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
blackbox-test-inject/src/main/java/org/example/myapp/i347/MyMetaDataRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package org.example.myapp.i347; | ||
|
||
import io.avaje.inject.Component; | ||
import io.avaje.inject.PreDestroy; | ||
import org.example.myapp.MyDestroyOrder; | ||
|
||
@Component | ||
public class MyMetaDataRepo extends MyMongoRepo<MyMetaData> { | ||
@Override | ||
public MyMetaData doThings(MoDocument moDocument) { | ||
return null; | ||
} | ||
|
||
@PreDestroy | ||
void close() { | ||
MyDestroyOrder.add("MyMetaDataRepo"); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
blackbox-test-inject/src/main/java/org/example/myapp/named/MyNamed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package org.example.myapp.named; | ||
|
||
import io.avaje.inject.Component; | ||
import io.avaje.inject.PreDestroy; | ||
import jakarta.inject.Named; | ||
import org.example.myapp.MyDestroyOrder; | ||
|
||
@Named("my-name-with-hyphens") | ||
@Component | ||
public class MyNamed { | ||
|
||
@PreDestroy | ||
public void close() { | ||
MyDestroyOrder.add("MyNamed"); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
blackbox-test-inject/src/test/java/org/example/myapp/MyDestroyOrderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.example.myapp; | ||
|
||
import io.avaje.inject.BeanScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MyDestroyOrderTest { | ||
|
||
@Test | ||
void ordering() { | ||
MyDestroyOrder.ordering().clear(); | ||
try (BeanScope beanScope = BeanScope.builder().build()) { | ||
beanScope.get(HelloService.class); | ||
} | ||
List<String> ordering = MyDestroyOrder.ordering(); | ||
assertThat(ordering).containsExactly("HelloService", "AppConfig", "MyNamed", "MyMetaDataRepo", "ExampleService", "AppHelloData"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.avaje.inject.spi; | ||
|
||
public final class ClosePair implements Comparable<ClosePair> { | ||
|
||
private final int priority; | ||
private final AutoCloseable closeable; | ||
|
||
public ClosePair(int priority, AutoCloseable closeable) { | ||
this.priority = priority; | ||
this.closeable = closeable; | ||
} | ||
|
||
public int priority() { | ||
return priority; | ||
} | ||
|
||
public AutoCloseable closeable() { | ||
return closeable; | ||
} | ||
|
||
@Override | ||
public int compareTo(ClosePair o) { | ||
return Integer.compare(priority, o.priority); | ||
} | ||
} |
Oops, something went wrong.