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(Class<?> si1,
Class<?> si2)
Tells whether the given classes are equivalent shared interfaces.
|
static <T> T |
bind(T o,
Class<T> targetType,
Feature targetOwner)
Binds an
Object owned by a Feature to another Feature. |
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 Class<?> |
getEquivalentSharedInterface(Class<?> si,
Feature target)
Gets the equivalent shared interface in the given target Feature.
|
static Class<?> |
getImplementedSharedInterface(Class<?> fromClass,
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(Object o)
Returns the owner of the given
Object . |
static Class<?> |
getSharedInterface(Class<?> si,
Class<?> topInterface,
Feature target)
From a shared interface, gets the closest shared interface in the given target Feature.
|
static Feature |
install(InputStream is)
Installs a Feature from an
InputStream . |
static boolean |
isAPI(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(Class<?> c)
Tells whether the given class is a shared interface (i.e.
|
static Feature |
load(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,
Runnable runnable)
Calls the
Runnable.run() method with current context set to the given Module . |
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 void addConverter(Converter<?> converter)
Converter
to the list of converters.
Registered converters are used by bind(Object, Class, Feature)
.converter
- the new converter to addNullPointerException
- if converter is null
IllegalArgumentException
- if a converter managing the same type is already registeredConverter.getType()
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 addNullPointerException
- 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 addNullPointerException
- if listener is null
public static boolean areEquivalentSharedInterfaces(Class<?> si1, 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 <T> T bind(@Nullable T o, 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 objectIllegalAccessError
- if the given object cannot be bounded to the given typeIllegalArgumentException
- if the given type is not a shared interfaceIllegalStateException
- if targetOwner
is not in the Feature.State.STARTED
state.public static <T> T clone(T from, Module toOwner) throws 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 objectCloneNotSupportedException
- if the source object cannot be clonedIllegalAccessError
- if the creation of the new object would break access rulesIllegalStateException
- if toOwner
is a Feature and not in the Feature.State.STARTED
state.NullPointerException
- if one of the arguments is null
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 FeatureStateListener[] getAllFeatureStateListeners()
FeatureStateListener
that
are notified when the state of a Feature has changed.FeatureStateListener[]
with all the listenerspublic static Feature[] getAllLoadedFeatures()
Feature.State.UNINSTALLED
.public static Module getContextOwner()
@Nullable public static Class<?> getEquivalentSharedInterface(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 foundIllegalArgumentException
- if si
is not a shared interface@Nullable public static Class<?> getImplementedSharedInterface(Class<?> fromClass, 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 foundIllegalArgumentException
- 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
public static Kernel getInstance()
public static Module getOwner(Object o)
Object
.o
- the object.@Nullable public static Class<?> getSharedInterface(Class<?> si, 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.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)
public static Feature install(InputStream is) throws 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.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 boolean isAPI(Class<?> c)
c
- the class to testtrue
if the class is a Kernel API, false
otherwisepublic static boolean isInKernelMode()
Kernel.getContextOwner() == Kernel.getInstance()
public static boolean isSharedInterface(Class<?> c)
c
- the class to testtrue
if the class is a shared interface, false
otherwisepublic static Feature load(InputStream is) throws IOException, InvalidFormatException, IncompatibleFeatureException, AlreadyLoadedFeatureException
InputStream
and starts it.is
- the input stream from where the Feature data is loaded.Feature.State.STARTED
state.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 <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 referenceIllegalStateException
- if owner
is a Feature and not in the Feature.State.STARTED
state.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 removedpublic 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 void runUnderContext(Module contextOwner, 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.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.IllegalStateException
- if contextOwner
is a Feature and not in the Feature.State.STARTED
state.public static void uninstall(Feature f)
Feature.State.UNINSTALLED
.f
- the feature to be uninstalled.IllegalStateException
- if Feature state is not Feature.State.INSTALLED
getAllLoadedFeatures()
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.IllegalStateException
- if Feature state is Feature.State.UNINSTALLED
uninstall(Feature)
,
Feature.stop()