All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.fork.ForkConfig Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 34.0.0.Final
Show newest version
package org.jgroups.fork;

import org.jgroups.conf.ProtocolConfiguration;
import org.jgroups.conf.XmlConfigurator;
import org.jgroups.conf.XmlNode;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Parses the fork-stacks.xsd schema. See conf/fork-stacks.xml for an example
 * @author Bela Ban
 * @since  3.4
 */
public final class ForkConfig {
    protected static final String FORK_STACKS   = "fork-stacks";
    protected static final String FORK_STACK    = "fork-stack";
    protected static final String ID            = "id";

	private ForkConfig() {
		throw new InstantiationError( "Must not instantiate this class" );
	}

    /**
     * Parses the input and returns a map of fork-stack IDs and lists of ProtocolConfigurations
     */
    public static Map> parse(InputStream input) throws Exception {
        XmlNode root=XmlConfigurator.parseXmlDocument(input);
        return parse(root);
    }

    public static Map> parse(XmlNode root) throws Exception {
        match(FORK_STACKS, root.getName());
        List children=root.getChildren();
        if(children == null || children.isEmpty())
            return null;

        Map> map=new HashMap<>();
        for(XmlNode node: children) {
            match(FORK_STACK, node.getName());
            parseForkStack(map, node);
        }
        return map;
    }


    protected static void parseForkStack(final Map> map, XmlNode root) throws Exception {
        List children=root.getChildren();
        if(children == null || children.isEmpty())
            return;

        Map attributes=root.getAttributes();
        String fork_stack_id=attributes.get(ID);
        if(map.containsKey(fork_stack_id))
            throw new IllegalStateException("duplicate fork-stack ID: \"" + fork_stack_id + "\"");

        for(XmlNode node : children) {
            List protocols=XmlConfigurator.parseProtocols(node);
            map.put(fork_stack_id, protocols);
        }
    }



    protected static void match(String expected_name, String name) throws Exception {
        if(!expected_name.equals(name))
            throw new Exception("\"" + name + "\" didn't match \"" + expected_name + "\"");
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy