public void configure()

in core/src/main/java/org/apache/stormcrawler/protocol/DelegatorProtocol.java [224:271]


    public void configure(@NotNull Config conf) {
        Object obj = conf.get(DELEGATOR_CONFIG_KEY);

        if (obj == null)
            throw new RuntimeException("DelegatorProtocol declared but no config set for it");

        // should contain a list of maps
        // each map having a className and optionally a number of filters
        if (obj instanceof Iterable) {
            // noinspection unchecked
            for (Map<String, Object> subConf : (Iterable<? extends Map<String, Object>>) obj) {
                final String className = (String) subConf.get("className");
                final Object filters = subConf.get("filters");
                final String operator = (String) subConf.get("operator");
                final String id = (String) subConf.get("id");
                final Object regexp = subConf.get("regex");

                FilteredProtocol protocol;
                if (filters == null && regexp == null) {
                    protocol = new FilteredProtocol(id, className, conf);
                } else {
                    // noinspection unchecked
                    protocol =
                            new FilteredProtocol(
                                    id,
                                    className,
                                    conf,
                                    (Map<String, String>) filters,
                                    operator,
                                    (List<String>) regexp);
                }
                protocols.add(protocol);
            }
        } else { // single value?
            throw new RuntimeException(
                    "DelegatorProtocol declared but single object found in config " + obj);
        }

        if (protocols.isEmpty()) {
            throw new RuntimeException("No sub protocols for delegation protocol defined.");
        }

        // check that the last protocol has no filter
        if (!protocols.peekLast().filters.isEmpty()) {
            throw new RuntimeException(
                    "The last sub protocol has filters but must not as it acts as the default");
        }
    }