if (factoryName == null)
{
factoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
}
StateModelFactory stateModelFactory =
getStateModelFactory(stateModelName, factoryName);
if (stateModelFactory == null)
{
logger.warn("Cannot find stateModelFactory for model:" + stateModelName
+ " using factoryName:" + factoryName + " for resourceGroup:" + resourceName);
return null;
}
// check if the state model definition exists and cache it
if (!_stateModelDefs.containsKey(stateModelName))
{
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
StateModelDefinition stateModelDef =
accessor.getProperty(keyBuilder.stateModelDef(stateModelName));
if (stateModelDef == null)
{
throw new HelixException("stateModelDef for " + stateModelName
+ " does NOT exists");
}
_stateModelDefs.put(stateModelName, stateModelDef);
}
// create currentStateDelta for this partition
String initState = _stateModelDefs.get(message.getStateModelDef()).getInitialState();
StateModel stateModel = stateModelFactory.getStateModel(partitionKey);
if (stateModel == null)
{
stateModelFactory.createAndAddStateModel(partitionKey);
stateModel = stateModelFactory.getStateModel(partitionKey);
stateModel.updateState(initState);
}
CurrentState currentStateDelta = new CurrentState(resourceName);
currentStateDelta.setSessionId(sessionId);