Package com.comphenix.protocol.reflect
Class VolatileField
java.lang.Object
com.comphenix.protocol.reflect.VolatileField
Represents a field that will revert to its original state when this class is garbaged collected.
- Author:
- Kristian
-
Constructor Summary
ConstructorsConstructorDescriptionVolatileField(FieldAccessor accessor, Object container)Initializes a volatile field with the given accessor and associated object.VolatileField(Field field, Object container)Initializes a volatile field with an associated object.VolatileField(Field field, Object container, boolean forceAccess)Initializes a volatile field with an associated object. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidfinalize()Retrieves the object the field is stored.getField()Retrieves the current field.Retrieves the field value before the previous setValue(), unless saveValue() has been called.getValue()Retrieves the current field value.booleanDetermine whether or not we'll need to revert the value.booleanRetrieves whether or not not to override any scope restrictions.voidReapply the current changed value.voidRevert to the previously set value.voidEnsure that the current value is still set after this class has been garbaged collected.voidsetForceAccess(boolean forceAccess)Sets whether or not not to override any scope restrictions.voidSets the current value.toString()Retrieve a synchronized version of the current field.
-
Constructor Details
-
VolatileField
Initializes a volatile field with an associated object.- Parameters:
field- - the field.container- - the object this field belongs to.
-
VolatileField
Initializes a volatile field with an associated object.- Parameters:
field- - the field.container- - the object this field belongs to.forceAccess- - whether or not to override any scope restrictions.
-
VolatileField
Initializes a volatile field with the given accessor and associated object.- Parameters:
accessor- - the field accessor.container- - the object this field belongs to.
-
-
Method Details
-
getField
Retrieves the current field.- Returns:
- The stored field.
-
getContainer
Retrieves the object the field is stored.- Returns:
- The reference object.
-
isForceAccess
public boolean isForceAccess()Retrieves whether or not not to override any scope restrictions.- Returns:
- TRUE if we override scope, FALSE otherwise.
-
setForceAccess
public void setForceAccess(boolean forceAccess)Sets whether or not not to override any scope restrictions.- Parameters:
forceAccess- - TRUE if we override scope, FALSE otherwise.
-
getValue
Retrieves the current field value.- Returns:
- The current field value.
-
getOldValue
Retrieves the field value before the previous setValue(), unless saveValue() has been called.- Returns:
- Previous value.
-
setValue
Sets the current value. This will be reverted unless saveValue() is called.- Parameters:
newValue- - new field value.
-
refreshValue
public void refreshValue()Reapply the current changed value.Also refresh the previously set value.
-
saveValue
public void saveValue()Ensure that the current value is still set after this class has been garbaged collected. -
revertValue
public void revertValue()Revert to the previously set value. -
toSynchronized
Retrieve a synchronized version of the current field.- Returns:
- A synchronized volatile field.
-
isCurrentSet
public boolean isCurrentSet()Determine whether or not we'll need to revert the value.- Returns:
- True if it is set, false if not.
-
finalize
-
toString
-