Class VolatileField

java.lang.Object
com.comphenix.protocol.reflect.VolatileField

public class VolatileField extends Object
Represents a field that will revert to its original state when this class is garbaged collected.
Author:
Kristian
  • Constructor Details

    • VolatileField

      public VolatileField(Field field, Object container)
      Initializes a volatile field with an associated object.
      Parameters:
      field - - the field.
      container - - the object this field belongs to.
    • VolatileField

      public VolatileField(Field field, Object container, boolean forceAccess)
      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

      public VolatileField(FieldAccessor accessor, Object container)
      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

      public Field getField()
      Retrieves the current field.
      Returns:
      The stored field.
    • getContainer

      public Object 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

      public Object getValue()
      Retrieves the current field value.
      Returns:
      The current field value.
    • getOldValue

      public Object getOldValue()
      Retrieves the field value before the previous setValue(), unless saveValue() has been called.
      Returns:
      Previous value.
    • setValue

      public void setValue(Object newValue)
      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

      public VolatileField 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

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • toString

      public String toString()
      Overrides:
      toString in class Object