Class ComponentKernel

java.lang.Object
arez.component.internal.ComponentKernel
All Implemented Interfaces:
ComponentObservable, Disposable

@OmitClinit public final class ComponentKernel extends Object implements Disposable, ComponentObservable
The "kernel" of the components generated by the annotation processor. This class exists so that code common across multiple components is not present in every generated class but is instead in a single location. This results in smaller, faster code.
  • Constructor Details

  • Method Details

    • observe

      public boolean observe()
      Description copied from interface: ComponentObservable
      Return true if the component is "alive" a.k.a. not disposing or disposed. This method MUST be invoked within a non-DISPOSE transaction and will add the component as a dependency if the transaction is tracking, unless this component is disposing or disposed.
      Specified by:
      observe in interface ComponentObservable
      Returns:
      true if the component is "alive" a.k.a. not disposing or disposed.
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Dispose the element. See Disposable for a description of the implications.
      Specified by:
      dispose in interface Disposable
    • isDisposed

      public boolean isDisposed()
      Description copied from interface: Disposable
      Return true if dispose() has been called on object.
      Specified by:
      isDisposed in interface Disposable
      Returns:
      true if dispose has been called.
    • notifyOnDisposeListeners

      public void notifyOnDisposeListeners()
      Notify an OnDispose listeners that have been added to the component. This method MUST only be called if the component has enabled onDisposeNotify feature.
    • hasBeenInitialized

      public boolean hasBeenInitialized()
      Return true if the component has been initialized.
      Returns:
      true if the component has been initialized.
    • hasBeenConstructed

      public boolean hasBeenConstructed()
      Return true if the component has been constructed.
      Returns:
      true if the component has been constructed.
    • hasBeenCompleted

      public boolean hasBeenCompleted()
      Return true if the component has been completed.
      Returns:
      true if the component has been completed.
    • isConstructed

      public boolean isConstructed()
      Return true if the component is in COMPONENT_CONSTRUCTED state.
      Returns:
      true if the component is in COMPONENT_CONSTRUCTED state.
    • isComplete

      public boolean isComplete()
      Return true if the component is in COMPONENT_COMPLETE state.
      Returns:
      true if the component is in COMPONENT_COMPLETE state.
    • isReady

      public boolean isReady()
      Return true if the component is ready.
      Returns:
      true if the component is ready.
    • isNotReady

      public boolean isNotReady()
      Return true if the component is NOT ready.
      Returns:
      true if the component is NOT ready.
    • isDisposing

      public boolean isDisposing()
      Return true if the component is disposing.
      Returns:
      true if the component is disposing.
    • isActive

      public boolean isActive()
      Return true if the component is active and can be interacted with. This means that the component has been constructed and has not started to be disposed.
      Returns:
      true if the component is active.
    • describeState

      @Nonnull public String describeState()
      Describe component state. This is usually used to provide error messages.
      Returns:
      a string description of the state.
    • componentConstructed

      public void componentConstructed()
      Transition component state from COMPONENT_INITIALIZED to COMPONENT_CONSTRUCTED.
    • componentComplete

      public void componentComplete()
      Transition component state from COMPONENT_INITIALIZED to COMPONENT_CONSTRUCTED and then to COMPONENT_READY. This should only be called if there is active elements that are part of the component that need to be scheduled, otherwise the component can transition directly to ready.
    • componentReady

      public void componentReady()
      Transition component state from COMPONENT_CONSTRUCTED to COMPONENT_READY. This should be invoked rather than componentComplete() if there is no active elements of the component that need to be scheduled.
    • getContext

      @Nonnull public ArezContext getContext()
      Return the context in which this component was created.
      Returns:
      the associated context.
    • safeSetObservable

      public void safeSetObservable(@Nullable String name, @Nonnull SafeProcedure setter)
      Invoke the setter in a transaction. If a transaction is active then invoke the setter directly, otherwise wrap the setter in an action.
      Parameters:
      name - the name of the action if it is needed.
      setter - the setter action to invoke.
    • setObservable

      public void setObservable(@Nullable String name, @Nonnull Procedure setter) throws Throwable
      Invoke the setter in a transaction. If a transaction is active then invoke the setter directly, otherwise wrap the setter in an action.
      Parameters:
      name - the name of the action if it is needed.
      setter - the setter action to invoke.
      Throws:
      Throwable - if setter throws an exception.
    • getName

      @Nonnull public String getName()
      Return the name of the component. This method should NOT be invoked unless Arez.areNamesEnabled() returns true and will throw an exception if invariant checking is enabled.
      Returns:
      the name of the component.
    • getId

      public int getId()
      Return the synthetic id associated with the component. This method MUST NOT be invoked if a synthetic id is not present and will generate an invariant failure when invariants are enabled.
      Returns:
      the synthetic id associated with the component.
    • getComponent

      @OmitSymbol(unless="arez.enable_native_components") @Nonnull public Component getComponent()
      Return the native component associated with the component. This method MUST NOT be invoked if native components are disabled.
      Returns:
      the native component associated with the component.
    • addOnDisposeListener

      public void addOnDisposeListener(@Nonnull Object key, @Nonnull SafeProcedure action)
      Add the listener to notify list under key. This method MUST NOT be invoked after dispose() has been invoked. This method should not be invoked if another listener has been added with the same key without being removed.

      If the key implements Disposable and Disposable.isDisposed() returns true when invoking the calback then the callback will be skipped. This rare situation only occurs when there is circular dependency in the object model usually involving CascadeDispose.

      Parameters:
      key - the key to uniquely identify listener.
      action - the listener callback.
    • removeOnDisposeListener

      public void removeOnDisposeListener(@Nonnull Object key)
      Remove the listener with specified key from the notify list. This method should only be invoked when a listener has been added for specific key using addOnDisposeListener(Object, SafeProcedure) and has not been removed by another call to this method.
      Parameters:
      key - the key under which the listener was previously added.
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object