pub struct Monitor<'env, T: ReferenceType> { /* private fields */ }Expand description
A borrowed Ref of a Java object locked with the JNI monitor mechanism, providing limited thread safety.
It is imposible to be FFI safe. It is important to drop the monitor or call Monitor::unlock() when appropriate.
Limitations:
- It merely blocks other native functions from owning the JNI monitor of the same object before it drops.
- It may not block other native functions from using the corresponding object without entering monitored mode.
- It may not prevent any Java method or block from using this object, even if it is marked as
synchronized. - While it is a reentrant lock for the current thread, dead lock is still possible under multi-thread conditions.
Implementations§
Methods from Deref<Target = Ref<'env, T>>§
Sourcepub fn as_global(&self) -> Global<T>
pub fn as_global(&self) -> Global<T>
Returns a new JNI global reference of the same Java object.
Sourcepub fn as_local(&self) -> Local<'env, T>
pub fn as_local(&self) -> Local<'env, T>
Returns a new JNI local reference of the same Java object.
Sourcepub fn as_monitor(&'env self) -> Monitor<'env, T>
pub fn as_monitor(&'env self) -> Monitor<'env, T>
Enters monitored mode or increments the JNI monitor counter in this thread for the referenced Java object. See Monitor for the limited locking functionality.
Sourcepub fn is_same_object<O: ReferenceType>(&self, other: &Ref<'_, O>) -> bool
pub fn is_same_object<O: ReferenceType>(&self, other: &Ref<'_, O>) -> bool
Tests whether two JNI references refer to the same Java object.
Sourcepub unsafe fn cast_ref_unchecked<U: ReferenceType>(&self) -> &Ref<'env, U>
pub unsafe fn cast_ref_unchecked<U: ReferenceType>(&self) -> &Ref<'env, U>
Casts the borrowed Ref to a JNI reference of type U forcefully, without the cost of runtime checking.
§Safety
selfreferences an instance of typeU.
Sourcepub fn cast_ref<U: ReferenceType>(&self) -> Result<&Ref<'env, U>, CastError>
pub fn cast_ref<U: ReferenceType>(&self) -> Result<&Ref<'env, U>, CastError>
Tries to cast the borrowed Ref to a JNI reference of type U.
Sourcepub fn upcast_ref<U: ReferenceType>(&self) -> &Ref<'env, U>where
T: AssignableTo<U>,
pub fn upcast_ref<U: ReferenceType>(&self) -> &Ref<'env, U>where
T: AssignableTo<U>,
Casts the borrowed Ref towards a super class type, without the cost of runtime checking.