Monitor

Struct Monitor 

Source
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§

Source§

impl<'env, T: ReferenceType> Monitor<'env, T>

Source

pub fn unlock(self) -> &'env Ref<'env, T>

Decrements the JNI monitor counter indicating the number of times it has entered this monitor. If the value of the counter becomes zero, the current thread releases the monitor.

Methods from Deref<Target = Ref<'env, T>>§

Source

pub fn env(&self) -> Env<'env>

Gets the Env under which the JNI reference is valid.

Source

pub fn as_raw(&self) -> jobject

Returns the raw JNI reference pointer.

Source

pub fn as_global(&self) -> Global<T>

Returns a new JNI global reference of the same Java object.

Source

pub fn as_local(&self) -> Local<'env, T>

Returns a new JNI local reference of the same Java object.

Source

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.

Source

pub fn is_same_object<O: ReferenceType>(&self, other: &Ref<'_, O>) -> bool

Tests whether two JNI references refer to the same Java object.

Source

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
  • self references an instance of type U.
Source

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.

Source

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.

Trait Implementations§

Source§

impl<'env, T: ReferenceType> Deref for Monitor<'env, T>

Source§

type Target = Ref<'env, T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'env, T: ReferenceType> Drop for Monitor<'env, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'env, T> Freeze for Monitor<'env, T>

§

impl<'env, T> RefUnwindSafe for Monitor<'env, T>
where T: RefUnwindSafe,

§

impl<'env, T> !Send for Monitor<'env, T>

§

impl<'env, T> !Sync for Monitor<'env, T>

§

impl<'env, T> Unpin for Monitor<'env, T>

§

impl<'env, T> UnwindSafe for Monitor<'env, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.