[New] Implemented separate DataStoreMode for each StrolchRealm
added new component state mode SETUP which is before initialize which is where configurations can be loaded, but no other components may be used
This commit is contained in:
parent
14de9b29df
commit
d6ebf330c7
|
@ -19,7 +19,7 @@ import java.text.MessageFormat;
|
||||||
|
|
||||||
public enum ComponentState {
|
public enum ComponentState {
|
||||||
|
|
||||||
UNDEFINED, INITIALIZED, STARTED, STOPPED, DESTROYED;
|
UNDEFINED, SETUP, INITIALIZED, STARTED, STOPPED, DESTROYED;
|
||||||
|
|
||||||
public ComponentState validateStateChange(ComponentState newState) {
|
public ComponentState validateStateChange(ComponentState newState) {
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ public enum ComponentState {
|
||||||
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case UNDEFINED:
|
case UNDEFINED:
|
||||||
|
if (newState != ComponentState.SETUP && newState != STOPPED)
|
||||||
|
throw getIllegalStateEx(newState);
|
||||||
|
break;
|
||||||
|
case SETUP:
|
||||||
if (newState != ComponentState.INITIALIZED && newState != STOPPED)
|
if (newState != ComponentState.INITIALIZED && newState != STOPPED)
|
||||||
throw getIllegalStateEx(newState);
|
throw getIllegalStateEx(newState);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -90,6 +90,8 @@ public class StrolchAgent {
|
||||||
this.strolchConfiguration = ConfigurationParser.parseConfiguration(path);
|
this.strolchConfiguration = ConfigurationParser.parseConfiguration(path);
|
||||||
|
|
||||||
ComponentContainerImpl container = new ComponentContainerImpl(this);
|
ComponentContainerImpl container = new ComponentContainerImpl(this);
|
||||||
|
container.setup(strolchConfiguration);
|
||||||
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
RuntimeConfiguration runtimeConfiguration = this.strolchConfiguration.getRuntimeConfiguration();
|
RuntimeConfiguration runtimeConfiguration = this.strolchConfiguration.getRuntimeConfiguration();
|
||||||
|
|
|
@ -69,6 +69,10 @@ public class StrolchComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setup(ComponentConfiguration configuration) {
|
||||||
|
this.state = this.state.validateStateChange(ComponentState.SETUP);
|
||||||
|
}
|
||||||
|
|
||||||
public void initialize(ComponentConfiguration configuration) {
|
public void initialize(ComponentConfiguration configuration) {
|
||||||
this.state = this.state.validateStateChange(ComponentState.INITIALIZED);
|
this.state = this.state.validateStateChange(ComponentState.INITIALIZED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
return getComponent(RealmHandler.class).getRealm(realm);
|
return getComponent(RealmHandler.class).getRealm(realm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeComponent(Map<Class<?>, StrolchComponent> componentMap,
|
private void setupComponent(Map<Class<?>, StrolchComponent> componentMap,
|
||||||
Map<String, ComponentController> controllerMap, ComponentConfiguration componentConfiguration) {
|
Map<String, ComponentController> controllerMap, ComponentConfiguration componentConfiguration) {
|
||||||
|
|
||||||
String componentName = componentConfiguration.getName();
|
String componentName = componentConfiguration.getName();
|
||||||
|
@ -120,6 +120,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
Constructor<StrolchComponent> constructor = strolchComponentClass.getConstructor(ComponentContainer.class,
|
Constructor<StrolchComponent> constructor = strolchComponentClass.getConstructor(ComponentContainer.class,
|
||||||
String.class);
|
String.class);
|
||||||
StrolchComponent strolchComponent = constructor.newInstance(this, componentName);
|
StrolchComponent strolchComponent = constructor.newInstance(this, componentName);
|
||||||
|
strolchComponent.setup(componentConfiguration);
|
||||||
|
|
||||||
componentMap.put(apiClass, strolchComponent);
|
componentMap.put(apiClass, strolchComponent);
|
||||||
controllerMap.put(componentName, new ComponentController(strolchComponent));
|
controllerMap.put(componentName, new ComponentController(strolchComponent));
|
||||||
|
@ -226,7 +227,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
destroy(dependencies);
|
destroy(dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(StrolchConfiguration strolchConfiguration) {
|
public void setup(StrolchConfiguration strolchConfiguration) {
|
||||||
|
|
||||||
// first set up the container itself
|
// first set up the container itself
|
||||||
this.strolchConfiguration = strolchConfiguration;
|
this.strolchConfiguration = strolchConfiguration;
|
||||||
|
@ -236,7 +237,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
for (String componentName : componentNames) {
|
for (String componentName : componentNames) {
|
||||||
ComponentConfiguration componentConfiguration = strolchConfiguration
|
ComponentConfiguration componentConfiguration = strolchConfiguration
|
||||||
.getComponentConfiguration(componentName);
|
.getComponentConfiguration(componentName);
|
||||||
initializeComponent(componentMap, controllerMap, componentConfiguration);
|
setupComponent(componentMap, controllerMap, componentConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// then analyze dependencies
|
// then analyze dependencies
|
||||||
|
@ -248,8 +249,12 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
this.controllerMap = controllerMap;
|
this.controllerMap = controllerMap;
|
||||||
this.strolchConfiguration = strolchConfiguration;
|
this.strolchConfiguration = strolchConfiguration;
|
||||||
|
|
||||||
|
this.state = this.state.validateStateChange(ComponentState.SETUP);
|
||||||
String msg = "Strolch Container setup with {0} components."; //$NON-NLS-1$
|
String msg = "Strolch Container setup with {0} components."; //$NON-NLS-1$
|
||||||
logger.info(MessageFormat.format(msg, this.componentMap.size()));
|
logger.info(MessageFormat.format(msg, this.componentMap.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(StrolchConfiguration strolchConfiguration) {
|
||||||
|
|
||||||
// now we can initialize the components
|
// now we can initialize the components
|
||||||
logger.info("Initializing strolch components..."); //$NON-NLS-1$
|
logger.info("Initializing strolch components..."); //$NON-NLS-1$
|
||||||
|
@ -258,7 +263,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
initialize(rootUpstreamComponents);
|
initialize(rootUpstreamComponents);
|
||||||
this.state = this.state.validateStateChange(ComponentState.INITIALIZED);
|
this.state = this.state.validateStateChange(ComponentState.INITIALIZED);
|
||||||
|
|
||||||
msg = "All {0} Strolch Components have been initialized."; //$NON-NLS-1$
|
String msg = "All {0} Strolch Components have been initialized."; //$NON-NLS-1$
|
||||||
logger.info(MessageFormat.format(msg, this.controllerMap.size()));
|
logger.info(MessageFormat.format(msg, this.controllerMap.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class DefaultRealmHandler extends StrolchComponent implements RealmHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ComponentConfiguration configuration) {
|
public void setup(ComponentConfiguration configuration) {
|
||||||
|
|
||||||
this.realms = new HashMap<>();
|
this.realms = new HashMap<>();
|
||||||
String[] realms = configuration.getStringArray(PROP_REALMS, StrolchConstants.DEFAULT_REALM);
|
String[] realms = configuration.getStringArray(PROP_REALMS, StrolchConstants.DEFAULT_REALM);
|
||||||
|
@ -81,6 +81,11 @@ public class DefaultRealmHandler extends StrolchComponent implements RealmHandle
|
||||||
StrolchRealm realm = dataStoreMode.createRealm(realmName);
|
StrolchRealm realm = dataStoreMode.createRealm(realmName);
|
||||||
this.realms.put(realmName, realm);
|
this.realms.put(realmName, realm);
|
||||||
}
|
}
|
||||||
|
super.setup(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(ComponentConfiguration configuration) {
|
||||||
|
|
||||||
for (String realmName : this.realms.keySet()) {
|
for (String realmName : this.realms.keySet()) {
|
||||||
StrolchRealm realm = this.realms.get(realmName);
|
StrolchRealm realm = this.realms.get(realmName);
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class InMemoryTransaction extends AbstractTransaction {
|
||||||
public void autoCloseableCommit() {
|
public void autoCloseableCommit() {
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.info("Committing TX..."); //$NON-NLS-1$
|
logger.info("Committing TX for realm " + getRealmName() + "..."); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
|
@ -86,13 +86,16 @@ public class InMemoryTransaction extends AbstractTransaction {
|
||||||
long txDuration = end - this.startTime;
|
long txDuration = end - this.startTime;
|
||||||
long closeDuration = end - start;
|
long closeDuration = end - start;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("TX has failed after "); //$NON-NLS-1$
|
sb.append("TX");
|
||||||
|
sb.append(getRealmName());
|
||||||
|
sb.append(" has failed after "); //$NON-NLS-1$
|
||||||
sb.append(StringHelper.formatNanoDuration(txDuration));
|
sb.append(StringHelper.formatNanoDuration(txDuration));
|
||||||
sb.append(" with close operation taking "); //$NON-NLS-1$
|
sb.append(" with close operation taking "); //$NON-NLS-1$
|
||||||
sb.append(StringHelper.formatNanoDuration(closeDuration));
|
sb.append(StringHelper.formatNanoDuration(closeDuration));
|
||||||
logger.info(sb.toString());
|
logger.info(sb.toString());
|
||||||
|
|
||||||
throw new StrolchPersistenceException("Strolch Transaction failed due to " + e.getMessage(), e); //$NON-NLS-1$
|
throw new StrolchPersistenceException(
|
||||||
|
"Strolch Transaction for realm " + getRealmName() + " failed due to " + e.getMessage(), e); //$NON-NLS-1$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +109,9 @@ public class InMemoryTransaction extends AbstractTransaction {
|
||||||
this.txResult.setRealm(getRealm().getRealm());
|
this.txResult.setRealm(getRealm().getRealm());
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("TX was completed after "); //$NON-NLS-1$
|
sb.append("TX for realm ");
|
||||||
|
sb.append(getRealmName());
|
||||||
|
sb.append(" was completed after "); //$NON-NLS-1$
|
||||||
sb.append(StringHelper.formatNanoDuration(txDuration));
|
sb.append(StringHelper.formatNanoDuration(txDuration));
|
||||||
sb.append(" with close operation taking "); //$NON-NLS-1$
|
sb.append(" with close operation taking "); //$NON-NLS-1$
|
||||||
sb.append(StringHelper.formatNanoDuration(closeDuration));
|
sb.append(StringHelper.formatNanoDuration(closeDuration));
|
||||||
|
|
Loading…
Reference in New Issue