throw new HelixException("Expect state-transition message type, but was "
+ message.getMsgType() + ", msgId: " + message.getMessageId());
}
PartitionId partitionKey = message.getPartitionId();
StateModelDefId stateModelId = message.getStateModelDefId();
ResourceId resourceId = message.getResourceId();
SessionId sessionId = message.getTypedTgtSessionId();
int bucketSize = message.getBucketSize();
if (stateModelId == null) {
LOG.error("Fail to create msg-handler because message does not contain stateModelDef. msgId: "
+ message.getId());
return null;
}
String factoryName = message.getStateModelFactoryName();
if (factoryName == null) {
factoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
}
StateModelFactory<? extends StateModel> stateModelFactory =
getStateModelFactory(stateModelId.stringify(), factoryName);
if (stateModelFactory == null) {
LOG.warn("Fail to create msg-handler because cannot find stateModelFactory for model: "
+ stateModelId + " using factoryName: " + factoryName + " for resource: " + resourceId);
return null;
}
// check if the state model definition exists and cache it
if (!_stateModelDefs.containsKey(stateModelId.stringify())) {
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
StateModelDefinition stateModelDef =
accessor.getProperty(keyBuilder.stateModelDef(stateModelId.stringify()));
if (stateModelDef == null) {
throw new HelixException("fail to create msg-handler because stateModelDef for "
+ stateModelId + " does NOT exist");
}
_stateModelDefs.put(stateModelId.stringify(), stateModelDef);
}
if (message.getBatchMessageMode() == false) {
// create currentStateDelta for this partition
String initState = _stateModelDefs.get(message.getStateModelDef()).getInitialState();
StateModel stateModel = stateModelFactory.getStateModel(partitionKey.stringify());
if (stateModel == null) {
stateModel = stateModelFactory.createAndAddStateModel(partitionKey.stringify());
stateModel.updateState(initState);
}
// TODO: move currentStateDelta to StateTransitionMsgHandler
CurrentState currentStateDelta = new CurrentState(resourceId.stringify());
currentStateDelta.setSessionId(sessionId);
currentStateDelta.setStateModelDefRef(stateModelId.stringify());
currentStateDelta.setStateModelFactoryName(factoryName);
currentStateDelta.setBucketSize(bucketSize);
currentStateDelta.setState(
partitionKey,