@@ -10562,12 +10562,12 @@ simple class that extends Spring's `ApplicationEvent` base class:
10562
10562
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
10563
10563
.Java
10564
10564
----
10565
- public class BlackListEvent extends ApplicationEvent {
10565
+ public class BlockedListEvent extends ApplicationEvent {
10566
10566
10567
10567
private final String address;
10568
10568
private final String content;
10569
10569
10570
- public BlackListEvent (Object source, String address, String content) {
10570
+ public BlockedListEvent (Object source, String address, String content) {
10571
10571
super(source);
10572
10572
this.address = address;
10573
10573
this.content = content;
@@ -10579,7 +10579,7 @@ simple class that extends Spring's `ApplicationEvent` base class:
10579
10579
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
10580
10580
.Kotlin
10581
10581
----
10582
- class BlackListEvent (source: Any,
10582
+ class BlockedListEvent (source: Any,
10583
10583
val address: String,
10584
10584
val content: String) : ApplicationEvent(source)
10585
10585
----
@@ -10594,20 +10594,20 @@ example shows such a class:
10594
10594
----
10595
10595
public class EmailService implements ApplicationEventPublisherAware {
10596
10596
10597
- private List<String> blackList ;
10597
+ private List<String> blockedList ;
10598
10598
private ApplicationEventPublisher publisher;
10599
10599
10600
- public void setBlackList (List<String> blackList ) {
10601
- this.blackList = blackList ;
10600
+ public void setBlockedList (List<String> blockedList ) {
10601
+ this.blockedList = blockedList ;
10602
10602
}
10603
10603
10604
10604
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
10605
10605
this.publisher = publisher;
10606
10606
}
10607
10607
10608
10608
public void sendEmail(String address, String content) {
10609
- if (blackList .contains(address)) {
10610
- publisher.publishEvent(new BlackListEvent (this, address, content));
10609
+ if (blockedList .contains(address)) {
10610
+ publisher.publishEvent(new BlockedListEvent (this, address, content));
10611
10611
return;
10612
10612
}
10613
10613
// send email...
@@ -10619,20 +10619,20 @@ example shows such a class:
10619
10619
----
10620
10620
class EmailService : ApplicationEventPublisherAware {
10621
10621
10622
- private lateinit var blackList : List<String>
10622
+ private lateinit var blockedList : List<String>
10623
10623
private lateinit var publisher: ApplicationEventPublisher
10624
10624
10625
- fun setBlackList(blackList : List<String>) {
10626
- this.blackList = blackList
10625
+ fun setBlockedList(blockedList : List<String>) {
10626
+ this.blockedList = blockedList
10627
10627
}
10628
10628
10629
10629
override fun setApplicationEventPublisher(publisher: ApplicationEventPublisher) {
10630
10630
this.publisher = publisher
10631
10631
}
10632
10632
10633
10633
fun sendEmail(address: String, content: String) {
10634
- if (blackList !!.contains(address)) {
10635
- publisher!!.publishEvent(BlackListEvent (this, address, content))
10634
+ if (blockedList !!.contains(address)) {
10635
+ publisher!!.publishEvent(BlockedListEvent (this, address, content))
10636
10636
return
10637
10637
}
10638
10638
// send email...
@@ -10653,41 +10653,42 @@ shows such a class:
10653
10653
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
10654
10654
.Java
10655
10655
----
10656
- public class BlackListNotifier implements ApplicationListener<BlackListEvent > {
10656
+ public class BlockedListNotifier implements ApplicationListener<BlockedListEvent > {
10657
10657
10658
10658
private String notificationAddress;
10659
10659
10660
10660
public void setNotificationAddress(String notificationAddress) {
10661
10661
this.notificationAddress = notificationAddress;
10662
10662
}
10663
10663
10664
- public void onApplicationEvent(BlackListEvent event) {
10664
+ public void onApplicationEvent(BlockedListEvent event) {
10665
10665
// notify appropriate parties via notificationAddress...
10666
10666
}
10667
10667
}
10668
10668
----
10669
10669
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
10670
10670
.Kotlin
10671
10671
----
10672
- class BlackListNotifier : ApplicationListener<BlackListEvent > {
10672
+ class BlockedListNotifier : ApplicationListener<BlockedListEvent > {
10673
10673
10674
10674
lateinit var notificationAddres: String
10675
10675
10676
- override fun onApplicationEvent(event: BlackListEvent ) {
10676
+ override fun onApplicationEvent(event: BlockedListEvent ) {
10677
10677
// notify appropriate parties via notificationAddress...
10678
10678
}
10679
10679
}
10680
10680
----
10681
10681
10682
10682
Notice that `ApplicationListener` is generically parameterized with the type of your
10683
- custom event (`BlackListEvent` in the preceding example). This means that the `onApplicationEvent()` method can
10684
- remain type-safe, avoiding any need for downcasting. You can register as many event
10685
- listeners as you wish, but note that, by default, event listeners receive events
10686
- synchronously. This means that the `publishEvent()` method blocks until all listeners have
10687
- finished processing the event. One advantage of this synchronous and single-threaded
10688
- approach is that, when a listener receives an event, it operates inside the transaction
10689
- context of the publisher if a transaction context is available. If another strategy for
10690
- event publication becomes necessary, see the javadoc for Spring's
10683
+ custom event (`BlockedListEvent` in the preceding example). This means that the
10684
+ `onApplicationEvent()` method can remain type-safe, avoiding any need for downcasting.
10685
+ You can register as many event listeners as you wish, but note that, by default, event
10686
+ listeners receive events synchronously. This means that the `publishEvent()` method
10687
+ blocks until all listeners have finished processing the event. One advantage of this
10688
+ synchronous and single-threaded approach is that, when a listener receives an event, it
10689
+ operates inside the transaction context of the publisher if a transaction context is
10690
+ available. If another strategy for event publication becomes necessary, see the javadoc
10691
+ for Spring's
10691
10692
{api-spring-framework}/context/event/ApplicationEventMulticaster.html[`ApplicationEventMulticaster`] interface
10692
10693
and {api-spring-framework}/context/event/SimpleApplicationEventMulticaster.html[`SimpleApplicationEventMulticaster`]
10693
10694
implementation for configuration options.
@@ -10698,7 +10699,7 @@ the classes above:
10698
10699
[source,xml,indent=0,subs="verbatim,quotes"]
10699
10700
----
10700
10701
<bean id="emailService" class="example.EmailService">
10701
- <property name="blackList ">
10702
+ <property name="blockedList ">
10702
10703
<list>
10703
10704
10704
10705
@@ -10707,15 +10708,15 @@ the classes above:
10707
10708
</property>
10708
10709
</bean>
10709
10710
10710
- <bean id="blackListNotifier " class="example.BlackListNotifier ">
10711
- <property name="notificationAddress" value="blacklist @example.org"/>
10711
+ <bean id="blockedListNotifier " class="example.BlockedListNotifier ">
10712
+ <property name="notificationAddress" value="blockedlist @example.org"/>
10712
10713
</bean>
10713
10714
----
10714
10715
10715
10716
Putting it all together, when the `sendEmail()` method of the `emailService` bean is
10716
- called, if there are any email messages that should be blacklisted , a custom event of type
10717
- `BlackListEvent ` is published. The `blackListNotifier ` bean is registered as an
10718
- `ApplicationListener` and receives the `BlackListEvent `, at which point it can
10717
+ called, if there are any email messages that should be blocked , a custom event of type
10718
+ `BlockedListEvent ` is published. The `blockedListNotifier ` bean is registered as an
10719
+ `ApplicationListener` and receives the `BlockedListEvent `, at which point it can
10719
10720
notify appropriate parties.
10720
10721
10721
10722
NOTE: Spring's eventing mechanism is designed for simple communication between Spring beans
@@ -10731,13 +10732,13 @@ architectures that build upon the well-known Spring programming model.
10731
10732
==== Annotation-based Event Listeners
10732
10733
10733
10734
As of Spring 4.2, you can register an event listener on any public method of a managed
10734
- bean by using the `@EventListener` annotation. The `BlackListNotifier ` can be rewritten as
10735
+ bean by using the `@EventListener` annotation. The `BlockedListNotifier ` can be rewritten as
10735
10736
follows:
10736
10737
10737
10738
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
10738
10739
.Java
10739
10740
----
10740
- public class BlackListNotifier {
10741
+ public class BlockedListNotifier {
10741
10742
10742
10743
private String notificationAddress;
10743
10744
@@ -10746,20 +10747,20 @@ follows:
10746
10747
}
10747
10748
10748
10749
@EventListener
10749
- public void processBlackListEvent(BlackListEvent event) {
10750
+ public void processBlockedListEvent(BlockedListEvent event) {
10750
10751
// notify appropriate parties via notificationAddress...
10751
10752
}
10752
10753
}
10753
10754
----
10754
10755
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
10755
10756
.Kotlin
10756
10757
----
10757
- class BlackListNotifier {
10758
+ class BlockedListNotifier {
10758
10759
10759
10760
lateinit var notificationAddress: String
10760
10761
10761
10762
@EventListener
10762
- fun processBlackListEvent (event: BlackListEvent ) {
10763
+ fun processBlockedListEvent (event: BlockedListEvent ) {
10763
10764
// notify appropriate parties via notificationAddress...
10764
10765
}
10765
10766
}
@@ -10802,15 +10803,15 @@ The following example shows how our notifier can be rewritten to be invoked only
10802
10803
.Java
10803
10804
----
10804
10805
@EventListener(condition = "#blEvent.content == 'my-event'")
10805
- public void processBlackListEvent(BlackListEvent blEvent ) {
10806
+ public void processBlockedListEvent(BlockedListEvent blockedListEvent ) {
10806
10807
// notify appropriate parties via notificationAddress...
10807
10808
}
10808
10809
----
10809
10810
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
10810
10811
.Kotlin
10811
10812
----
10812
10813
@EventListener(condition = "#blEvent.content == 'my-event'")
10813
- fun processBlackListEvent(blEvent: BlackListEvent ) {
10814
+ fun processBlockedListEvent(blockedListEvent: BlockedListEvent ) {
10814
10815
// notify appropriate parties via notificationAddress...
10815
10816
}
10816
10817
----
@@ -10852,7 +10853,7 @@ method signature to return the event that should be published, as the following
10852
10853
.Java
10853
10854
----
10854
10855
@EventListener
10855
- public ListUpdateEvent handleBlackListEvent(BlackListEvent event) {
10856
+ public ListUpdateEvent handleBlockedListEvent(BlockedListEvent event) {
10856
10857
// notify appropriate parties via notificationAddress and
10857
10858
// then publish a ListUpdateEvent...
10858
10859
}
@@ -10861,7 +10862,7 @@ method signature to return the event that should be published, as the following
10861
10862
.Kotlin
10862
10863
----
10863
10864
@EventListener
10864
- fun handleBlackListEvent (event: BlackListEvent ): ListUpdateEvent {
10865
+ fun handleBlockedListEvent (event: BlockedListEvent ): ListUpdateEvent {
10865
10866
// notify appropriate parties via notificationAddress and
10866
10867
// then publish a ListUpdateEvent...
10867
10868
}
@@ -10870,7 +10871,7 @@ method signature to return the event that should be published, as the following
10870
10871
NOTE: This feature is not supported for
10871
10872
<<context-functionality-events-async, asynchronous listeners>>.
10872
10873
10873
- This new method publishes a new `ListUpdateEvent` for every `BlackListEvent ` handled by the
10874
+ This new method publishes a new `ListUpdateEvent` for every `BlockedListEvent ` handled by the
10874
10875
method above. If you need to publish several events, you can return a `Collection` of events
10875
10876
instead.
10876
10877
@@ -10887,17 +10888,17 @@ The following example shows how to do so:
10887
10888
----
10888
10889
@EventListener
10889
10890
@Async
10890
- public void processBlackListEvent(BlackListEvent event) {
10891
- // BlackListEvent is processed in a separate thread
10891
+ public void processBlockedListEvent(BlockedListEvent event) {
10892
+ // BlockedListEvent is processed in a separate thread
10892
10893
}
10893
10894
----
10894
10895
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
10895
10896
.Kotlin
10896
10897
----
10897
10898
@EventListener
10898
10899
@Async
10899
- fun processBlackListEvent (event: BlackListEvent ) {
10900
- // BlackListEvent is processed in a separate thread
10900
+ fun processBlockedListEvent (event: BlockedListEvent ) {
10901
+ // BlockedListEvent is processed in a separate thread
10901
10902
}
10902
10903
----
10903
10904
@@ -10922,7 +10923,7 @@ annotation to the method declaration, as the following example shows:
10922
10923
----
10923
10924
@EventListener
10924
10925
@Order(42)
10925
- public void processBlackListEvent(BlackListEvent event) {
10926
+ public void processBlockedListEvent(BlockedListEvent event) {
10926
10927
// notify appropriate parties via notificationAddress...
10927
10928
}
10928
10929
----
@@ -10931,7 +10932,7 @@ annotation to the method declaration, as the following example shows:
10931
10932
----
10932
10933
@EventListener
10933
10934
@Order(42)
10934
- fun processBlackListEvent (event: BlackListEvent ) {
10935
+ fun processBlockedListEvent (event: BlockedListEvent ) {
10935
10936
// notify appropriate parties via notificationAddress...
10936
10937
}
10937
10938
----
0 commit comments