Skip to content

Commit

Permalink
Better naming/docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Sep 18, 2024
1 parent c20d423 commit 724452b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,52 @@
import io.deephaven.io.logger.Logger;
import io.deephaven.util.annotations.ScriptApi;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jpy.PyObject;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;

@ScriptApi
public class PythonInputTableStatusListenerAdapter implements InputTableStatusListener {

private static final Logger log = LoggerFactory.getLogger(PythonInputTableStatusListenerAdapter.class);
private final PyObject pyOnSuccessCallable;
private final PyObject pyOnSuccessCallback;
private final PyObject pyOnErrorCallback;

/**
* Create a Python InputTable status listener.
*
* @param pyOnSuccessListener The Python onSuccess callback function.
* @param pyOnErrorCallback The Python onError callback function.
* @param pyOnSuccessCallback The Python onSuccess callback function.
* @param pyOnErrorCallback The Python onError callback function.
*/
private PythonInputTableStatusListenerAdapter(@Nullable PyObject pyOnSuccessListener,
@Nonnull PyObject pyOnErrorCallback) {
this.pyOnSuccessCallable = pyOnSuccessListener;
private PythonInputTableStatusListenerAdapter(@Nullable PyObject pyOnSuccessCallback,
@NotNull PyObject pyOnErrorCallback) {
this.pyOnSuccessCallback = pyOnSuccessCallback;
this.pyOnErrorCallback = pyOnErrorCallback;
}

public static PythonInputTableStatusListenerAdapter create(@Nullable PyObject pyOnSuccessListener,
@Nonnull PyObject pyOnErrorCallback) {
return new PythonInputTableStatusListenerAdapter(pyOnSuccessListener,
public static PythonInputTableStatusListenerAdapter create(@Nullable PyObject pyOnSuccessCallback,
@NotNull PyObject pyOnErrorCallback) {
return new PythonInputTableStatusListenerAdapter(pyOnSuccessCallback,
Objects.requireNonNull(pyOnErrorCallback, "Python on_error callback cannot be None"));
}

@Override
public void onError(Throwable originalException) {
if (!pyOnErrorCallback.isNone()) {
try {
pyOnErrorCallback.call("__call__", ExceptionUtils.getStackTrace(originalException));
} catch (Throwable e) {
// If the Python onFailure callback fails, log the new exception
// and continue with the original exception.
log.error().append("Python on_error callback failed: ").append(e).endl();
}
} else {
log.error().append("Python on_error callback is None: ")
.append(ExceptionUtils.getStackTrace(originalException)).endl();
try {
pyOnErrorCallback.call("__call__", ExceptionUtils.getStackTrace(originalException));
} catch (Throwable e) {
// If the Python onFailure callback fails, log the new exception
// and continue with the original exception.
log.error().append("Python on_error callback failed: ").append(e).endl();
}
}

@Override
public void onSuccess() {
if (pyOnSuccessCallable != null && !pyOnSuccessCallable.isNone()) {
pyOnSuccessCallable.call("__call__");
if (pyOnSuccessCallback != null && !pyOnSuccessCallback.isNone()) {
pyOnSuccessCallback.call("__call__");
} else {
InputTableStatusListener.super.onSuccess();
}
Expand Down
12 changes: 8 additions & 4 deletions py/server/deephaven/table_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ def __init__(self, j_table: jpy.JType):

def add(self, table: Table) -> None:
"""Synchronously writes rows from the provided table to this input table. If this is a keyed input table,
added rows with keys
that match existing rows will replace those rows.
added rows with keys that match existing rows will replace those rows.
Args:
table (Table): the table that provides the rows to write
Expand All @@ -271,8 +270,7 @@ def add(self, table: Table) -> None:

def delete(self, table: Table) -> None:
"""Synchronously deletes the keys contained in the provided table from this keyed input table. If this
method is called on an
append-only input table, an error will be raised.
method is called on an append-only input table, an error will be raised.
Args:
table (Table): the table with the keys to delete
Expand All @@ -293,6 +291,9 @@ def add_async(self, table: Table, on_success: Callable[[], None] = None,
will be called. If the operation fails, the optional on_error callback if provided will be called. If on_error
is not provided, a default callback function will be called that simply prints out the received exception.
Note, multiple calls to this method on the same thread will be queued and processed in order. However, ordering
is not guaranteed across threads.
Args:
table (Table): the table that provides the rows to write
on_success (Callable[[], None]): the success callback function, default is None
Expand Down Expand Up @@ -326,6 +327,9 @@ def delete_async(self, table: Table, on_success: Callable[[], None] = None,
will be called. If the operation fails, the optional on_error callback if provided will be called. If on_error
is not provided, a default callback function will be called that simply prints out the received exception.
Note, multiple calls to this method on the same thread will be queued and processed in order. However, ordering
is not guaranteed across threads.
Args:
table (Table): the table with the keys to delete
on_success (Callable[[], None]): the success callback function, default is None
Expand Down

0 comments on commit 724452b

Please sign in to comment.