Class Language
java.lang.Object
org.logicmachine.rebl.common.KeyValue
org.logicmachine.rebl.language.Language
- All Implemented Interfaces:
Maybe
Top-level class defining the entry-point into the language.
In particular, this class creates an instance of the Grammar associated with this language as well as the top-most scope instance and the default system exception handler.
In particular, this class creates an instance of the Grammar associated with this language as well as the top-most scope instance and the default system exception handler.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddToGlobalScope
(Class<? extends Entity> clazz, Entities entities) Adds the 'entities' of the specified 'clazz' to the global scope.Removes all of the entities stored within the global scope.Clears the collection of parallel active entities (for all scopes).Returns a handle to the empty scope instance.findWithinGlobalScope
(Class<? extends Entity> clazz, Object key) Attempts to locate an object of the specified 'clazz' with the given 'key', within the global data.Returns the global environment object with the given 'key', or an empty non-null environment object on no match.Returns the next parallel active entity.protected static ActiveEntity
getNextParallelActiveEntity
(Map<Thread, List<ActiveEntity>> entry) Returns the next parallel active entity from any of the threads within the given 'entry' map.Returns the next parallel active entity.int
Returns a count of the number of parallel active entity instances associated with the given 'scope' which are currently running, pending completion.registerScope
(Scope scope) Stores the given scope entry.void
removeAllParallelActiveEntitiesForThread
(ActiveEntity activeEntity) Removes all of the active entities associated with the given 'thread'.void
Removes all data associated with all scopes.void
Unregisters the completed parallel ActiveEntities for the given 'scope'.boolean
scopeExists
(String scopeName) This method can be used to check if an existing Scope is associated with the given 'scopeName'.toString()
toString
(int indentLevel) This method returns a detailed description of the business entities and business functionality contained within this language, indented to the specified level.unregisterScope
(Scope scope) Unregisters the given 'scope', closing any CloseableResources associated with this scope and clearing all related scope data; returning the parent of this scope (which may be a non-null 'empty' instance).protected void
unregisterThisScope
(Scope scope) Unregisters the given 'scope' from this Language instance.void
If any ActiveEntity instances associated with the given 'scope' have previously been declared as parallel, this method will wait until all such ActiveEntities have completed, before returning.Returns the top-level default scope instance for this language.withGlobalEnvironmentObject
(Object object) Allows the given environment object to be added to the global environment.Allows the given environment object to be added to the global environment.Returns the set of global environment objects as a 'EnvironmentObjects' collection.withGlobalEnvironmentObjects
(Object... objects) Allows the given environment objects to be added to the global environment.withGlobalEnvironmentObjects
(EnvironmentObject... objects) Allows the given environment objects to be added to the global environment.Returns the set of objects within the global environment as a list of 'EnvironmentObject' objects.Returns a handle to the grammar instance associated with this Language.Returns the locale associated with this Language instance.withLocale
(Locale locale) Setter method allowing a locale to be defined for this Language instance.withParallelActiveEntityForScope
(ActiveEntity activeEntity) This method should be used to associate any ActiveEntity instances which are running in parallel with their corresponding Scope.Returns the scope associated with the given 'scopeName', or a non-null 'empty' scope instance on no match.
-
Constructor Details
-
Language
Constructor, creating a new language instance of the given 'languageName'.
Note that a top-level default scope instance will also be created along with the top-most default exception handler.- Parameters:
languageName
- the name of this language
-
Language
Constructor, creating a new language instance of the given 'languageName'.
Note that a top-level default scope instance will also be created along with the top-most default exception handler.
The type of scope instance created will be determined by the given 'scopeType'. However if 'scopeType' is null, the default scope type will be used.
The default scope type will then be set to 'scopeType', provided 'scopeType' is non-null.- Parameters:
languageName
- the name of this languagescopeType
- sets the default scope type (can be null)
-
-
Method Details
-
withLocale
-
withLocale
Returns the locale associated with this Language instance.
Note that the locale defaults to the system default.- Returns:
- the current locale
-
withGrammar
Returns a handle to the grammar instance associated with this Language.- Returns:
- a handle to the grammar instance
-
emptyScope
-
withDefaultScope
Returns the top-level default scope instance for this language.
This will be the first scope created.- Returns:
- the (first) top-most scope instance added, or null if no scope currently exists
-
withScope
-
registerScope
Stores the given scope entry.
This method will throw an EmptyOrNullArgumentException if 'scopeName' is null or an IllegalArgumentException if a Scope with this 'scopeName' already exists.
Note that the 'empty' scope name will never be registered.- Parameters:
scope
- holds the new scope instance to add- Returns:
- a handle to the 'scope' parameter
-
unregisterScope
Unregisters the given 'scope', closing any CloseableResources associated with this scope and clearing all related scope data; returning the parent of this scope (which may be a non-null 'empty' instance).- Parameters:
scope
- handle to the scope to unregister- Returns:
- a handle to the parent of this scope (which may be a non-null 'empty' instance)
-
scopeExists
This method can be used to check if an existing Scope is associated with the given 'scopeName'.
This method is intended to be used to prevent the creation of duplicate scope names.
See also the 'addScope()' method, which calls this method automatically.- Parameters:
scopeName
- the name of the scope to check (cannot be null or empty)- Returns:
- true if an existing scope is associated with the given 'key'; false otherwise
-
withParallelActiveEntityForScope
This method should be used to associate any ActiveEntity instances which are running in parallel with their corresponding Scope. This is necessary to ensure that no attempt is made to clear the Scope until all outstanding threads have completed.- Parameters:
activeEntity
- handle to the ActiveEntity which is running in parallel- Returns:
- the given 'activeEntity' parameter, unchanged (to allow chaining)
-
getNumberOfPendingParallelActiveEntitiesForScope
Returns a count of the number of parallel active entity instances associated with the given 'scope' which are currently running, pending completion. Returns zero if there are no such pending active entity instance associated with the given 'scope'.- Parameters:
scope
- handle to the scope instance potentially holding parallel ActiveEntity instances- Returns:
- a count of the number of active entity instances for the given 'scope'
-
getNextParallelActiveEntityForScope
Returns the next parallel active entity. This active entity will be found by checking all threads associated with the given 'scope'. Returns null if no parallel active entities exist.- Parameters:
scope
- handle to the scope containing the active entities- Returns:
- the next available parallel active entity (associated with the given 'scope') to wait for, or null if no such parallel active entities exist
-
getNextParallelActiveEntity
Returns the next parallel active entity. This active entity will be found by checking all scopes and all threads. Returns null if no parallel active entities exist.- Returns:
- the next available parallel active entity to wait for, or null if no such parallel active entities exist
-
waitForParallelActiveEntitiesForScope
If any ActiveEntity instances associated with the given 'scope' have previously been declared as parallel, this method will wait until all such ActiveEntities have completed, before returning.
This method will have no affect if there are no such parallel ActiveEntity instances associated with the given 'scope', or if all relevant threads have already completed.
Once all relevant threads have completed, all such parallel threads will be unregistered. Therefore calling this method more than once will have no affect, since all relevant threads will be completed and removed after the first invocation.- Parameters:
scope
- holds the scope to check for parallel active entities
-
removeAllParallelActiveEntitiesForThread
Removes all of the active entities associated with the given 'thread'.- Parameters:
activeEntity
- the parallel ActiveEntity to be removed (which identifies both the scope and thread)
-
removeParallelActiveEntitiesFromScope
Unregisters the completed parallel ActiveEntities for the given 'scope'.
This method is called automatically once the associated parallel active entities have completed.- Parameters:
scope
- handle to the scope containing the completed parallel active entity instances
-
clearParallelActiveEntities
Clears the collection of parallel active entities (for all scopes).- Returns:
- a handle to self to allow chaining
-
withGlobalEnvironmentObject
-
withGlobalEnvironmentObject
Allows the given environment object to be added to the global environment.- Parameters:
object
- handle to the environment object to be added to the global environment- Returns:
- a handle to self to allow chaining
-
withGlobalEnvironmentObjects
-
withGlobalEnvironmentObjects
Allows the given environment objects to be added to the global environment.- Parameters:
objects
- handle to the environment objects to be added to the global environment- Returns:
- a handle to self to allow chaining
-
getGlobalEnvironmentObject
Returns the global environment object with the given 'key', or an empty non-null environment object on no match.- Parameters:
key
- identifies the required global environment variable- Returns:
- a non-null environment object
-
withGlobalObjects
Returns the set of objects within the global environment as a list of 'EnvironmentObject' objects.
Note that this method is similar to the 'withGlobalEnvironmentObjects()' method, which just returns the same data but as an 'EnvironmentObjects' collection.- Returns:
- the global environment objects
-
withGlobalEnvironmentObjects
Returns the set of global environment objects as a 'EnvironmentObjects' collection.
Note that this method is similar to the 'withGlobalObjects()' method, which just returns the same data but as a list of 'EnvironmentObject' objects.- Returns:
- the global environment objects
-
addToGlobalScope
Adds the 'entities' of the specified 'clazz' to the global scope.
Note that this method is NOT thread-safe.
Note also that this method will have no affect if 'clazz' or 'entities' are null.- Parameters:
clazz
- specifies the type of the entities to be addedentities
- holds the entities to add- Returns:
- the input 'entities' parameter, unchanged, to allow chaining
-
findWithinGlobalScope
Attempts to locate an object of the specified 'clazz' with the given 'key', within the global data.- Parameters:
clazz
- specifies the type of data item requiredkey
- the key to search for- Returns:
- a handle to the object of the specified type and with the given 'name' on match; or a non-null empty instance on no-match
-
clearGlobalScopeEntities
Removes all of the entities stored within the global scope.- Returns:
- a handle to self to allow chaining
-
removeAllScopeData
public void removeAllScopeData()Removes all data associated with all scopes. -
toString
-
toString
This method returns a detailed description of the business entities and business functionality contained within this language, indented to the specified level. -
unregisterThisScope
Unregisters the given 'scope' from this Language instance.
Do not call this method directly. Rather, call the method 'Common.unregisterScope()' instead.
See also the 'unregisterScope()' method in the Common class, which actually invokes this method as well as removing the given scope from the list of known parallel scopes (if applicable).- Parameters:
scope
- handle to the scope to unregister
-
getNextParallelActiveEntity
Returns the next parallel active entity from any of the threads within the given 'entry' map.- Parameters:
entry
- holds the thread map containing the parallel active entities- Returns:
- the next available parallel active entity to wait for, or null if no such parallel active entities exist
-