trait RefLike[A, Context] extends SourceLike[A, Context] with SinkLike[A, Context]
Provides all of the operations of a Ref[A], without the ability to get a
Ref.View.
- Alphabetic
- By Inheritance
- RefLike
- SinkLike
- SourceLike
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
- abstract def get(implicit txn: Context): A
Performs a transactional read and checks that it is consistent with all reads already made by
txn.Performs a transactional read and checks that it is consistent with all reads already made by
txn. Equivalent toapply(), which is more concise in many situations.- txn
an active transaction.
- returns
the value of the
Refas observed bytxn.
- Definition Classes
- SourceLike
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- abstract def getWith[Z](f: (A) => Z)(implicit txn: Context): Z
Returns
f(get), possibly reevaluatingfto avoid rollback if a conflicting change is made but the old and new values are equal after application off.Returns
f(get), possibly reevaluatingfto avoid rollback if a conflicting change is made but the old and new values are equal after application off. Requires thatf(x) == f(y)ifx == y.getWith(f)is equivalent tof(relaxedGet({ f(_) == f(_) })), although perhaps more efficient.- f
an idempotent function.
- returns
the result of applying
fto the value contained in thisRef.
- Definition Classes
- SourceLike
- abstract def relaxedGet(equiv: (A, A) => Boolean)(implicit txn: Context): A
Returns the same value as
get, but allows the caller to determine whethertxnshould be rolled back if another thread changes the value of thisRefbeforetxnis committed.Returns the same value as
get, but allows the caller to determine whethertxnshould be rolled back if another thread changes the value of thisRefbeforetxnis committed. Ifref.relaxedGet(equiv)returnsv0intxn, another context changesreftov1, andequiv(v0, v1) == true, thentxnwon't be required to roll back (at least not due to this read). If additional changes are made torefadditional calls to the equivalence function will be made, always withv0as the first parameter.equivwill always be invoked on the current thread. Extreme care should be taken if the equivalence function accesses anyRefs.As an example, to perform a read that will not be validated during commit you can use the maximally permissive equivalence function:
val unvalidatedValue = ref.relaxedGet({ (_, _) => true })
To check view serializability rather than conflict serializability for a read:
val viewSerializableValue = ref.relaxedGet({ _ == _ })The
getWithmethod provides related functionality.- equiv
an equivalence function that returns true if a transaction that observed the first argument will still complete correctly, where the second argument is the actual value that should have been observed.
- returns
a value of the
Ref, not necessary consistent with the rest of the reads performed bytxn.
- Definition Classes
- SourceLike
- abstract def set(v: A)(implicit txn: Context): Unit
Performs a transactional write.
Performs a transactional write. The new value will not be visible by any other threads until (and unless)
txnsuccessfully commits. Equivalent toupdate(v).- v
a value to store in the
Ref.
- Definition Classes
- SinkLike
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- abstract def swap(v: A)(implicit txn: Context): A
Works like
set(v), but returns the old value.Works like
set(v), but returns the old value.- returns
the previous value of this
Ref, as observed bytxn.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- abstract def transform(f: (A) => A)(implicit txn: Context): Unit
Transforms the value referenced by this
Refby applying the functionf.Transforms the value referenced by this
Refby applying the functionf. Acts likeref.set(f(ref.get)), but the execution offmay be deferred or repeated by the STM to reduce transaction conflicts.- f
a function that is safe to call multiple times, and safe to call later during the transaction.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- abstract def transformIfDefined(pf: PartialFunction[A, A])(implicit txn: Context): Boolean
Transforms the value v referenced by this
Refby topf.apply(v), but only ifpf.isDefinedAt(v).Transforms the value v referenced by this
Refby topf.apply(v), but only ifpf.isDefinedAt(v). Returns true if a transformation was performed, false otherwise.pf.applyandpf.isDefinedAtmay be deferred or repeated by the STM to reduce transaction conflicts.- pf
a partial function that is safe to call multiple times, and safe to call later in the transaction.
- returns
pf.isDefinedAt(v), wherevwas the value of thisRefbefore transformation (if any).
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- abstract def trySet(v: A)(implicit txn: Context): Boolean
Performs a transactional write and returns true, or returns false.
Performs a transactional write and returns true, or returns false. The STM implementation may choose to return false to reduce (not necessarily avoid) blocking. If no other threads are performing any transactional or atomic accesses then this method will succeed.
- Definition Classes
- SinkLike
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- def *=(rhs: A)(implicit txn: Context, num: Numeric[A]): Unit
Transforms the value stored in the
Refby multiplying it.Transforms the value stored in the
Refby multiplying it.Note: Implementations may choose to ignore the provided
Numeric[A]instance ifAis a primitive type.- rhs
the quantity by which to multiply the value of this
Ref.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- def +=(rhs: A)(implicit txn: Context, num: Numeric[A]): Unit
Transforms the value stored in the
Refby incrementing it.Transforms the value stored in the
Refby incrementing it.Note: Implementations may choose to ignore the provided
Numeric[A]instance ifAis a primitive type.- rhs
the quantity by which to increment the value of this
Ref.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- def -=(rhs: A)(implicit txn: Context, num: Numeric[A]): Unit
Transforms the value stored in the
Refby decrementing it.Transforms the value stored in the
Refby decrementing it.Note: Implementations may choose to ignore the provided
Numeric[A]instance ifAis a primitive type.- rhs
the quantity by which to decrement the value of this
Ref.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- def /=(rhs: A)(implicit txn: Context, num: Numeric[A]): Unit
Transforms the value stored the
Refby performing a division on it, throwing away the remainder if division is not exact for instances of typeA.Transforms the value stored the
Refby performing a division on it, throwing away the remainder if division is not exact for instances of typeA. The careful reader will note that division is actually provided byFractional[A]orIntegral[A], it is not defined onNumeric[A]. To avoid compile-time ambiguity this method accepts aNumeric[A]and assumes that it can be converted at runtime into either aFractional[A]or anIntegral[A].Note: Implementations may choose to ignore the provided
Numeric[A]instance ifAis a primitive type.- rhs
the quantity by which to divide the value of this
Ref.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply()(implicit txn: Context): A
Performs a transactional read and checks that it is consistent with all reads already made by
txn.Performs a transactional read and checks that it is consistent with all reads already made by
txn. Equivalent toget.Example:
val x = Ref(0) atomic { implicit t => ... val v = x() // perform a read inside a transaction ... }
- txn
an active transaction.
- returns
the value of the
Refas observed bytxn.
- Definition Classes
- SourceLike
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def getAndTransform(f: (A) => A)(implicit txn: Context): A
Transforms the value referenced by this
Refby applying the functionf, and returns the previous value.Transforms the value referenced by this
Refby applying the functionf, and returns the previous value.- f
a function that is safe to call multiple times.
- returns
the previous value of this
Ref(the value passed tof).
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def transformAndExtract[B](f: (A) => (A, B))(implicit txn: Context): B
Transforms the value referenced by this
Reffrom v tof(v)._1, and returnsf(v)._2.Transforms the value referenced by this
Reffrom v tof(v)._1, and returnsf(v)._2.- f
a function that is safe to call multiple times.
- returns
the second element of the pair returned by
f.
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- def transformAndGet(f: (A) => A)(implicit txn: Context): A
Transforms the value referenced by this
Refby applying the functionf, and returns the new value.Transforms the value referenced by this
Refby applying the functionf, and returns the new value.- f
a function that is safe to call multiple times.
- returns
the new value of this
Ref(the value returned fromf).
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- def update(v: A)(implicit txn: Context): Unit
Performs a transactional write.
Performs a transactional write. The new value will not be visible by any other threads until (and unless)
txnsuccessfully commits. Equivalent toset(v).Example:
val x = Ref(0) atomic { implicit t => ... x() = 10 // perform a write inside a transaction ... }
- v
a value to store in the
Ref.
- Definition Classes
- SinkLike
- Exceptions thrown
IllegalStateExceptioniftxnis not active.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()