forked from deephaven/deephaven-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable figures to retain references to objects they rely on (deephave…
…n#4552) Also turns down log levels when testing/generating figure code. Fixes deephaven#4540
- Loading branch information
Showing
6 changed files
with
145 additions
and
23 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
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
45 changes: 45 additions & 0 deletions
45
Plot/src/test/java/io/deephaven/plot/TestFigureLiveness.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,45 @@ | ||
package io.deephaven.plot; | ||
|
||
import io.deephaven.engine.liveness.LivenessReferent; | ||
import io.deephaven.engine.liveness.LivenessScope; | ||
import io.deephaven.engine.liveness.LivenessScopeStack; | ||
import io.deephaven.engine.table.Table; | ||
import io.deephaven.engine.testutil.testcase.RefreshingTableTestCase; | ||
import io.deephaven.engine.util.TableTools; | ||
import io.deephaven.util.SafeCloseable; | ||
|
||
public class TestFigureLiveness extends RefreshingTableTestCase { | ||
public void testFigureLiveness() { | ||
// Scope that represents the incoming grpc call | ||
LivenessScope reqScope = new LivenessScope(); | ||
|
||
// Scope that the work is done in | ||
LivenessScope scope = new LivenessScope(); | ||
Table t; | ||
Figure plot; | ||
try (SafeCloseable ignored = LivenessScopeStack.open(scope, false)) { | ||
t = TableTools.timeTable("PT1s").updateView("Y=i", "X=i", "Z=i"); | ||
plot = PlottingConvenience.plot("series", t, "X", "Y") | ||
.plotBy("multieseries", t, "X", "Y", "Z") | ||
.show(); | ||
reqScope.manage((LivenessReferent) plot);// explicitly manage outside of the scope | ||
} | ||
|
||
// Assert that the tables are retained while the scope is still open (then drop the new reference) | ||
assertTrue(t.tryRetainReference()); | ||
t.dropReference(); | ||
|
||
// Drop the inner scope | ||
scope.release(); | ||
|
||
// Assert that the table reference is retained now by virtue of the plot that holds it | ||
assertTrue(t.tryRetainReference()); | ||
t.dropReference(); | ||
|
||
// Simulate the user releasing their export | ||
reqScope.release(); | ||
|
||
// Assert that the table reference is no longer held after the figure is released | ||
assertFalse(t.tryRetainReference()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
engine/updategraph/src/main/java/io/deephaven/engine/liveness/DelegatingLivenessNode.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,51 @@ | ||
package io.deephaven.engine.liveness; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Indicates that this class implements LivenessNode via a member rather than implementing it directly. The real | ||
* LivenessNode is exposed via {@link #asLivenessNode()}, all other methods delegate to this instance. | ||
*/ | ||
public interface DelegatingLivenessNode extends LivenessNode { | ||
/** | ||
* Returns the "real" {@link LivenessNode} instance. When implementing this, care should be taken to match lifecycle | ||
* of the {@code DelegatingLivenessNode} instance with this instance, as the returned {@code LivenessNode} behaves | ||
* as a proxy for {@code this}. | ||
* | ||
* @return a LivenessNode to use to manage this object's liveness. | ||
*/ | ||
LivenessNode asLivenessNode(); | ||
|
||
@Override | ||
default boolean tryManage(@NotNull LivenessReferent referent) { | ||
return asLivenessNode().tryManage(referent); | ||
} | ||
|
||
@Override | ||
default boolean tryUnmanage(@NotNull LivenessReferent referent) { | ||
return asLivenessNode().tryManage(referent); | ||
} | ||
|
||
@Override | ||
default boolean tryUnmanage(@NotNull Stream<? extends LivenessReferent> referents) { | ||
return asLivenessNode().tryUnmanage(referents); | ||
} | ||
|
||
@Override | ||
default boolean tryRetainReference() { | ||
return asLivenessNode().tryRetainReference(); | ||
} | ||
|
||
@Override | ||
default void dropReference() { | ||
asLivenessNode().dropReference(); | ||
} | ||
|
||
@Override | ||
default WeakReference<? extends LivenessReferent> getWeakReference() { | ||
return asLivenessNode().getWeakReference(); | ||
} | ||
} |