Package org.python.modules._weakref
Class GlobalRef
- java.lang.Object
-
- java.lang.ref.Reference<T>
-
- java.lang.ref.WeakReference<PyObject>
-
- org.python.modules._weakref.GlobalRef
-
- All Implemented Interfaces:
ReferenceBackend
public class GlobalRef extends java.lang.ref.WeakReference<PyObject> implements ReferenceBackend
-
-
Field Summary
Fields Modifier and Type Field Description static ReferenceBackendFactory
factory
This is a hook for JyNI to insert a native-objects-aware implementation of ReferenceBackend.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(AbstractReference ref)
int
count()
boolean
equals(java.lang.Object o)
AllowGlobalRef
s to be used as hashtable-keys.AbstractReference
find(java.lang.Class<?> cls)
Search for a reusable reference.static int
getCount(PyObject object)
Return the number of references to the specifiedPyObject
.static PyList
getRefs(PyObject object)
Return a list of references to the specifiedPyObject
.static boolean
hasDelayedCallbacks()
int
hashCode()
AllowsGlobalRef
to be used as hashtable-keys.boolean
isCleared()
static ReferenceBackend
newInstance(PyObject object)
Create a new trackedReferenceBackend
.static void
processDelayedCallbacks()
Call all callbacks that were enqueued viadelayedCallback(GlobalRef)
method.int
pythonHashCode()
The publicly usedhashCode
, for theAbstractReference
wrapper.PyList
refs()
void
restore(PyObject formerReferent)
Restores this weak reference to its former referent.-
Methods inherited from class java.lang.ref.Reference
clear, enqueue, get, isEnqueued, reachabilityFence
-
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.python.modules._weakref.ReferenceBackend
get
-
-
-
-
Field Detail
-
factory
public static ReferenceBackendFactory factory
This is a hook for JyNI to insert a native-objects-aware implementation of ReferenceBackend.
-
-
Constructor Detail
-
GlobalRef
public GlobalRef(PyObject object)
-
-
Method Detail
-
add
public void add(AbstractReference ref)
- Specified by:
add
in interfaceReferenceBackend
-
find
public AbstractReference find(java.lang.Class<?> cls)
Search for a reusable reference. To be reused, it must be of the same class and it must not have a callback.- Specified by:
find
in interfaceReferenceBackend
-
processDelayedCallbacks
public static void processDelayedCallbacks()
Call all callbacks that were enqueued viadelayedCallback(GlobalRef)
method.- See Also:
delayedCallback(GlobalRef)
-
hasDelayedCallbacks
public static boolean hasDelayedCallbacks()
-
isCleared
public boolean isCleared()
- Specified by:
isCleared
in interfaceReferenceBackend
-
count
public int count()
- Specified by:
count
in interfaceReferenceBackend
-
refs
public PyList refs()
- Specified by:
refs
in interfaceReferenceBackend
-
newInstance
public static ReferenceBackend newInstance(PyObject object)
Create a new trackedReferenceBackend
. If noReferenceBackendFactory
is registered, it actually returns aGlobalRef
.- Parameters:
object
- aPyObject
to reference- Returns:
- a new tracked
ReferenceBackend
-
restore
public void restore(PyObject formerReferent)
Restores this weak reference to its former referent. This actually means that a freshGlobalRef
is created and inserted into all adjacentAbstractReference
s. The currentGlobalRef
is disbanded. If the givenPyObject
is not the former referent of this weak reference, anIllegalArgumentException
is thrown.- Specified by:
restore
in interfaceReferenceBackend
- Throws:
java.lang.IllegalArgumentException
- ifformerReferent
is not the actual former referent.
-
getCount
public static int getCount(PyObject object)
Return the number of references to the specifiedPyObject
.- Parameters:
object
- a PyObject- Returns:
- an int reference count
-
getRefs
public static PyList getRefs(PyObject object)
Return a list of references to the specifiedPyObject
.
-
equals
public boolean equals(java.lang.Object o)
AllowGlobalRef
s to be used as hashtable-keys.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
AllowsGlobalRef
to be used as hashtable-keys.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hashCode
int
-value
-
pythonHashCode
public int pythonHashCode()
The publicly usedhashCode
, for theAbstractReference
wrapper.- Specified by:
pythonHashCode
in interfaceReferenceBackend
- Returns:
- a hashCode
int
-value
-
-