/** * Replace variables of the form ${var:default} with the getProperty(var, * default) * * @param configurator */ public static void substituteVariables(ProtocolStackConfigurator configurator) { List<ProtocolConfiguration> protocols=configurator.getProtocolStack(); protocols.stream().filter(data -> data != null).forEach(data -> { Map<String,String> parms=data.getProperties(); for(Map.Entry<String,String> entry : parms.entrySet()) { String val=entry.getValue(); String replacement=Util.substituteVariable(val); if(!replacement.equals(val)) { entry.setValue(replacement); } } }); } }
@Override public ProtocolDefaults get() { ProtocolStackConfigurator configurator = load(ProtocolDefaultsServiceConfigurator.this.resource); try { for (org.jgroups.conf.ProtocolConfiguration config: configurator.getProtocolStack()) { String protocolClassName = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, config.getProtocolName()); Class<? extends Protocol> protocolClass = Protocol.class.getClassLoader().loadClass(protocolClassName).asSubclass(Protocol.class); this.map.put(protocolClass, Collections.unmodifiableMap(config.getProperties())); } return this; } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
private static String dump(Collection<ProtocolConfiguration> configs) { StringBuilder sb=new StringBuilder(); String indent=" "; sb.append("<config>\n"); for(ProtocolConfiguration cfg: configs) { sb.append(indent).append("<").append(cfg.getProtocolName()); Map<String,String> props=cfg.getProperties(); if(props.isEmpty()) { sb.append(" />\n"); } else { sb.append("\n").append(indent).append(indent); for(Map.Entry<String,String> entry: props.entrySet()) { String key=entry.getKey(); String val=entry.getValue(); key=trim(key); val=trim(val); sb.append(key).append("=\"").append(val).append("\" "); } sb.append(" />\n"); } } sb.append("</config>\n"); return sb.toString(); }
Map<String,String> properties = new HashMap<>(protocol_config.getProperties());
protected static Protocol createLayer(ProtocolStack stack, ProtocolConfiguration config) throws Exception { String protocol_name=config.getProtocolName(); Map<String, String> properties=new HashMap<>(config.getProperties()); Protocol retval=null;
Map<String,String> properties=new HashMap<>(protocol_config.getProperties());
private static void setProperty(Introspector introspector, org.jgroups.conf.ProtocolConfiguration config, String name, String value) { if (introspector.hasProperty(name)) { config.getProperties().put(name, value); } }
private void setProperty(ProtocolConfiguration protocol, org.jgroups.conf.ProtocolConfiguration config, String name, String value) { if (protocol.hasProperty(name)) { config.getProperties().put(name, value); } }
@Override public ProtocolDefaults get() { ProtocolStackConfigurator configurator = load(ProtocolDefaultsServiceConfigurator.this.resource); try { for (org.jgroups.conf.ProtocolConfiguration config: configurator.getProtocolStack()) { String protocolClassName = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, config.getProtocolName()); Class<? extends Protocol> protocolClass = Protocol.class.getClassLoader().loadClass(protocolClassName).asSubclass(Protocol.class); this.map.put(protocolClass, Collections.unmodifiableMap(config.getProperties())); } return this; } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
/** * Replace variables of the form ${var:default} with the getProperty(var, * default) * * @param configurator */ public static void substituteVariables(ProtocolStackConfigurator configurator) { List<ProtocolConfiguration> protocols=configurator.getProtocolStack(); protocols.stream().filter(data -> data != null).forEach(data -> { Map<String,String> parms=data.getProperties(); for(Map.Entry<String,String> entry : parms.entrySet()) { String val=entry.getValue(); String replacement=Util.substituteVariable(val); if(!replacement.equals(val)) { entry.setValue(replacement); } } }); } }
/** * {@inheritDoc} * @see org.jboss.msc.value.Value#getValue() */ @Override public ProtocolDefaults getValue() { ProtocolStackConfigurator configurator = load(ProtocolDefaultsBuilder.this.resource); for (org.jgroups.conf.ProtocolConfiguration config: configurator.getProtocolStack()) { this.map.put(config.getProtocolName(), Collections.unmodifiableMap(config.getProperties())); } return this; }
private static String dump(Collection<ProtocolConfiguration> configs) { StringBuilder sb=new StringBuilder(); String indent=" "; sb.append("<config>\n"); for(ProtocolConfiguration cfg: configs) { sb.append(indent).append("<").append(cfg.getProtocolName()); Map<String,String> props=cfg.getProperties(); if(props.isEmpty()) { sb.append(" />\n"); } else { sb.append("\n").append(indent).append(indent); for(Map.Entry<String,String> entry: props.entrySet()) { String key=entry.getKey(); String val=entry.getValue(); key=trim(key); val=trim(val); sb.append(key).append("=\"").append(val).append("\" "); } sb.append(" />\n"); } } sb.append("</config>\n"); return sb.toString(); }
private static String replaceMCastAddressAndPort(JGroupsProtocolCfg jgroupsCfg) { ProtocolConfiguration udp = jgroupsCfg.getProtocol(UDP); if (udp == null) return jgroupsCfg.toString(); Map<String, String> props = udp.getProperties(); props.put("mcast_addr", threadMcastIP.get()); props.put("mcast_port", threadMcastPort.get().toString()); return replaceProperties(jgroupsCfg, props, UDP); }
private static String getTestPingDiscovery(String fullTestName, JGroupsProtocolCfg jgroupsCfg) { ProtocolType type = TEST_PING; Map<String, String> props = jgroupsCfg.getProtocol(type).getProperties(); props.put("testName", fullTestName); return replaceProperties(jgroupsCfg, props, type); }
static List<ProtocolConfiguration> copy(List<ProtocolConfiguration> protocols) { // Make a safe copy of the protocol stack to avoid concurrent modification issues List<ProtocolConfiguration> copy = new ArrayList<ProtocolConfiguration>(protocols.size()); for (ProtocolConfiguration p : protocols) copy.add(new ProtocolConfiguration( p.getProtocolName(), immutableMapCopy(p.getProperties()))); return copy; } }
/** * {@inheritDoc} * @see org.jboss.msc.service.Service#start(org.jboss.msc.service.StartContext) */ @Override public void start(final StartContext context) throws StartException { ProtocolStackConfigurator configurator = load(ProtocolDefaultsService.this.resource); Defaults defaults = new Defaults(); for (org.jgroups.conf.ProtocolConfiguration config: configurator.getProtocolStack()) { defaults.add(config.getProtocolName(), config.getProperties()); } ProtocolDefaultsService.this.defaults = defaults; }
TransportConfiguration transport = this.configuration.getTransport(); org.jgroups.conf.ProtocolConfiguration protocol = createProtocol(this.configuration, transport); Map<String, String> properties = protocol.getProperties();
private static String replaceTcpStartPort(JGroupsProtocolCfg jgroupsCfg, TransportFlags transportFlags) { ProtocolType transportProtocol = jgroupsCfg.containsProtocol(TCP_NIO2) ? TCP_NIO2 : TCP; Map<String, String> props = jgroupsCfg.getProtocol(transportProtocol).getProperties(); Integer startPort = threadTcpStartPort.get(); int portRange = TCP_PORT_RANGE_PER_THREAD; if (transportFlags.isPortRangeSpecified()) { portRange = 25; int maxIndex = TCP_PORT_RANGE_PER_THREAD / portRange - 1; if (transportFlags.portRange() > maxIndex) { throw new IllegalStateException("Currently we only support " + (maxIndex + 1) + " ranges/sites!"); } startPort += transportFlags.portRange() * portRange; } props.put("bind_port", startPort.toString()); // In JGroups, the port_range is inclusive props.put("port_range", String.valueOf(portRange - 1)); return replaceProperties(jgroupsCfg, props, transportProtocol); }
TransportConfiguration transport = this.configuration.getTransport(); org.jgroups.conf.ProtocolConfiguration config = this.createProtocol(transport); Map<String, String> properties = config.getProperties();
public static String getTcpConfig(String fullTestName, TransportFlags flags) { // With the XML already parsed, make a safe copy of the // protocol stack configurator and use that accordingly. JGroupsProtocolCfg jgroupsCfg = getJGroupsProtocolCfg(tcpConfigurator.getProtocolStack()); if (!flags.withFD()) removeFailureDetection(jgroupsCfg); if (!flags.isRelayRequired()) { removeRelay2(jgroupsCfg); } else { ProtocolConfiguration protocol = jgroupsCfg.getProtocol(TEST_RELAY2); protocol.getProperties().put("site", flags.siteName()); if (flags.relayConfig() != null) //if not specified, use default protocol.getProperties().put("config", flags.relayConfig()); } if (!flags.withMerge()) removeMerge(jgroupsCfg); if (jgroupsCfg.containsProtocol(TEST_PING)) { replaceTcpStartPort(jgroupsCfg, flags); if (fullTestName == null) return jgroupsCfg.toString(); // IDE run of test else return getTestPingDiscovery(fullTestName, jgroupsCfg); // Cmd line test run } else { return replaceMCastAddressAndPort(jgroupsCfg); } }