diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-10-04 17:20:40 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-10-05 14:49:20 +0200 |
commit | c9982ddc5ce3083101541a301cca20b19b4914e8 (patch) | |
tree | f63fa1165e4b8572a7dd7c24ed056e851b97660d /jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java | |
parent | 5f5cb7aa87195c92b374dcbc742a5263559c8bb0 (diff) |
Add option to attach a context to refer.
Introduce a lightweight debug mode.
Diffstat (limited to 'jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java b/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java index 20656bf7d1d..dee0f8ee410 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/SharedResource.java @@ -28,10 +28,22 @@ import com.yahoo.jdisc.service.ServerProvider; public interface SharedResource { String SYSTEM_PROPERTY_NAME_DEBUG = "jdisc.debug.resources"; - boolean DEBUG = Boolean.valueOf(System.getProperty(SYSTEM_PROPERTY_NAME_DEBUG)); + enum Debug {NO, SIMPLE, STACK} + Debug DEBUG = valueOfDebug(); + private static Debug valueOfDebug() { + String val = System.getProperty(SYSTEM_PROPERTY_NAME_DEBUG); + if (val != null) { + val = val.toUpperCase(); + if (Boolean.valueOf(val)) return Debug.SIMPLE; + try { + return Debug.valueOf(val); + } catch (IllegalArgumentException e) { } + } + return Debug.NO; + } /** - * <p>Increments the reference count of this resource. You call this method to prevent an object from being + * <p>Creates a reference to this resource. You call this method to prevent an object from being * destroyed until you have finished using it.</p> * * <p>You MUST keep the returned {@link ResourceReference} object and release the reference by calling @@ -43,6 +55,21 @@ public interface SharedResource { ResourceReference refer(); /** + * <p>Creates a reference to this resource. You call this method to prevent an object from being + * destroyed until you have finished using it. You can attach a context that will live as long as the reference.</p> + * + * @param context A context to be associated with the reference. It should give some clue as to who referenced it. + * <p>You MUST keep the returned {@link ResourceReference} object and release the reference by calling + * {@link ResourceReference#close()} on it. A reference created by this method can NOT be released by calling + * {@link #release()}.</p> + * + * @see ResourceReference#close() + */ + default ResourceReference refer(Object context) { + return refer(); + } + + /** * <p>Releases the "main" reference to this resource (the implicit reference due to creation of the object).</p> * * <p>References obtained by calling {@link #refer()} must be released by calling {@link ResourceReference#close()} |