Class DefaultAzkarraContext
- java.lang.Object
-
- io.streamthoughts.azkarra.runtime.context.DefaultAzkarraContext
-
- All Implemented Interfaces:
AzkarraContext
public class DefaultAzkarraContext extends Object implements AzkarraContext
The AzkarraContext.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ENV_NAME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> AzkarraContext
addComponent(ComponentFactory<T> factory)
Registers a components into this context.<T> AzkarraContext
addComponent(Class<T> cls)
Registers a components into this context.AzkarraContext
addComponent(String className)
Registers a components into this context.AzkarraContext
addConfiguration(Conf configuration)
Adds the specifiedConf
to the configuration of thisAzkarraContext
.AzkarraContext
addExecutionEnvironment(StreamsExecutionEnvironment env)
Adds theStreamsExecutionEnvironment
to this context.AzkarraContext
addListener(AzkarraContextListener listener)
Registers a new listener instance to this context.ApplicationId
addTopology(Class<? extends TopologyProvider> type, Executed executed)
Adds a topology to the default environment of this context.ApplicationId
addTopology(Class<? extends TopologyProvider> type, String envName, Executed executed)
Adds a topology to a specified environment.ApplicationId
addTopology(String type, Executed executed)
Adds a topology to the default environment of this context.ApplicationId
addTopology(String type, String environment, Executed executed)
Adds a topology to a specified environment.ApplicationId
addTopology(String type, String version, String environment, Executed executed)
Adds a topology to a specified environment.static AzkarraContext
create()
Static helper that can be used to creates a newAzkarraContext
instance using a defaultComponentRegistry
and a empty configuration.static AzkarraContext
create(ComponentClassReader reader)
Static helper that can be used to creates a newAzkarraContext
instance using the specifiedComponentRegistry
and a empty configuration.static AzkarraContext
create(ComponentRegistry registry)
Static helper that can be used to creates a newAzkarraContext
instance using the specifiedComponentRegistry
and a empty configuration.static AzkarraContext
create(Conf configuration)
Static helper that can be used to creates a newAzkarraContext
instance using a defaultComponentRegistry
and the specified configuration.StreamsExecutionEnvironment
defaultExecutionEnvironment()
Gets the defaultStreamsExecutionEnvironment
.List<StreamsExecutionEnvironment>
environments()
Gets allStreamsExecutionEnvironment
registered to this context.<T> Collection<T>
getAllComponentForType(Class<T> cls)
Get all component instances for the specified class.ComponentClassReader
getComponentClassReader()
Gets the internalComponentClassReader
.<T> T
getComponentForType(Class<T> cls)
Gets a component instance for the specified class.ComponentRegistry
getComponentRegistry()
Gets the internalComponentRegistry
.Conf
getConfiguration()
Returns the global context streamsConfig of thisAzkarraContext
instance.StreamsExecutionEnvironment
getEnvironmentForNameOrCreate(String envName)
Gets theStreamsExecutionEnvironment
for the specified name or create a new one.TopologyDescriptor
getTopology(String type)
Gets the topology for the specified class name or alias.AzkarraContext
setComponentClassReader(ComponentClassReader reader)
Sets the internal theComponentClassReader
which is used for registering components to this context.AzkarraContext
setComponentRegistry(ComponentRegistry registry)
Sets the internal theComponentRegistry
which is used for registering components to this context.AzkarraContext
setConfiguration(Conf configuration)
Sets the default configuration to be used for thisAzkarraContext
.AzkarraContext
setRegisterShutdownHook(boolean registerShutdownHook)
Sets if the createdAzkarraContext
should have a shutdown hook registered.void
setState(State started)
void
start()
Starts thisAzkarraContext
instance.void
stop()
Stops thisAzkarraContext
instance.void
stop(boolean cleanUp)
Stops thisAzkarraContext
instance.Set<TopologyDescriptor>
topologyProviders()
Gets all topologies registered into thisAzkarraContext
.
-
-
-
Field Detail
-
DEFAULT_ENV_NAME
public static final String DEFAULT_ENV_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static AzkarraContext create()
Static helper that can be used to creates a newAzkarraContext
instance using a defaultComponentRegistry
and a empty configuration.- Returns:
- a new
AzkarraContext
instance.
-
create
public static AzkarraContext create(ComponentRegistry registry)
Static helper that can be used to creates a newAzkarraContext
instance using the specifiedComponentRegistry
and a empty configuration.- Returns:
- a new
AzkarraContext
instance.
-
create
public static AzkarraContext create(ComponentClassReader reader)
Static helper that can be used to creates a newAzkarraContext
instance using the specifiedComponentRegistry
and a empty configuration.- Returns:
- a new
AzkarraContext
instance.
-
create
public static AzkarraContext create(Conf configuration)
Static helper that can be used to creates a newAzkarraContext
instance using a defaultComponentRegistry
and the specified configuration.- Returns:
- a new
AzkarraContext
instance.
-
setComponentRegistry
public AzkarraContext setComponentRegistry(ComponentRegistry registry)
Sets the internal theComponentRegistry
which is used for registering components to this context.- Specified by:
setComponentRegistry
in interfaceAzkarraContext
- Parameters:
registry
- theComponentRegistry
instance to be used.- Returns:
- this
AzkarraContext
instance.
-
getComponentRegistry
public ComponentRegistry getComponentRegistry()
Gets the internalComponentRegistry
.- Specified by:
getComponentRegistry
in interfaceAzkarraContext
- Returns:
- the
ComponentRegistry
instance to be used.
-
getComponentClassReader
public ComponentClassReader getComponentClassReader()
Gets the internalComponentClassReader
.- Specified by:
getComponentClassReader
in interfaceAzkarraContext
- Returns:
- the
ComponentClassReader
instance to be used.
-
setComponentClassReader
public AzkarraContext setComponentClassReader(ComponentClassReader reader)
Sets the internal theComponentClassReader
which is used for registering components to this context.- Specified by:
setComponentClassReader
in interfaceAzkarraContext
- Parameters:
reader
- theComponentClassReader
instance to be used.- Returns:
- this
AzkarraContext
instance.
-
addListener
public AzkarraContext addListener(AzkarraContextListener listener)
Registers a new listener instance to this context.- Specified by:
addListener
in interfaceAzkarraContext
- Parameters:
listener
- theAzkarraContextListener
instance to register.- Returns:
- this
AzkarraContext
instance.
-
setRegisterShutdownHook
public AzkarraContext setRegisterShutdownHook(boolean registerShutdownHook)
Sets if the createdAzkarraContext
should have a shutdown hook registered. Defaults totrue
to ensure that JVM shutdowns are handled gracefully.- Specified by:
setRegisterShutdownHook
in interfaceAzkarraContext
- Parameters:
registerShutdownHook
- if the shutdown hook should be registered- Returns:
- this
AzkarraContext
instance.
-
getConfiguration
public Conf getConfiguration()
Returns the global context streamsConfig of thisAzkarraContext
instance.- Specified by:
getConfiguration
in interfaceAzkarraContext
- Returns:
- a
Conf
instance.
-
setConfiguration
public AzkarraContext setConfiguration(Conf configuration)
Sets the default configuration to be used for thisAzkarraContext
.- Specified by:
setConfiguration
in interfaceAzkarraContext
- Parameters:
configuration
- theConf
instance.- Returns:
- this
AzkarraContext
instance.
-
addConfiguration
public AzkarraContext addConfiguration(Conf configuration)
Adds the specifiedConf
to the configuration of thisAzkarraContext
.- Specified by:
addConfiguration
in interfaceAzkarraContext
- Parameters:
configuration
- theConf
instance to be used.- Returns:
- this
AzkarraContext
instance.
-
addExecutionEnvironment
public AzkarraContext addExecutionEnvironment(StreamsExecutionEnvironment env) throws AlreadyExistsException
Adds theStreamsExecutionEnvironment
to this context.- Specified by:
addExecutionEnvironment
in interfaceAzkarraContext
- Parameters:
env
- theStreamsExecutionEnvironment
instance.- Returns:
- this
AzkarraContext
instance. - Throws:
AlreadyExistsException
- if aStreamsExecutionEnvironment
is already registered for the given name.
-
addTopology
public ApplicationId addTopology(String type, Executed executed)
Adds a topology to the default environment of this context.- Specified by:
addTopology
in interfaceAzkarraContext
- Parameters:
type
- the fully qualified class name or alias of the targetTopologyProvider
.executed
- theExecuted
instance.- Returns:
- the
ApplicationId
instance if the environment is already started, otherwisenull
.
-
addTopology
public ApplicationId addTopology(Class<? extends TopologyProvider> type, Executed executed)
Adds a topology to the default environment of this context.- Specified by:
addTopology
in interfaceAzkarraContext
- Parameters:
type
- theTopologyProvider
class to add.executed
- theExecuted
instance.- Returns:
- the
ApplicationId
instance if the environment is already started, otherwisenull
.
-
addTopology
public ApplicationId addTopology(Class<? extends TopologyProvider> type, String envName, Executed executed)
Adds a topology to a specified environment.- Specified by:
addTopology
in interfaceAzkarraContext
- Parameters:
type
- theTopologyProvider
class to add.envName
- the environment name.executed
- theExecuted
instance.- Returns:
- the
ApplicationId
instance if the environment is already started, otherwisenull
..
-
addTopology
public ApplicationId addTopology(String type, String environment, Executed executed)
Adds a topology to a specified environment.- Specified by:
addTopology
in interfaceAzkarraContext
- Parameters:
type
- the fully qualified class name or alias of the targetTopologyProvider
.environment
- the environment name.executed
- theExecuted
instance.- Returns:
- the
ApplicationId
instance if the environment is already started, otherwisenull
.
-
addTopology
public ApplicationId addTopology(String type, String version, String environment, Executed executed)
Adds a topology to a specified environment.- Specified by:
addTopology
in interfaceAzkarraContext
- Parameters:
type
- the fully qualified class name or alias of the targetTopologyProvider
.version
- the topology version.environment
- the environment name.executed
- theExecuted
instance.- Returns:
- the
ApplicationId
instance if the environment is already started, otherwisenull
.
-
setState
public void setState(State started)
-
topologyProviders
public Set<TopologyDescriptor> topologyProviders()
Gets all topologies registered into thisAzkarraContext
. Note, if provider scan is enable then topologies will be scan when thisAzkarraContext
will be started.- Specified by:
topologyProviders
in interfaceAzkarraContext
- Returns:
- a set of
TopologyDescriptor
.
-
environments
public List<StreamsExecutionEnvironment> environments()
Gets allStreamsExecutionEnvironment
registered to this context.- Specified by:
environments
in interfaceAzkarraContext
- Returns:
- a list of
StreamsExecutionEnvironment
instance.
-
getEnvironmentForNameOrCreate
public StreamsExecutionEnvironment getEnvironmentForNameOrCreate(String envName)
Gets theStreamsExecutionEnvironment
for the specified name or create a new one.- Specified by:
getEnvironmentForNameOrCreate
in interfaceAzkarraContext
- Parameters:
envName
- the environment name.- Returns:
- a
StreamsExecutionEnvironment
instance with the specified name.
-
defaultExecutionEnvironment
public StreamsExecutionEnvironment defaultExecutionEnvironment()
Gets the defaultStreamsExecutionEnvironment
.- Specified by:
defaultExecutionEnvironment
in interfaceAzkarraContext
- Returns:
- a
StreamsExecutionEnvironment
instance.
-
addComponent
public <T> AzkarraContext addComponent(Class<T> cls)
Registers a components into this context.- Specified by:
addComponent
in interfaceAzkarraContext
- Parameters:
cls
- the component class.- Returns:
- this
AzkarraContext
instance.
-
addComponent
public <T> AzkarraContext addComponent(ComponentFactory<T> factory)
Registers a components into this context.- Specified by:
addComponent
in interfaceAzkarraContext
- Parameters:
factory
- theComponentFactory
instance.- Returns:
- this
AzkarraContext
instance.
-
addComponent
public AzkarraContext addComponent(String className)
Registers a components into this context.- Specified by:
addComponent
in interfaceAzkarraContext
- Parameters:
className
- the component class name.- Returns:
- this
AzkarraContext
instance.
-
getComponentForType
public <T> T getComponentForType(Class<T> cls)
Gets a component instance for the specified class.- Specified by:
getComponentForType
in interfaceAzkarraContext
- Type Parameters:
T
- the component type.- Parameters:
cls
- the component class.- Returns:
- the component instance of type
AzkarraContext
.
-
getAllComponentForType
public <T> Collection<T> getAllComponentForType(Class<T> cls)
Get all component instances for the specified class.- Specified by:
getAllComponentForType
in interfaceAzkarraContext
- Type Parameters:
T
- the component type.- Parameters:
cls
- the component class.- Returns:
- the component instance of type
AzkarraContext
.
-
getTopology
public TopologyDescriptor getTopology(String type)
Gets the topology for the specified class name or alias.- Specified by:
getTopology
in interfaceAzkarraContext
- Parameters:
type
- the topology type.- Returns:
- the
TopologyDescriptor
.
-
start
public void start()
Starts thisAzkarraContext
instance.- Specified by:
start
in interfaceAzkarraContext
-
stop
public void stop(boolean cleanUp)
Stops thisAzkarraContext
instance.- Specified by:
stop
in interfaceAzkarraContext
- Parameters:
cleanUp
- if local states of eachKafkaStreams
instance must be cleanup.- See Also:
.
-
stop
public void stop()
Stops thisAzkarraContext
instance.- Specified by:
stop
in interfaceAzkarraContext
-
-