Search in sources :

Example 1 with Groups

use of services.moleculer.eventbus.Groups in project moleculer-java by moleculer-java.

the class CommonUtils method parseParams.

// --- PARSE CALL / BROADCAST PARAMS ---
public static final ParseResult parseParams(Object[] params) {
    Tree data = null;
    CallOptions.Options opts = null;
    Groups groups = null;
    if (params != null) {
        if (params.length == 1) {
            if (params[0] instanceof Tree) {
                data = (Tree) params[0];
            } else {
                data = new CheckedTree(params[0]);
            }
        } else {
            LinkedHashMap<String, Object> map = new LinkedHashMap<>();
            String prev = null;
            Object value;
            for (int i = 0; i < params.length; i++) {
                value = params[i];
                if (prev == null) {
                    if (!(value instanceof String)) {
                        if (value instanceof CallOptions.Options) {
                            opts = (CallOptions.Options) value;
                            continue;
                        }
                        if (value instanceof Groups) {
                            groups = (Groups) value;
                            continue;
                        }
                        i++;
                        throw new IllegalArgumentException("Parameter #" + i + " (\"" + value + "\") must be String, Context, Groups, or CallOptions!");
                    }
                    prev = (String) value;
                    continue;
                }
                map.put(prev, value);
                prev = null;
            }
            data = new Tree(map);
        }
    }
    return new ParseResult(data, opts, groups);
}
Also used : CallOptions(services.moleculer.context.CallOptions) CallOptions(services.moleculer.context.CallOptions) LinkedHashMap(java.util.LinkedHashMap) Groups(services.moleculer.eventbus.Groups) Tree(io.datatree.Tree)

Aggregations

Tree (io.datatree.Tree)1 LinkedHashMap (java.util.LinkedHashMap)1 CallOptions (services.moleculer.context.CallOptions)1 Groups (services.moleculer.eventbus.Groups)1