-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support bidi objecttype plugins exporting new python objects (#4360)
Attempts to sidestep #1775 by offering a consistent convention to pass Python and Java objects between their runtimes - instead of exclusively "wrapping" for Python and "unwrapping" to return to Java, this encourages "javaify" to wrap or unwrap as necessary to to pass to Java, and "pythonify" to unwrap or wrap as necessary to pass to Python. This way, PyObjects can be avoided being passed to Java directly. This new wrapper is a liveness node, to ensure that the surrounding liveness scope always takes ownership on creation, even if the calling Java code isn't aware that it has received a resource that needs to be managed. Fixes #4338 Co-authored-by: Ryan Caudy <ryan@deephaven.io>
- Loading branch information
Showing
12 changed files
with
251 additions
and
121 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
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
59 changes: 59 additions & 0 deletions
59
...ategraph/src/main/java/io/deephaven/engine/liveness/ReferenceCountedLivenessReferent.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,59 @@ | ||
package io.deephaven.engine.liveness; | ||
|
||
import io.deephaven.util.Utils; | ||
import io.deephaven.util.referencecounting.ReferenceCounted; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
/** | ||
* {@link LivenessReferent} implementation that relies on reference counting to determine its liveness. | ||
*/ | ||
public class ReferenceCountedLivenessReferent extends ReferenceCounted implements LivenessReferent { | ||
|
||
public final boolean tryRetainReference() { | ||
if (Liveness.REFERENCE_TRACKING_DISABLED) { | ||
return true; | ||
} | ||
return tryIncrementReferenceCount(); | ||
} | ||
|
||
public final void dropReference() { | ||
if (Liveness.REFERENCE_TRACKING_DISABLED) { | ||
return; | ||
} | ||
if (Liveness.DEBUG_MODE_ENABLED) { | ||
Liveness.log.info().append("LivenessDebug: Releasing ").append(Utils.REFERENT_FORMATTER, this).endl(); | ||
} | ||
if (!tryDecrementReferenceCount()) { | ||
throw new LivenessStateException( | ||
getReferentDescription() + " could not be released as it was no longer live"); | ||
} | ||
} | ||
|
||
@Override | ||
public WeakReference<? extends LivenessReferent> getWeakReference() { | ||
return new WeakReference<>(this); | ||
} | ||
|
||
/** | ||
* Attempt to release (destructively when necessary) resources held by this object. This may render the object | ||
* unusable for subsequent operations. Implementations should be sure to call super.destroy(). | ||
* <p> | ||
* This is intended to only ever be used as a side effect of decreasing the reference count to 0. | ||
*/ | ||
protected void destroy() {} | ||
|
||
@Override | ||
protected void onReferenceCountAtZero() { | ||
if (Liveness.REFERENCE_TRACKING_DISABLED) { | ||
throw new IllegalStateException( | ||
"Reference count on " + this + " reached zero while liveness reference tracking is disabled"); | ||
} | ||
try { | ||
destroy(); | ||
} catch (Exception e) { | ||
Liveness.log.warn().append("Exception while destroying ").append(Utils.REFERENT_FORMATTER, this) | ||
.append(" after reference count reached zero: ").append(e).endl(); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.