public String toString() { return super.toString() + ", protocols=" + printProtocols(protocols); }
public String toString() {return "config=" + config + super.toString();} }
public void parse(Node node) throws Exception { RelayConfig.parse(node, sites); }
protected static void parseBridges(SiteConfig site_config, Node root) throws Exception { NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; String node_name=node.getNodeName(); match(BRIDGE, node_name, true); NamedNodeMap attrs=node.getAttributes(); if(attrs == null || attrs.getLength() == 0) continue; Attr name_attr=(Attr)attrs.getNamedItem("name"); Attr config_attr=(Attr)attrs.getNamedItem("config"); String name=name_attr != null? name_attr.getValue() : null; String config=config_attr.getValue(); BridgeConfig bridge_config=new PropertiesBridgeConfig(name, config); site_config.addBridge(bridge_config); } }
protected static void parseSites(final Map<String,SiteConfig> map, Node root) throws Exception { NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; match(SITE, node.getNodeName(), true); NamedNodeMap attrs=node.getAttributes(); if(attrs == null || attrs.getLength() == 0) continue; Attr name_attr=(Attr)attrs.getNamedItem("name"); String name=name_attr.getValue(); if(map.containsKey(name)) throw new Exception("Site \"" + name + "\" already defined"); SiteConfig site_config=new SiteConfig(name); map.put(name, site_config); parseBridgesAndForwards(site_config, node); } }
RelayConfig.SiteConfig siteConfig = new RelayConfig.SiteConfig(site); protocol.addSite(site, siteConfig); if (site.equals(localSite)) { for (RelayConfig.BridgeConfig bridge: bridges.values()) { siteConfig.addBridge(bridge);
protected static void parseForwards(SiteConfig site_config, Node root) throws Exception { NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; String node_name=node.getNodeName(); match(FORWARD, node_name, true); NamedNodeMap attrs=node.getAttributes(); if(attrs == null || attrs.getLength() == 0) continue; Attr to_attr=(Attr)attrs.getNamedItem("to"); Attr gw_attr=(Attr)attrs.getNamedItem("gateway"); String to=to_attr.getValue(); String gateway=gw_attr.getValue(); ForwardConfig forward_config=new ForwardConfig(to, gateway); site_config.addForward(forward_config); } }
public static void parse(Node root, final Map<String,SiteConfig> map) throws Exception { match(RELAY_CONFIG, root.getNodeName(), true); NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; String element_name=node.getNodeName(); if(SITES.equals(element_name)) parseSites(map, node); else throw new Exception("expected <" + SITES + ">, but got " + "<" + element_name + ">"); } }
protected static void parseBridgesAndForwards(SiteConfig site_config, Node root) throws Exception { NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; String node_name=node.getNodeName(); if(BRIDGES.equals(node_name)) parseBridges(site_config, node); else if(FORWARDS.equals(node_name)) parseForwards(site_config, node); else throw new Exception("expected \"" + BRIDGES + "\" or \"" + FORWARDS + "\" keywords"); } }
protected void startRelayer(Relayer rel, String bridge_name) { try { log.trace(local_addr + ": became site master; starting bridges"); rel.start(site_config.getBridges(), bridge_name, site); } catch(Throwable t) { log.error(local_addr + ": failed starting relayer", t); } }
Bridge bridge=new Bridge(bridge_config.createChannel(), bridge_config.getClusterName(), bridge_name, () -> new SiteUUID(UUID.randomUUID(), null, my_site_id)); bridges.add(bridge);
log.trace(local_addr + ": site configuration:\n" + site_config); if(!site_config.getForwards().isEmpty()) log.warn(local_addr + ": forwarding routes are currently not supported and will be ignored. This will change " + "with hierarchical routing (https://issues.jboss.org/browse/JGRP-1506)");
protected static void parseBridges(SiteConfig site_config, Node root) throws Exception { NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; String node_name=node.getNodeName(); match(BRIDGE, node_name, true); NamedNodeMap attrs=node.getAttributes(); if(attrs == null || attrs.getLength() == 0) continue; Attr name_attr=(Attr)attrs.getNamedItem("name"); Attr config_attr=(Attr)attrs.getNamedItem("config"); String name=name_attr != null? name_attr.getValue() : null; String config=config_attr.getValue(); BridgeConfig bridge_config=new PropertiesBridgeConfig(name, config); site_config.addBridge(bridge_config); } }
public String toString() { return super.toString() + ", protocols=" + printProtocols(protocols); }
/** Parses site names and their configuration (e.g. "nyc" --> SiteConfig) into the map passed as argument */ public static void parse(InputStream input, final Map<String,SiteConfig> map) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); // for now DocumentBuilder builder=factory.newDocumentBuilder(); Document document=builder.parse(input); Element root=document.getDocumentElement(); parse(root, map); }
protected void startRelayer(Relayer rel, String bridge_name) { try { log.trace(local_addr + ": became site master; starting bridges"); rel.start(site_config.getBridges(), bridge_name, site); } catch(Throwable t) { log.error(local_addr + ": failed starting relayer", t); } }
public String toString() {return "config=" + config + super.toString();} }
public static void main(String[] args) throws Exception { InputStream input=new FileInputStream("/home/bela/relay2.xml"); Map<String,SiteConfig> sites=new HashMap<>(); RelayConfig.parse(input, sites); System.out.println("sites:"); for(Map.Entry<String,SiteConfig> entry: sites.entrySet()) System.out.println(entry.getKey() + ":\n" + entry.getValue() + "\n"); } }
/** * Parses the configuration by reading the config file. * @throws Exception */ protected void parseSiteConfiguration(final Map<String,RelayConfig.SiteConfig> map) throws Exception { InputStream input=null; try { input=ConfiguratorFactory.getConfigStream(config); RelayConfig.parse(input, map); } finally { Util.close(input); } }
public void parse(Node node) throws Exception { RelayConfig.parse(node, sites); }