-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Niang <[email protected]>
- Loading branch information
Showing
6 changed files
with
82 additions
and
4 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
34 changes: 34 additions & 0 deletions
34
application/src/main/java/run/halo/app/plugin/DefaultSharedEventListenerRegistry.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,34 @@ | ||
package run.halo.app.plugin; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DefaultSharedEventListenerRegistry implements | ||
ApplicationListener<ApplicationEvent>, SharedEventListenerRegistry { | ||
|
||
private final List<ApplicationListener<ApplicationEvent>> listeners; | ||
|
||
public DefaultSharedEventListenerRegistry() { | ||
listeners = new CopyOnWriteArrayList<>(); | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationEvent event) { | ||
if (!event.getClass().isAnnotationPresent(SharedEvent.class)) { | ||
return; | ||
} | ||
listeners.forEach(listener -> listener.onApplicationEvent(event)); | ||
} | ||
|
||
public void register(ApplicationListener<ApplicationEvent> listener) { | ||
this.listeners.add(listener); | ||
} | ||
|
||
public void unregister(ApplicationListener<ApplicationEvent> listener) { | ||
this.listeners.remove(listener); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../app/PluginApplicationContextFactory.java → ...ugin/PluginApplicationContextFactory.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,4 +1,4 @@ | ||
package run.halo.app; | ||
package run.halo.app.plugin; | ||
|
||
import org.springframework.context.ApplicationContext; | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
application/src/main/java/run/halo/app/plugin/SharedEventListenerRegistry.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,12 @@ | ||
package run.halo.app.plugin; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
public interface SharedEventListenerRegistry { | ||
|
||
void register(ApplicationListener<ApplicationEvent> listener); | ||
|
||
void unregister(ApplicationListener<ApplicationEvent> listener); | ||
|
||
} |
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