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.
Modifier and Type | Class and Description |
---|---|
static class |
Feature.State
A Feature state.
|
Modifier and Type | Field and Description |
---|---|
static int |
MAX_CRITICALITY
The maximum criticality that a feature can have.
|
static int |
MIN_CRITICALITY
The minimum criticality that a feature can have.
|
static int |
NORM_CRITICALITY
The default criticality that is assigned to a feature.
|
Modifier and Type | Method and Description |
---|---|
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).
|
int |
getCriticality()
Returns the criticality of this feature.
|
long |
getMemoryLimit()
Gets the maximum amount of memory heap that can be allocated by this Feature.
|
InputStream |
getResourceAsStream(String name)
Finds in this feature the resource with the given name.
|
Feature.State |
getState()
Returns the current Feature state.
|
void |
setCriticality(int criticality)
Sets the criticality of this feature.
|
boolean |
setMemoryLimit(long size)
Sets the maximum amount of memory heap that can be allocated by this Feature.
|
void |
start()
Causes this Feature to start.
|
void |
stop()
Causes this Feature to stop.
|
getAllocatedMemory, getExecutionCounter, getExecutionQuota, getName, getProvider, getUID, getVersion, setExecutionQuota
public static final int MAX_CRITICALITY
getCriticality()
,
Constant Field Valuespublic static final int MIN_CRITICALITY
getCriticality()
,
Constant Field Valuespublic static final int NORM_CRITICALITY
getCriticality()
,
Constant Field Valuespublic Thread[] getAllAliveThreads()
IllegalStateException
- if the Feature is not in the Feature.State.STARTED
statepublic int getCriticality()
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
.
IllegalStateException
- if this feature is in Feature.State.UNINSTALLED
state.public long getMemoryLimit()
Runtime.maxMemory()
(disabled).IllegalStateException
- if this feature is in Feature.State.UNINSTALLED
state.setMemoryLimit(long)
@Nullable public InputStream getResourceAsStream(String name)
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.
name
- The resource namenull
if the resource could not be found.IllegalStateException
- if this feature is in Feature.State.UNINSTALLED
state.public Feature.State getState()
Feature.State
public void setCriticality(int criticality)
criticality
- the new criticality of this feature.IllegalArgumentException
- If the criticality is not in the range MIN_CRITICALITY
to MAX_CRITICALITY
.IllegalStateException
- if this feature is in Feature.State.UNINSTALLED
state.getCriticality()
public boolean setMemoryLimit(long size)
Module.getAllocatedMemory()
. OutOfMemoryError
is thrown during an allocation made by a Feature if its memory usage would exceed
this limit.size
- the maximum amount of memory heap that can be allocated by this Feature (in bytes)true
if the maximum amount of memory heap has been updated, false
otherwise.IllegalArgumentException
- if the requested size is negative or greater than the memory heap (Runtime.maxMemory()
)IllegalStateException
- if this feature is in Feature.State.UNINSTALLED
state.getMemoryLimit()
,
Module.getAllocatedMemory()
public void start()
Feature.State.STARTED
state and this method returns. Next steps are executed asynchronously within the new
thread context:
FeatureEntryPoint.start()
is calledIllegalStateException
- if the Feature state is not in Feature.State.INSTALLED
statepublic void stop()
FeatureEntryPoint.stop()
is executed.ej.lang.Resource.reclaim()
is called for each resource that remains open by the Feature.DeadFeatureException
is thrown in threads that are running Feature code or in threads that want to
call Feature code.Feature.State.STOPPED
.Feature.State.INSTALLED
.
When the new Feature state is Feature.State.INSTALLED
, the Feature runtime has been fully reclaimed (threads and
objects). Otherwise, the new Feature state is Feature.State.STOPPED
and there are some remaining Feature objects
references from Kernel.
This method can be called multiple times by the Kernel to reclaim objects again and thus to try to switch the
Feature in the Feature.State.INSTALLED
state.
When Feature state is set to Feature.State.STOPPED
, Kernel application shall remove all its references to objects
owned by this Feature, through the calls of FeatureStateListener.stateChanged(ej.kf.Feature, ej.kf.Feature.State)
.
IllegalStateException
- if the Feature is in the Feature.State.INSTALLED
or Feature.State.UNINSTALLED
state