- java.lang.Object
-
- java.lang.invoke.CallSite
-
- java.lang.invoke.VolatileCallSite
-
public class VolatileCallSite extends CallSite
A VolatileCallSite acts as though its target MethodHandle were a volatile variable. This CallSite sub-class should be used if the changes to the target are frequent or if changes must be immediately observed by all threads, even if thesetTarget(MethodHandle)
occurs in a different thread.Since VolatileCallSite's target is defined as though it were a volatile variable, there is no need for a method like
MutableCallSite.syncAll(MutableCallSite[])
because every thread will always see a consistent view of the MethodHandle target.- Since:
- 1.7
-
-
Constructor Summary
Constructors Constructor Description VolatileCallSite(MethodHandle volatileTarget)
Create a VolatileCallSite with the same type as the volatileTarget and the initial target set to volatileTarget.VolatileCallSite(MethodType type)
Create a VolatileCallSite with the MethodType type and an initial target that throws IllegalStateException.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MethodHandle
getTarget()
The target MethodHandle is returned as though by a read of a volatile variable.void
setTarget(MethodHandle nextTarget)
Set the CallSite's target to be nextTarget.-
Methods declared in class java.lang.invoke.CallSite
dynamicInvoker, type
-
-
-
-
Constructor Detail
-
VolatileCallSite
public VolatileCallSite(MethodHandle volatileTarget) throws NullPointerException
Create a VolatileCallSite with the same type as the volatileTarget and the initial target set to volatileTarget.- Parameters:
volatileTarget
- - the target MethodHandle of the CallSite- Throws:
NullPointerException
- - if the volatileTarget is null.
-
VolatileCallSite
public VolatileCallSite(MethodType type) throws NullPointerException
Create a VolatileCallSite with the MethodType type and an initial target that throws IllegalStateException.- Parameters:
type
- - the permanent type of this CallSite.- Throws:
NullPointerException
- - if the type is null.
-
-
Method Detail
-
getTarget
public final MethodHandle getTarget()
The target MethodHandle is returned as though by a read of a volatile variable.
-
setTarget
public void setTarget(MethodHandle nextTarget) throws NullPointerException, WrongMethodTypeException
Set the CallSite's target to be nextTarget. The nextTarget MethodHandle must have the same type as the CallSite. This occurs as though by a write to a volatile variable.- Specified by:
setTarget
in classCallSite
- Parameters:
nextTarget
- - the new target value for the CallSite- Throws:
NullPointerException
- - if nextTarget is null.WrongMethodTypeException
- - if the type of nextTarget differs from that of the CallSite.
-
-