Skip to content

Commit

Permalink
Change SafeCloseable to AutoCloseable
Browse files Browse the repository at this point in the history
  • Loading branch information
arman-ddl committed Mar 15, 2024
1 parent 2b70878 commit 67421f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions py/server/deephaven/jcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ def _j_array_to_series(dtype: DType, j_array: jpy.JType, conv_null: bool) -> pd.
return s


class SafeCloseable(JObjectWrapper):
"""A context manager wrapper to allow Java SafeCloseable to be used in with statements.
class AutoCloseable(JObjectWrapper):
"""A context manager wrapper to allow Java AutoCloseable to be used in with statements.
When constructing a new instance, the Java SafeCloseable must not be closed."""
When constructing a new instance, the Java AutoCloseable must not be closed."""

j_object_type = jpy.get_type("io.deephaven.util.SafeCloseable")
j_object_type = jpy.get_type("java.lang.AutoCloseable")

def __init__(self, j_safe_closeable):
self._j_safe_closeable = j_safe_closeable
def __init__(self, j_auto_closeable):
self._j_auto_closeable = j_auto_closeable
self.closed = False

def __enter__(self):
Expand All @@ -323,7 +323,7 @@ def __enter__(self):
def close(self):
if not self.closed:
self.closed = True
self._j_safe_closeable.close()
self._j_auto_closeable.close()

def __exit__(self, exc_type, exc_value, traceback):
self.close()
Expand All @@ -333,4 +333,4 @@ def __del__(self):

@property
def j_object(self) -> jpy.JType:
return self._j_safe_closeable
return self._j_auto_closeable
12 changes: 6 additions & 6 deletions py/server/tests/test_jcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import unittest

from deephaven import dtypes
from deephaven.jcompat import j_function, j_lambda, SafeCloseable
from deephaven.jcompat import j_function, j_lambda, AutoCloseable
from tests.testbase import BaseTestCase

import jpy
Expand All @@ -30,11 +30,11 @@ def int_to_str(v: int) -> str:
r = j_func.apply(10)
self.assertEqual(r, "10")

def test_safe_closeable(self):
safe_closeable = SafeCloseable(_JSharedContext.makeSharedContext())
with safe_closeable:
self.assertEqual(safe_closeable.closed, False)
self.assertEqual(safe_closeable.closed, True)
def test_auto_closeable(self):
auto_closeable = AutoCloseable(_JSharedContext.makeSharedContext())
with auto_closeable:
self.assertEqual(auto_closeable.closed, False)
self.assertEqual(auto_closeable.closed, True)


if __name__ == "__main__":
Expand Down

0 comments on commit 67421f4

Please sign in to comment.