Modifier and Type | Method and Description |
---|---|
static void |
addConverter(Converter<?> converter)
Adds the
Converter to the list of converters. |
static void |
addFeatureStateListener(FeatureStateListener listener)
Adds the given
FeatureStateListener to the list of listeners
that are notified when the state of a Feature has changed. |
static void |
addResourceControlListener(ResourceControlListener listener)
Adds the given
ResourceControlListener to the list of listeners
that are notified when a Feature is stopped by the Resource Control Manager. |
static boolean |
areEquivalentSharedInterfaces(java.lang.Class<?> si1,
java.lang.Class<?> si2)
Tells whether the given classes are equivalent shared interfaces.
|
static <T> T |
bind(T o,
java.lang.Class<T> targetType,
Feature targetOwner)
Binds an
Object owned by a Feature to another Feature. |
static boolean |
canUninstall(Feature f)
Tells whether the given Feature can be uninstalled.
|
static <T> T |
clone(T from,
Module toOwner)
Creates and returns a copy of the given object, so that the newly created object is owned by the given
Module . |
static void |
enter()
Enters in Kernel mode: the current thread context is switched to be owned by the Kernel.
|
static void |
exit()
Exits from Kernel mode: the current thread context is restored to the owner of the caller of the method (which can remain the Kernel).
|
static FeatureStateListener[] |
getAllFeatureStateListeners()
Returns an array containing all the
FeatureStateListener that
are notified when the state of a Feature has changed. |
static Feature[] |
getAllLoadedFeatures()
Returns the set of Features currently loaded.
|
static Module |
getContextOwner()
Returns the owner of the current thread context.
|
static java.lang.Class<?> |
getEquivalentSharedInterface(java.lang.Class<?> si,
Feature target)
Gets the equivalent shared interface in the given target Feature.
|
static java.lang.Class<?> |
getImplementedSharedInterface(java.lang.Class<?> fromClass,
java.lang.Class<?> topInterface)
Gets the first shared interface implemented by the given class under the hierarchy of
topInterface . |
static Kernel |
getInstance()
Returns the singleton instance representing the Kernel.
|
static Module |
getOwner(java.lang.Object o)
Returns the owner of the given
Object . |
static java.lang.Class<?> |
getSharedInterface(java.lang.Class<?> si,
java.lang.Class<?> topInterface,
Feature target)
From a shared interface, gets the closest shared interface in the given target Feature.
|
static Feature |
install(java.io.InputStream is)
Installs a Feature from an
InputStream . |
static boolean |
isAPI(java.lang.Class<?> c)
Tells whether the given class is a Kernel API.
|
static boolean |
isInKernelMode()
Tells whether the current thread context is currently in Kernel mode.
|
static boolean |
isSharedInterface(java.lang.Class<?> c)
Tells whether the given class is a shared interface (i.e.
|
static Feature |
load(java.io.InputStream is)
Installs a Feature from an
InputStream and starts it. |
static <T> Proxy<T> |
newProxy(T ref,
Module owner)
Allocates a new
Proxy and sets its reference to the given object. |
static void |
removeConverter(Converter<?> converter)
Removes the
Converter to the list of converters. |
static void |
removeFeatureStateListener(FeatureStateListener listener)
Removes the
FeatureStateListener to the list of listeners
that are notified when the state of a Feature has changed. |
static void |
removeResourceControlListener(ResourceControlListener listener)
Removes the
ResourceControlListener to the list of listeners
that are notified when a Feature is stopped by the Resource Control Manager. |
static void |
runUnderContext(Module contextOwner,
java.lang.Runnable runnable)
Calls the
Runnable.run() method with current context set to the given Module . |
static void |
setUncaughtExceptionHandler(UncaughtExceptionHandler handler)
Deprecated.
Use
Thread.setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) |
static void |
uninstall(Feature f)
Uninstalls a Feature.
|
static boolean |
unload(Feature f)
Stops a Feature and uninstalls it if its state is
Feature.State.INSTALLED after Feature.stop() . |
getExecutionCounter, getExecutionQuota, getName, getProvider, getUID, getVersion, setExecutionQuota
public static Kernel getInstance()
public static Feature load(java.io.InputStream is) throws java.io.IOException, InvalidFormatException, IncompatibleFeatureException, AlreadyLoadedFeatureException
InputStream
and starts it.is
- the input stream from where the Feature data is loaded.Feature.State.STARTED
state.java.io.IOException
- if something occurs when reading InputStream
AlreadyLoadedFeatureException
- if Feature is already loadedIncompatibleFeatureException
- if Feature is not compatible with the current KernelInvalidFormatException
- if Feature content is invalidinstall(InputStream)
,
Feature.start()
public static Feature install(java.io.InputStream is) throws java.io.IOException, InvalidFormatException, IncompatibleFeatureException, AlreadyLoadedFeatureException
InputStream
. Feature shall have been generated against the current Kernel classes.
Feature data is read and linked to the Kernel.
The Feature is added to the list of loaded features and its state is set to Feature.State.INSTALLED
.
The given input stream is let open.is
- the input stream from where the Feature data is loaded.Feature.State.INSTALLED
state.java.io.IOException
- if something occurs when reading InputStream
AlreadyLoadedFeatureException
- if Feature is already loadedIncompatibleFeatureException
- if Feature is not compatible with the current KernelInvalidFormatException
- if Feature content is invalidgetAllLoadedFeatures()
public static void uninstall(Feature f)
Feature.State.UNINSTALLED
.f
- the feature to be uninstalled.java.lang.IllegalStateException
- if Feature state is not Feature.State.INSTALLED
getAllLoadedFeatures()
public static boolean canUninstall(Feature f)
f
- the Feature to testtrue
if the Feature can be uninstalled,
false
otherwise.public static boolean unload(Feature f) throws UnknownFeatureException
Feature.State.INSTALLED
after Feature.stop()
.f
- the feature to be unloaded.true
if Feature state is Feature.State.UNINSTALLED
, false
otherwise.UnknownFeatureException
- if the given Feature is unknown.java.lang.IllegalStateException
- if Feature state is Feature.State.UNINSTALLED
uninstall(Feature)
,
Feature.stop()
public static Feature[] getAllLoadedFeatures()
Feature.State.UNINSTALLED
.public static void enter()
The context owner is automatically restored when returning from the method (equivalent to calling exit()
before returning).
exit()
public static void exit()
null
.enter()
public static boolean isInKernelMode()
Kernel.getContextOwner() == Kernel.getInstance()
public static Module getOwner(java.lang.Object o)
Object
.o
- the object.public static Module getContextOwner()
@Deprecated public static void setUncaughtExceptionHandler(@Nullable UncaughtExceptionHandler handler)
Thread.setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
handler
- the handler to register, or null
if no explicit handler.public static void addFeatureStateListener(FeatureStateListener listener)
FeatureStateListener
to the list of listeners
that are notified when the state of a Feature has changed.listener
- the new listener to addjava.lang.NullPointerException
- if listener is null
public static void addResourceControlListener(ResourceControlListener listener)
ResourceControlListener
to the list of listeners
that are notified when a Feature is stopped by the Resource Control Manager.listener
- the new listener to addjava.lang.NullPointerException
- if listener is null
public static void removeFeatureStateListener(FeatureStateListener listener)
FeatureStateListener
to the list of listeners
that are notified when the state of a Feature has changed.
Does nothing if the listener is not registered or null
.
listener
- the listener to be removedpublic static void removeResourceControlListener(ResourceControlListener listener)
ResourceControlListener
to the list of listeners
that are notified when a Feature is stopped by the Resource Control Manager.
Does nothing if the listener is not registered or null
.
listener
- the listener to be removedpublic static FeatureStateListener[] getAllFeatureStateListeners()
FeatureStateListener
that
are notified when the state of a Feature has changed.FeatureStateListener[]
with all the listenerspublic static void runUnderContext(Module contextOwner, java.lang.Runnable runnable)
Runnable.run()
method with current context set to the given Module
.contextOwner
- the context owner that will execute the methodrunnable
- the Runnable
instance to run under the given Feature
context.java.lang.IllegalAccessError
- if the Runnable
instance is not accessible to the context owner, or if the Runnable
is owned by a Feature and must run in Kernel context.java.lang.IllegalStateException
- if contextOwner
is a Feature and not in the Feature.State.STARTED
state.public static <T> T clone(T from, Module toOwner) throws java.lang.CloneNotSupportedException
Module
.
The source object class must be String
or must implement Cloneable
. Otherwise, a CloneNotSupportedException
is thrown.
If the source object owner and the target owner are the same, this method is equivalent to Object.clone()
method
applied on the source object.
Otherwise, the object can be cloned if the source object class is owned by the Kernel and all its object references are accessible to the new owner.
In all other cases, an IllegalAccessError
is thrown.T
- the Kernel type of the object to clonefrom
- the object to clonetoOwner
- the owner of the cloned objectjava.lang.CloneNotSupportedException
- if the source object cannot be clonedjava.lang.IllegalAccessError
- if the creation of the new object would break access rulesjava.lang.IllegalStateException
- if toOwner
is a Feature and not in the Feature.State.STARTED
state.java.lang.NullPointerException
- if one of the arguments is null
public static void addConverter(Converter<?> converter)
Converter
to the list of converters.
Registered converters are used by bind(Object, Class, Feature)
.converter
- the new converter to addjava.lang.NullPointerException
- if converter is null
java.lang.IllegalArgumentException
- if a converter managing the same type is already registeredConverter.getType()
public static void removeConverter(Converter<?> converter)
Converter
to the list of converters.
Does nothing if the converter is not registered or null
.
converter
- the converter to be removed@Nullable public static <T> T bind(@Nullable T o, java.lang.Class<T> targetType, Feature targetOwner)
Binds an Object
owned by a Feature to another Feature.
When the target type is owned by the Kernel, the object is converted using the most accurate registered converter.
When the target type is owned by the Feature, it must be a shared interface.
In this case, a Proxy
instance is returned.
Object
identity is preserved across Features: calling multiple times this method with the same parameters returns the same object.
T
- the Kernel type of the object to bindo
- the object to be convertedtargetType
- the type of the converted objecttargetOwner
- the owner of the converted objectnull
if o is null
or is a Proxy
that refers to a dead objectjava.lang.IllegalAccessError
- if the given object cannot be bounded to the given typejava.lang.IllegalArgumentException
- if the given type is not a shared interfacejava.lang.IllegalStateException
- if targetOwner
is not in the Feature.State.STARTED
state.public static boolean isSharedInterface(java.lang.Class<?> c)
c
- the class to testtrue
if the class is a shared interface, false
otherwisepublic static <T> Proxy<T> newProxy(T ref, Module owner)
Proxy
and sets its reference to the given object.T
- the reference typeref
- the Proxy
referenceowner
- the owner of the Proxy
instanceProxy
instance initialized with the given referencejava.lang.IllegalStateException
- if owner
is a Feature and not in the Feature.State.STARTED
state.public static boolean isAPI(java.lang.Class<?> c)
c
- the class to testtrue
if the class is a Kernel API, false
otherwise@Nullable public static java.lang.Class<?> getSharedInterface(java.lang.Class<?> si, java.lang.Class<?> topInterface, Feature target)
From a shared interface, gets the closest shared interface in the given target Feature.
The closest shared interface is computed by returning the first equivalent shared interface in the target Feature,
starting from the interface si
to the interface topInterface
(included).
If the owner of the given shared interface is the target, the same shared interface is returned.
si
- a shared interface that extends topInterface
interfacetopInterface
- a shared interface or an interface owned by the Kernel, which is assignable from si
.target
- the target Feature where to find the closest equivalent shared interface of si
null
if not found.java.lang.IllegalArgumentException
- if si
is not a shared interface or if topInterface
is not an interface or if topInterface
is not assignable from fromClass
getEquivalentSharedInterface(Class, Feature)
@Nullable public static java.lang.Class<?> getEquivalentSharedInterface(java.lang.Class<?> si, Feature target)
Gets the equivalent shared interface in the given target Feature.
The equivalent shared interface is the interface owned by the target Feature such as areEquivalentSharedInterfaces(Class, Class)
is true
.
si
- a shared interfacetarget
- the target Feature where to find the equivalent shared interface of si
null
if not foundjava.lang.IllegalArgumentException
- if si
is not a shared interfacepublic static boolean areEquivalentSharedInterfaces(java.lang.Class<?> si1, java.lang.Class<?> si2)
Tells whether the given classes are equivalent shared interfaces.
Two classes are equivalent shared interfaces if they are shared interfaces and have the same fully qualified name.
si1
- a class to testsi2
- a class to testtrue
if the given classes are equivalent shared interfaces, false
otherwise@Nullable public static java.lang.Class<?> getImplementedSharedInterface(java.lang.Class<?> fromClass, java.lang.Class<?> topInterface)
Gets the first shared interface implemented by the given class under the hierarchy of topInterface
.
If fromClass
is a shared interface it is directly returned.
fromClass
- a class or an interface owned by a Feature
that implements topInterface
topInterface
- an interface implemented by fromClass
null
if no shared interface foundjava.lang.IllegalArgumentException
- if the given class is an array or is owned by the Kernel or if topInterface
is not an interface or if topInterface
is not assignable from fromClass