Changed Subscription Mode (for Strong/Weak references) to be it's own class
parent
d473b4a5e6
commit
11a08ddc28
|
@ -0,0 +1,23 @@
|
|||
package dorkbox.messageBus;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public
|
||||
enum SubscriptionMode {
|
||||
/**
|
||||
* This is the default.
|
||||
* <p>
|
||||
* We use strong references when saving the subscribed listeners (these are the classes & methods that receive messages).
|
||||
* <p>
|
||||
* In certain environments (ie: spring), it is desirable to use weak references -- so that there are no memory leaks during
|
||||
* the container lifecycle (or, more specifically, so one doesn't have to manually manage the memory).
|
||||
*/
|
||||
StrongReferences,
|
||||
|
||||
/**
|
||||
* Using weak references is a tad slower than using strong references, since there are additional steps taken when there are orphaned
|
||||
* references (when GC occurs) that have to be cleaned up. This cleanup occurs during message publication.
|
||||
*/
|
||||
WeakReferences
|
||||
}
|
|
@ -45,12 +45,11 @@ import java.lang.annotation.Target;
|
|||
public
|
||||
@interface Listener {
|
||||
/**
|
||||
* By default, references to message listeners (these are the objects/methods that receive messages) are strong. This default can be
|
||||
* changed via a static boolean (during startup, see MessageBus.useStrongReferencesByDefault).
|
||||
* By default, references to message listeners (these are the objects/methods that receive messages) are strong. See {@link dorkbox.messageBus.SubscriptionMode}).
|
||||
*
|
||||
* The benefits to use WEAK references, is to eliminate risks of memory leaks in managed environments (such as spring).
|
||||
*
|
||||
* the default here "Undefined" here so that the static boolean (MessageBus.useStrongReferencesByDefault) takes priority
|
||||
* the default here "Undefined" here so that the {@link dorkbox.messageBus.SubscriptionMode#StrongReferences} takes priority
|
||||
*/
|
||||
References references() default References.Undefined;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue