public abstract class BoundedContext extends java.lang.Object implements Closeable, io.spine.logging.Logging
Logically, a Bounded Context represents a sub-system built to be described with the same Ubiquitous Language. Any term within a single bounded context has a single meaning and may or may not map to another term in the language of another Bounded Context.
The Ubiquitous Language of a Bounded Context is represented by such concepts as the entity
state, event, and command types, entity types, and others. An entity and its adjacent types
belong to the Bounded Context which the entity Repository
is
registered in.
Structurally, a Bounded Context brings together all the infrastructure required for the components of a model to cooperate.
An instance of BoundedContext
acts as a major point of configuration for all
the model elements which belong to it.
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the
BoundedContext performing all necessary clean-ups. |
CommandBus |
commandBus()
Obtains instance of
CommandBus of this BoundedContext . |
EventBus |
eventBus()
Obtains instance of
EventBus of this BoundedContext . |
boolean |
hasEntitiesOfType(java.lang.Class<? extends Entity<?,?>> entityClass)
Verifies if this Bounded Context contains entities of the passed class.
|
boolean |
hasEntitiesWithState(java.lang.Class<? extends io.spine.base.EntityState> stateClass)
Verifies if this Bounded Context has entities with the state of the passed class.
|
ImportBus |
importBus()
Obtains instance of
ImportBus of this BoundedContext . |
protected void |
init()
Performs post-creation initialization of the instance.
|
boolean |
isMultitenant()
Returns
true if the Bounded Context is designed to serve more than one tenant of
the application, false otherwise. |
boolean |
isOpen()
Tells if the object is still open.
|
static BoundedContextBuilder |
multitenant(java.lang.String name)
Creates a new builder for a multitenant
BoundedContext . |
io.spine.core.BoundedContextName |
name()
Obtains an ID of the Bounded Context.
|
protected void |
register(Repository<?,?> repository)
Adds the passed repository to the context.
|
protected void |
registerCommandDispatcher(CommandDispatcher dispatcher)
Registers the passed command dispatcher with the
CommandBus . |
protected void |
registerEventDispatcher(EventDispatcher dispatcher)
Registering the passed event dispatcher with the buses of this context.
|
static BoundedContextBuilder |
singleTenant(java.lang.String name)
Creates a new builder for a single tenant
BoundedContext . |
ContextSpec |
spec()
Obtains specification of this context.
|
Stand |
stand()
Obtains instance of
Stand of this BoundedContext . |
java.util.Set<io.spine.type.TypeName> |
stateTypes()
Obtains the set of all entity type names.
|
java.util.Set<io.spine.type.TypeName> |
stateTypes(io.spine.option.EntityOption.Visibility visibility)
Obtains a set of entity type names by their visibility.
|
java.lang.String |
toString()
Returns the name of this Bounded Context.
|
protected final void init()
This method must be called shortly after the constructor so that the instance can perform dependency injections steps that cannot be performed in the constructor.
public static BoundedContextBuilder singleTenant(java.lang.String name)
BoundedContext
.name
- the name of the built contextpublic static BoundedContextBuilder multitenant(java.lang.String name)
BoundedContext
.name
- the name of the built contextprotected final void register(Repository<?,?> repository)
protected void registerCommandDispatcher(CommandDispatcher dispatcher)
CommandBus
.protected void registerEventDispatcher(EventDispatcher dispatcher)
If the passed instance dispatches domestic events, registers it with the EventBus
.
If the passed instance dispatches external events, registers it with
the IntegrationBroker
.
public java.util.Set<io.spine.type.TypeName> stateTypes(io.spine.option.EntityOption.Visibility visibility)
public java.util.Set<io.spine.type.TypeName> stateTypes()
public boolean hasEntitiesOfType(java.lang.Class<? extends Entity<?,?>> entityClass)
This method does not take into account visibility of entity states.
public boolean hasEntitiesWithState(java.lang.Class<? extends io.spine.base.EntityState> stateClass)
This method does not take into account visibility of entity states.
public CommandBus commandBus()
CommandBus
of this BoundedContext
.public io.spine.core.BoundedContextName name()
The ID allows to identify a Bounded Context if a multi-context application.
If the ID was not defined during the building process, the Bounded Context gets
BoundedContextNames.assumingTests()
name.
BoundedContext
public ContextSpec spec()
public boolean isMultitenant()
true
if the Bounded Context is designed to serve more than one tenant of
the application, false
otherwise.public void close() throws java.lang.Exception
BoundedContext
performing all necessary clean-ups.
This method performs the following:
StorageFactory
.
CommandBus
.
EventBus
.
IntegrationBroker
.
EventStore
.
Stand
.
ImportBus
.
TracerFactory
if it is present.
close
in interface java.lang.AutoCloseable
java.lang.Exception
- caused by closing one of the componentspublic boolean isOpen()
Closeable
Implementations must return false
after AutoCloseable.close()
is invoked.
public java.lang.String toString()
toString
in class java.lang.Object