Class DefaultAzkarraContext
- java.lang.Object
-
- io.streamthoughts.azkarra.runtime.context.DefaultAzkarraContext
-
- All Implemented Interfaces:
AzkarraContext
,ComponentRegistry
,ConfigurableComponentFactory
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 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(ComponentFactory factory)
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.ComponentFactory
getComponentFactory()
Gets the internalComponentFactory
.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.<T> void
registerComponent(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.<T> void
registerComponent(String componentName, Class<T> componentClass, Supplier<T> supplier, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.<T> void
registerSingleton(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers a singleton no-arg constructor component supplier for the specified type.<T> void
registerSingleton(String componentName, Class<T> componentClass, Supplier<T> singleton, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.<T> void
registerSingleton(T singleton)
Register the specified shared instance.AzkarraContext
setComponentFactory(ComponentFactory componentFactory)
Sets the internal theComponentFactory
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
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.streamthoughts.azkarra.api.components.ComponentRegistry
registerComponent, registerComponent, registerSingleton, registerSingleton
-
Methods inherited from interface io.streamthoughts.azkarra.api.components.ConfigurableComponentFactory
getAllComponents, getAllComponents, getAllComponents, getAllComponents, getComponent, getComponent, getComponent, getComponent
-
-
-
-
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(ComponentFactory factory)
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.
-
setComponentFactory
public AzkarraContext setComponentFactory(ComponentFactory componentFactory)
Sets the internal theComponentFactory
which is used for registering components to this context.- Specified by:
setComponentFactory
in interfaceAzkarraContext
- Parameters:
componentFactory
- theComponentFactory
instance to be used.- Returns:
- this
AzkarraContext
instance.
-
getComponentFactory
public ComponentFactory getComponentFactory()
Gets the internalComponentFactory
.- Specified by:
getComponentFactory
in interfaceAzkarraContext
- Specified by:
getComponentFactory
in interfaceConfigurableComponentFactory
- Returns:
- the
ComponentFactory
instance to be used.
-
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
- Specified by:
getConfiguration
in interfaceConfigurableComponentFactory
- 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.
-
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
-
registerComponent
public <T> void registerComponent(String componentName, Class<T> componentClass, Supplier<T> supplier, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.- Specified by:
registerComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.supplier
- the supplier of the component.modifiers
- the component descriptor modifiers.
-
registerComponent
public <T> void registerComponent(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name.- Specified by:
registerComponent
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.
-
registerSingleton
public <T> void registerSingleton(String componentName, Class<T> componentClass, Supplier<T> singleton, ComponentDescriptorModifier... modifiers)
Registers the component supplier for the specified type and name. The given supplier will be used for creating a shared instance of typeComponentRegistry
.- Specified by:
registerSingleton
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.singleton
- the supplier of the component.
-
registerSingleton
public <T> void registerSingleton(String componentName, Class<T> componentClass, ComponentDescriptorModifier... modifiers)
Registers a singleton no-arg constructor component supplier for the specified type.- Specified by:
registerSingleton
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
componentName
- the name of the component.componentClass
- the class-type of the component.
-
registerSingleton
public <T> void registerSingleton(T singleton)
Register the specified shared instance.- Specified by:
registerSingleton
in interfaceComponentRegistry
- Type Parameters:
T
- the component-type.- Parameters:
singleton
- the singleton component instance.
-
-