use of org.apache.storm.flux.model.PropertyDef in project open-kilda by telstra.
the class AbstractTopology method declareSpout.
protected SpoutDeclarer declareSpout(TopologyBuilder builder, IRichSpout spout, String spoutId) {
Integer spoutParallelism = null;
Integer spoutNumTasks = null;
Integer spoutMaxSpoutPending = null;
if (topologyDef != null) {
SpoutDef spoutDef = topologyDef.getSpoutDef(spoutId);
if (spoutDef != null) {
spoutParallelism = spoutDef.getParallelism();
if (spoutDef.getNumTasks() > 0) {
spoutNumTasks = spoutDef.getNumTasks();
}
if (spoutDef.getProperties() != null) {
for (PropertyDef propertyDef : spoutDef.getProperties()) {
if (MAX_SPOUT_PENDING_SPOUT_DEF_KEY.equals(propertyDef.getName())) {
spoutMaxSpoutPending = (Integer) propertyDef.getValue();
break;
}
}
}
}
}
if (spoutParallelism == null) {
if (topologyDef != null && topologyDef.getConfig() != null) {
spoutParallelism = (Integer) topologyDef.getConfig().get(SPOUT_PARALLELISM_TOPOLOGY_DEF_KEY);
}
if (spoutParallelism == null) {
spoutParallelism = getTopologyParallelism().orElse(null);
}
}
SpoutDeclarer spoutDeclarer = builder.setSpout(spoutId, spout, spoutParallelism);
if (spoutNumTasks != null) {
spoutDeclarer.setNumTasks(spoutNumTasks);
}
if (spoutMaxSpoutPending != null) {
spoutDeclarer.setMaxSpoutPending(spoutMaxSpoutPending);
}
return spoutDeclarer;
}
use of org.apache.storm.flux.model.PropertyDef in project storm by apache.
the class FluxBuilder method applyProperties.
private static void applyProperties(ObjectDef bean, Object instance, ExecutionContext context) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
List<PropertyDef> props = bean.getProperties();
Class clazz = instance.getClass();
if (props != null) {
for (PropertyDef prop : props) {
Object value = prop.isReference() ? context.getComponent(prop.getRef()) : prop.getValue();
Method setter = findSetter(clazz, prop.getName(), value);
if (setter != null) {
Object[] methodArgs = getArgsWithListCoercion(Collections.singletonList(value), setter.getParameterTypes());
LOG.debug("found setter, attempting to invoke with {}", methodArgs);
// invoke setter
setter.invoke(instance, methodArgs);
} else {
// look for a public instance variable
LOG.debug("no setter found. Looking for a public instance variable...");
Field field = findPublicField(clazz, prop.getName(), value);
if (field != null) {
field.set(instance, value);
}
}
}
}
}
Aggregations