Class ConcurrentInferenceContext
- java.lang.Object
-
- com.aquima.interactions.portal.model.session.concurrent.ConcurrentInferenceContext
-
- All Implemented Interfaces:
IEventChannel
,IProfile
,IProfileLifecycle
,InferenceContext
,Serializable
public class ConcurrentInferenceContext extends Object implements InferenceContext
Inference context that may be used to handle concurrent profile calls.- Since:
- 8.4.3
- Author:
- Jon van Leuven
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ConcurrentInferenceContext(InferenceContext context, ReadWriteLock lock)
Construct a concurrent inference context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate(IProfileActivationContext profileActivationContext)
This method may be used for activating the profile after deserialization.boolean
addEventListener(IEventListener listener)
This method will add the passed event listener to the list of listeners.void
commitTransaction(String name)
Commits the current transaction in the profile.IEntityInstance
createInstance(String entityName)
This method creates a new empty instance for the specified entity type.IEntityInstance
createInstance(String entityName, GUID instanceId, String instanceName)
This method creates a new empty instance for the specified entity type.void
deleteInstance(IEntityInstance instance, boolean autoDetach)
Deletes the given instance, rendering the parameter useless.IEntityInstance
getActiveInstance(String entityName)
This method returns the active instance for the specified type.IEntityInstance[]
getAllInstancesForEntity(String entityName, boolean includeChildren)
This method returns all existing instances of a certain type in the profile.IEntityDefinition
getEntityDefinition(String entityName)
This method returns an entity definition for the supplied entity name.IInferenceDetails
getInferenceDetails(ValueReference attributeReference)
This method may be used to request detailed inference information for a specific attribute.IEntityInstance
getInstance(EntityValue instance)
This method can be used to lookup an instance based on a reference.IEntityInstance
getInstanceById(String entityName, GUID instanceId)
This method returns the instance of the specified type for the given instance id.IEntityInstance
getInstanceByName(String entityName, String instanceName)
This method returns an instance of the specified type for the given instance name.IEntityInstance
getSingletonInstance(String entityName, boolean create)
This method can be used to retrieve the singleton instance from the profile for a specific entity type.IProfileState
getState()
Returns the state of the profile (for serialization)int
getSupportedEvents()
Deze methode geeft een bit-mask met daarin alle event types die door dit event channel ondersteund worden.void
passivate()
This method may be used for preparing the profile for serialization.boolean
removeEventListener(IEventListener listener)
This method will remove the specified event listener from the list of listeners.void
restore(IProfileState state)
Clears the current state and overrides it with the provided state.void
rollbackTransaction(String name)
Performs a roll-back of all changes since the last start of a transaction.void
startTransaction(String name)
Starts a new transaction in the profile.IEntityInstance
wrapInstance(IEntityInstance instance)
IEntityInstance[]
wrapInstances(IEntityInstance[] allInstancesForEntity)
-
-
-
Constructor Detail
-
ConcurrentInferenceContext
public ConcurrentInferenceContext(InferenceContext context, ReadWriteLock lock)
Construct a concurrent inference context.- Parameters:
context
- The delegate inference context, may not be null.lock
- The read/write lock to handle concurrent calls, may not be null.
-
-
Method Detail
-
getInstance
public IEntityInstance getInstance(EntityValue instance) throws UnknownEntityException, UnknownInstanceException, InstanceCastException
Description copied from interface:IProfile
This method can be used to lookup an instance based on a reference.- Specified by:
getInstance
in interfaceIProfile
- Parameters:
instance
- InstanceReference of the instance that should be returned.- Returns:
- IEntityInstance The entity instance for the specified ID.
- Throws:
UnknownEntityException
- This exception is thrown when the entity value contains an invalid entity name.UnknownInstanceException
- This exception is thrown when the entity value refers to an unknown instance.InstanceCastException
- This exception is thrown when the ID of the entity value does not match the actual type.
-
getInstanceByName
public IEntityInstance getInstanceByName(String entityName, String instanceName) throws UnknownEntityException, UnknownInstanceException, InstanceCastException
Description copied from interface:IProfile
This method returns an instance of the specified type for the given instance name.- Specified by:
getInstanceByName
in interfaceIProfile
- Parameters:
entityName
- The name of the entity (type) of which the instance should be.instanceName
- The name of the instance.- Returns:
- IEntityInstance object of the correct type for the specified name.
- Throws:
UnknownEntityException
- This exception is raised when the specified entity name is not known by the profile.UnknownInstanceException
- This exception is raised when no instance of the requested type can be found for the specified name.InstanceCastException
- This exception is raised when the type of the instance referred by the specified name could not be cast to the requested type.
-
getInstanceById
public IEntityInstance getInstanceById(String entityName, GUID instanceId) throws UnknownEntityException, UnknownInstanceException, InstanceCastException
Description copied from interface:IProfile
This method returns the instance of the specified type for the given instance id. The id of an instance is generated when the instance is created, and can thus only be used within the same session.- Specified by:
getInstanceById
in interfaceIProfile
- Parameters:
entityName
- The name of the entity (type) of which the instance should be.instanceId
- The (unique) id of the instance.- Returns:
- IEntityInstance object of the correct type for the specified name.
- Throws:
UnknownEntityException
- This exception is raised when the specified entity name is not known by the profile.UnknownInstanceException
- This exception is raised when no instance of the requested type can be found for the specified name.InstanceCastException
- This exception is raised when the type of the instance referred by the specified name could not be cast to the requested type.
-
getSingletonInstance
public IEntityInstance getSingletonInstance(String entityName, boolean create) throws UnknownEntityException, UnknownInstanceException, CreateInstanceException
Description copied from interface:IProfile
This method can be used to retrieve the singleton instance from the profile for a specific entity type. Depending on the value of the create parameter that is passed, the behavior of this method differs slightly.
- When there is a singleton instance present in the profile for the specified type, this method will return that instance regardless the value of create.
- When no instance is present for the specified type and create is set to true, the singleton instance will be created and returned.
- When no instance is present for the specified type and create is set to false, an UnknownInstanceException will be thrown.
- Specified by:
getSingletonInstance
in interfaceIProfile
- Parameters:
entityName
- String the Name of the entitycreate
- boolean indicating whether the singleton instance should be created in case it does not exist yet.- Returns:
- IEntityInstance interface pointing to the singleton ('0'th) instance for the specified entity type.
- Throws:
UnknownEntityException
- When the specified entity name is invalid/unknown.UnknownInstanceException
- When the singleton instance did not exist and/or could not be created.CreateInstanceException
- This type of exception may be raised when a singleton instance is requested for a non-singleton entity type.
-
getAllInstancesForEntity
public IEntityInstance[] getAllInstancesForEntity(String entityName, boolean includeChildren) throws UnknownEntityException
Description copied from interface:IProfile
This method returns all existing instances of a certain type in the profile. Even when there are no instances available for a certain type an empty array will be returned.- Specified by:
getAllInstancesForEntity
in interfaceIProfile
- Parameters:
entityName
- The entity type for which the instances are requested.includeChildren
- when this option is passed as true, all child entity-types are also returned.- Returns:
- An array of instances for the specified type (never null).
- Throws:
UnknownEntityException
- When the specified entity name is invalid/unknown.
-
createInstance
public IEntityInstance createInstance(String entityName) throws UnknownEntityException, CreateInstanceException
Description copied from interface:IProfile
This method creates a new empty instance for the specified entity type. The name and id of this new instance are generated by the profile itself.- Specified by:
createInstance
in interfaceIProfile
- Parameters:
entityName
- The name of the entity for which a new instance should be created.- Returns:
- A new instance for the specified type. Never null.
- Throws:
UnknownEntityException
- The passed entity name argument is invalid, the type is unknown.CreateInstanceException
- This type of exception is raised when the instance could not be created.
-
createInstance
public IEntityInstance createInstance(String entityName, GUID instanceId, String instanceName) throws UnknownEntityException, CreateInstanceException
Description copied from interface:IProfile
This method creates a new empty instance for the specified entity type. This method may supply either a name or ID which will be used by the profile to determine these values. When ID and instanceName are supplied with null, the behavior of this function is exactly the same as createInstance( String entityName ).- Specified by:
createInstance
in interfaceIProfile
- Parameters:
entityName
- The name of the entity for which a new instance should be created.instanceId
- Unique ID of the new instance. When null is supplied, an ID will be generated by the profile.instanceName
- Unique name of the new instance. when null is supplied a name will be generated by the profile.- Returns:
- A new instance for the specified type. Never null.
- Throws:
UnknownEntityException
- The passed entity name argument is invalid, the type is unknown.CreateInstanceException
- This exception is raised when the instance could not be created.
-
deleteInstance
public void deleteInstance(IEntityInstance instance, boolean autoDetach) throws UnknownInstanceException, RemoveInstanceException
Description copied from interface:IProfile
Deletes the given instance, rendering the parameter useless. Please ensure no calls to the parameter IEntityInstance will be done after the deleteInstance.- Specified by:
deleteInstance
in interfaceIProfile
- Parameters:
instance
- IEntityInstance the instance to delete.autoDetach
- Boolean indicating if references to this instance should automatically be updated.- Throws:
UnknownInstanceException
- When entity or instance does not exist.RemoveInstanceException
- When the instance could not be removed (for instance when it is still referred to by others).
-
getEntityDefinition
public IEntityDefinition getEntityDefinition(String entityName) throws UnknownEntityException
Description copied from interface:IProfile
This method returns an entity definition for the supplied entity name.- Specified by:
getEntityDefinition
in interfaceIProfile
- Parameters:
entityName
- The name of the entity for which the definition is requested.- Returns:
- IEntityDefinition object containing the static entity information.
- Throws:
UnknownEntityException
- This exception is raised when the specified entity name is not known by the profile.
-
startTransaction
public void startTransaction(String name)
Description copied from interface:IProfile
Starts a new transaction in the profile.- Specified by:
startTransaction
in interfaceIProfile
- Parameters:
name
- Unique name identifying the transaction.
-
commitTransaction
public void commitTransaction(String name) throws AppException
Description copied from interface:IProfile
Commits the current transaction in the profile.- Specified by:
commitTransaction
in interfaceIProfile
- Parameters:
name
- Unique name identifying the transaction.- Throws:
AppException
- when no transaction has been started.
-
rollbackTransaction
public void rollbackTransaction(String name) throws AppException
Description copied from interface:IProfile
Performs a roll-back of all changes since the last start of a transaction.- Specified by:
rollbackTransaction
in interfaceIProfile
- Parameters:
name
- Unique name identifying the transaction.- Throws:
AppException
- when no transaction has been started.
-
getSupportedEvents
public int getSupportedEvents()
Description copied from interface:IEventChannel
Deze methode geeft een bit-mask met daarin alle event types die door dit event channel ondersteund worden. Dit bit-mask is een bitwise OR van de diverse event typen. Om te controleren of een specifieke event-listener ondersteund wordt, kan je het volgende doen:// dit controlleer of een VALUE listener ondersteund wordt if ((channel.getSupportedEvents() & IEvent.Mask.VALUE) != 0) { // VALUE event listeners worden ondersteund }
TODO translate to English- Specified by:
getSupportedEvents
in interfaceIEventChannel
- Returns:
- Bit-mask met daarin de event typen die ondersteund worden door het event channel.
-
addEventListener
public boolean addEventListener(IEventListener listener)
Description copied from interface:IEventChannel
This method will add the passed event listener to the list of listeners.- Specified by:
addEventListener
in interfaceIEventChannel
- Parameters:
listener
- The event listener that should be added.- Returns:
- boolean indicating is the listener was actually added.
-
removeEventListener
public boolean removeEventListener(IEventListener listener)
Description copied from interface:IEventChannel
This method will remove the specified event listener from the list of listeners.- Specified by:
removeEventListener
in interfaceIEventChannel
- Parameters:
listener
- The event listener that should be removed.- Returns:
- boolean indicating if the listener was actually removed.
-
getActiveInstance
public IEntityInstance getActiveInstance(String entityName) throws UnknownInstanceException, UnknownEntityException, CreateInstanceException
Description copied from interface:InferenceContext
This method returns the active instance for the specified type. When no active instance can be found for the specified type, the type is assumed to be a singleton instance. When this method is invoked for a non singleton type without any active instance, the call to the getSingletonInstance will fail due to a CreateInstanceException.- Specified by:
getActiveInstance
in interfaceInferenceContext
- Parameters:
entityName
- The entity type for which the active instance is requested.- Returns:
- The instance that is active for the specified type.
- Throws:
UnknownInstanceException
- This exception type is raised when no active instance could be found for the specified type.UnknownEntityException
- This exception type is raised when the entity type is unknown.CreateInstanceException
- This type of exception may be raised when a singleton instance could not be created for the specified type.
-
getInferenceDetails
public IInferenceDetails getInferenceDetails(ValueReference attributeReference) throws AppException
Description copied from interface:InferenceContext
This method may be used to request detailed inference information for a specific attribute. The details object contains information like which rule inferenced the value, and what other values were used by the rule engine to determine the current result.- Specified by:
getInferenceDetails
in interfaceInferenceContext
- Parameters:
attributeReference
- The reference to the attribute whose inference information is requested.- Returns:
- Object containing detailed information about the value related to the inference process.
- Throws:
AppException
- This exception is thrown when the inference details could not be retrieved.
-
wrapInstances
public IEntityInstance[] wrapInstances(IEntityInstance[] allInstancesForEntity)
-
wrapInstance
public IEntityInstance wrapInstance(IEntityInstance instance)
-
getState
public IProfileState getState()
Description copied from interface:IProfile
Returns the state of the profile (for serialization)
-
restore
public void restore(IProfileState state)
Description copied from interface:IProfile
Clears the current state and overrides it with the provided state.
-
passivate
public void passivate()
Description copied from interface:IProfileLifecycle
This method may be used for preparing the profile for serialization.- Specified by:
passivate
in interfaceIProfileLifecycle
-
activate
public void activate(IProfileActivationContext profileActivationContext)
Description copied from interface:IProfileLifecycle
This method may be used for activating the profile after deserialization.- Specified by:
activate
in interfaceIProfileLifecycle
- Parameters:
profileActivationContext
- the current profile activation context.
-
-