Package ej.kf

Class Feature


  • public class Feature
    extends Module

    A Feature represents an optional part of an application that adds new features and services.

    A Feature only depends on Kernel code. A Feature is considered as unreliable code from Kernel point of view.

    Instances of this class are owned by the Kernel.

    • Method Detail

      • getAllAliveThreads

        public Thread[] getAllAliveThreads()
        Gets a snapshot of all alive threads owned by this Feature (some threads included in the returned array may have been terminated when this method returns, some new threads may have been created when this method returns).
        Returns:
        the threads owned by this Feature
        Throws:
        IllegalStateException - if the Feature is not in the Feature.State.STARTED state
      • getState

        public Feature.State getState()
        Returns the current Feature state.
        Returns:
        this Feature's state.
        See Also:
        Feature.State
      • start

        public void start()
        Causes this Feature to start. A new thread owned by the Feature is created and started. The Feature is switched in the Feature.State.STARTED state and this method returns. Next steps are executed asynchronously within the new thread context:
        Throws:
        IllegalStateException - if the Feature state is not in Feature.State.INSTALLED state
      • getCriticality

        public int getCriticality()
        Returns the criticality of this feature.

        The criticality is used by the system to determine which feature to kill when there is memory pressure. The features with the lowest criticality will be killed first. The features with a criticality set to MAX_CRITICALITY are not killed automatically by the system when there is memory pressure.

        The default criticality of a feature is NORM_CRITICALITY.

        Returns:
        the criticality.
        Throws:
        IllegalStateException - if this feature is in Feature.State.UNINSTALLED state.
      • getResourceAsStream

        @Nullable
        public InputStream getResourceAsStream​(String name)
        Finds in this feature the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed from code.

        The name of a resource is a '/'-separated path name that identifies the resource. This path must be absolute (i.e., begins with a '/'); if not, this method returns null.

        This method will search this feature for the resource. It will not search the Kernel for the resource.

        The returned input stream is automatically closed when this feature is uninstalled.

        Parameters:
        name - The resource name
        Returns:
        An input stream for reading the resource, or null if the resource could not be found.
        Throws:
        IllegalStateException - if this feature is in Feature.State.UNINSTALLED state.
      • getMemoryLimit

        public long getMemoryLimit()
        Gets the maximum amount of memory heap that can be allocated by this Feature. By default, the maximum amount of memory heap is equal to Runtime.maxMemory() (disabled).
        Returns:
        the maximum amount of memory heap that can be allocated by this Feature (in bytes)
        Throws:
        IllegalStateException - if this feature is in Feature.State.UNINSTALLED state.
        Since:
        1.7
        See Also:
        setMemoryLimit(long)