aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java
Publish
Diffstat (limited to 'jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java')
-rw-r--r--jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java b/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java
new file mode 100644
index 00000000000..d004846d5b8
--- /dev/null
+++ b/jdisc_core/src/main/java/com/yahoo/jdisc/ResourceReference.java
@@ -0,0 +1,33 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.jdisc;
+
+/**
+ * <p>Represents a live reference to a {@link SharedResource}. Only provides the ability to release the reference.</p>
+ *
+ * <p>Implements {@link AutoCloseable} so that it can be used in try-with-resources statements. Example</p>
+ * <pre>
+ * void doSomethingWithRequest(final Request request) {
+ * try (final ResourceReference ref = request.refer()) {
+ * // Do something with request
+ * }
+ * // ref.close() will be called automatically on exit from the try block, releasing the reference on 'request'.
+ * }
+ * </pre>
+ *
+ * @author <a href="mailto:bakksjo@yahoo-inc.com">Oyvind Bakksjo</a>
+ */
+public interface ResourceReference extends AutoCloseable {
+
+ /**
+ * <p>Decrements the reference count of the referenced resource.
+ * You call this method once you are done using an object
+ * that you have previously {@link SharedResource#refer() referred}.</p>
+ *
+ * <p>Note that this method is NOT idempotent; you must call it exactly once.</p>
+ *
+ * @see SharedResource#refer()
+ */
+ @Override
+ void close();
+
+}