+ 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;
}
StateTransitionHandlerFactory<? extends TransitionHandler> stateModelFactory =
getStateModelFactory(stateModelId, 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)) {
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, stateModelDef);
}
if (message.getBatchMessageMode() == false) {
// create currentStateDelta for this partition
String initState = _stateModelDefs.get(message.getStateModelDefId()).getInitialState();
TransitionHandler stateModel = stateModelFactory.getTransitionHandler(partitionKey);
if (stateModel == null) {
stateModel = stateModelFactory.createAndAddSTransitionHandler(partitionKey);
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);