Search in sources :

Example 1 with PropertyDef

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;
}
Also used : PropertyDef(org.apache.storm.flux.model.PropertyDef) SpoutDeclarer(org.apache.storm.topology.SpoutDeclarer) SpoutDef(org.apache.storm.flux.model.SpoutDef)

Example 2 with PropertyDef

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);
                }
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) PropertyDef(org.apache.storm.flux.model.PropertyDef) Method(java.lang.reflect.Method)

Aggregations

PropertyDef (org.apache.storm.flux.model.PropertyDef)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 SpoutDef (org.apache.storm.flux.model.SpoutDef)1 SpoutDeclarer (org.apache.storm.topology.SpoutDeclarer)1