* {@inheritDoc}
*/
@Override
public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor) {
List<ModuleDescriptor> streamModules = stream.getModuleDescriptors();
RuntimeModuleDeploymentProperties properties = super.propertiesForDescriptor(moduleDescriptor);
int moduleSequence = properties.getSequence();
int moduleIndex = moduleDescriptor.getIndex();
if (moduleIndex > 0) {
ModuleDescriptor previous = streamModules.get(moduleIndex - 1);
ModuleDeploymentProperties previousProperties = deploymentPropertiesProvider.propertiesForDescriptor(previous);
if (hasPartitionKeyProperty(previousProperties)) {
properties.put("consumer.partitionIndex", String.valueOf(moduleSequence - 1));
}
}
if (hasPartitionKeyProperty(properties)) {
try {
ModuleDeploymentProperties nextProperties =
deploymentPropertiesProvider.propertiesForDescriptor(streamModules.get(moduleIndex + 1));
String count = nextProperties.get("count");
validateCountProperty(count, moduleDescriptor);
properties.put("producer.partitionCount", count);
}
catch (IndexOutOfBoundsException e) {
logger.warn("Module '{}' is a sink module which contains a property " +
"of '{}' used for data partitioning; this feature is only " +
"supported for modules that produce data", moduleDescriptor,
"producer.partitionKeyExpression");
}
}
else if (streamModules.size() > moduleIndex + 1) {
ModuleDeploymentProperties nextProperties = deploymentPropertiesProvider.propertiesForDescriptor(streamModules.get(moduleIndex + 1));
String count = nextProperties.get("count");
properties.put("producer." + BusProperties.NEXT_MODULE_COUNT, count);
/*
* A direct binding is allowed if all of the following are true:
* 1. the user did not explicitly disallow direct binding
* 2. this module is not a partitioning producer
* 3. this module is not the last one in a stream
* 4. both this module and the next module have a count of 0
* 5. both this module and the next module have the same criteria (both can be null)
*/
String directBindingKey = "producer." + BusProperties.DIRECT_BINDING_ALLOWED;
String directBindingValue = properties.get(directBindingKey);
if (directBindingValue != null && !"false".equalsIgnoreCase(properties.get(directBindingKey))) {
logger.warn(
"Only 'false' is allowed as an explicit value for the {} property, but the value was: '{}'",
directBindingKey, directBindingValue);
}
if (!"false".equalsIgnoreCase(properties.get(directBindingKey))) {
if (properties.getCount() == 0 && nextProperties.getCount() == 0) {
String criteria = properties.getCriteria();
if ((criteria == null && nextProperties.getCriteria() == null)
|| (criteria != null && criteria.equals(nextProperties.getCriteria()))) {
properties.put(directBindingKey, Boolean.toString(true));
}
}
}
}
return properties;