-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathPyCompoundCallable.java
More file actions
61 lines (49 loc) · 1.57 KB
/
PyCompoundCallable.java
File metadata and controls
61 lines (49 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Corporation for National Research Initiatives
package org.python.core;
import java.util.List;
import org.python.util.Generic;
public class PyCompoundCallable extends PyObject implements Traverseproc {
private List<PyObject> callables = Generic.list();
private PySystemState systemState = Py.getSystemState();
public void append(PyObject callable) {
callables.add(callable);
}
public void clear() {
callables.clear();
}
public PyObject __call__(PyObject[] args, String[] keywords) {
// Set the system state to handle callbacks from java threads
Py.setSystemState(systemState);
for (PyObject callable : callables) {
callable.__call__(args, keywords);
}
return Py.None;
}
public String toString() {
return "<CompoundCallable with " + callables.size() + " callables>";
}
/* Traverseproc implementation */
@Override
public int traverse(Visitproc visit, Object arg) {
int retValue;
if (systemState != null) {
retValue = visit.visit(systemState, arg);
if (retValue != 0) {
return retValue;
}
}
if (callables != null) {
for (PyObject ob: callables) {
retValue = visit.visit(ob, arg);
if (retValue != 0) {
return retValue;
}
}
}
return 0;
}
@Override
public boolean refersDirectlyTo(PyObject ob) {
return ob != null && (ob == systemState || callables.contains(ob));
}
}