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()) removeFailureDetectionTcp(jgroupsCfg); if (!flags.isSiteIndexSpecified()) { removeRela2(jgroupsCfg); } else { ProtocolConfiguration protocol = jgroupsCfg.getProtocol(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); } }
Introspector(org.jgroups.conf.ProtocolConfiguration config) { String name = config.getProtocolName(); try { this.protocolClass = config.getClassLoader().loadClass(name).asSubclass(Protocol.class); PrivilegedAction<Void> action = new PrivilegedAction<Void>() { @Override public Void run() { Class<?> targetClass = Introspector.this.protocolClass; while (Protocol.class.isAssignableFrom(targetClass)) { for (Method method : targetClass.getDeclaredMethods()) { if (method.isAnnotationPresent(Property.class)) { String property = method.getAnnotation(Property.class).name(); if (!property.isEmpty()) { Introspector.this.properties.add(property); } } } for (Field field : targetClass.getDeclaredFields()) { if (field.isAnnotationPresent(Property.class)) { String property = field.getAnnotation(Property.class).name(); Introspector.this.properties.add( !property.isEmpty() ? property : field.getName()); } } targetClass = targetClass.getSuperclass(); } return null; } }; WildFlySecurityManager.doChecked(action); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
private void configureMulticastSocket( ProtocolConfiguration protocol, org.jgroups.conf.ProtocolConfiguration config, String addressProperty, String portProperty, SocketBinding binding) { Map<String, String> properties = config.getProperties(); try { InetSocketAddress mcastSocketAddress = binding.getMulticastSocketAddress(); if (protocol.hasProperty(addressProperty)) { properties.put(addressProperty, mcastSocketAddress.getAddress().getHostAddress()); } if (protocol.hasProperty(portProperty)) { properties.put(portProperty, String.valueOf(mcastSocketAddress.getPort())); } } catch (IllegalStateException e) { ROOT_LOGGER.tracef( e, "Could not set %s.%s and %s.%s, %s socket binding does not specify a multicast socket", config.getProtocolName(), addressProperty, config.getProtocolName(), portProperty, binding.getName()); } }
/** * {@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 replaceProperties( JGroupsProtocolCfg cfg, Map<String, String> newProps, ProtocolType type) { ProtocolConfiguration protocol = cfg.getProtocol(type); ProtocolConfiguration newProtocol = new ProtocolConfiguration(protocol.getProtocolName(), newProps); cfg.replaceProtocol(type, newProtocol); return cfg.toString(); }
protected final void init(ProtocolStackConfigurator configurator) throws Exception { List<ProtocolConfiguration> configs = configurator.getProtocolStack(); for (ProtocolConfiguration config : configs) config.substituteVariables(); // replace vars with system props prot_stack = new ProtocolStack(this); prot_stack.setup(configs); // Setup protocol stack (creates protocol, calls init() on them) }
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; }
private static JGroupsProtocolCfg getJGroupsProtocolCfg(List<ProtocolConfiguration> baseStack) { JGroupsXmxlConfigurator configurator = new JGroupsXmxlConfigurator(baseStack); List<ProtocolConfiguration> protoStack = configurator.getProtocolStack(); Map<ProtocolType, ProtocolConfiguration> protoMap = new HashMap<ProtocolType, ProtocolConfiguration>(protoStack.size()); for (ProtocolConfiguration cfg : protoStack) protoMap.put(getProtocolType(cfg.getProtocolName()), cfg); return new JGroupsProtocolCfg(protoMap, configurator); }
private static void setSocketBindingProperty( Introspector introspector, org.jgroups.conf.ProtocolConfiguration config, String name, String value) { try { Map<String, String> properties = config.getOriginalProperties(); if (properties.containsKey(name)) { ROOT_LOGGER.unableToOverrideSocketBindingValue( name, config.getProtocolName(), value, properties.get(name)); } setProperty(introspector, config, name, value); } catch (Exception e) { ROOT_LOGGER.unableToAccessProtocolPropertyValue(e, name, config.getProtocolName()); } }
/** * {@inheritDoc} * * @see org.jgroups.conf.ProtocolStackConfigurator#getProtocolStack() */ @Override public List<org.jgroups.conf.ProtocolConfiguration> getProtocolStack() { List<org.jgroups.conf.ProtocolConfiguration> configs = new ArrayList<org.jgroups.conf.ProtocolConfiguration>( this.configuration.getProtocols().size() + 1); TransportConfiguration transport = this.configuration.getTransport(); org.jgroups.conf.ProtocolConfiguration config = this.createProtocol(transport); Map<String, String> properties = config.getProperties(); if (transport.isShared()) { properties.put(Global.SINGLETON_NAME, this.configuration.getName()); } SocketBinding binding = transport.getSocketBinding(); if (binding != null) { this.configureBindAddress(transport, config, binding); this.configureServerSocket(transport, config, "bind_port", binding); this.configureMulticastSocket(transport, config, "mcast_addr", "mcast_port", binding); } SocketBinding diagnosticsSocketBinding = transport.getDiagnosticsSocketBinding(); boolean diagnostics = (diagnosticsSocketBinding != null); properties.put("enable_diagnostics", String.valueOf(diagnostics)); if (diagnostics) { this.configureMulticastSocket( transport, config, "diagnostics_addr", "diagnostics_port", diagnosticsSocketBinding); } configs.add(config); for (ProtocolConfiguration protocol : this.configuration.getProtocols()) { config = this.createProtocol(protocol); binding = protocol.getSocketBinding(); if (binding != null) { this.configureBindAddress(protocol, config, binding); this.configureServerSocket(protocol, config, "bind_port", binding); this.configureServerSocket(protocol, config, "start_port", binding); this.configureMulticastSocket(protocol, config, "mcast_addr", "mcast_port", binding); } else if (transport.getSocketBinding() != null) { // If no socket-binding was specified, use bind address of transport this.configureBindAddress(protocol, config, transport.getSocketBinding()); } configs.add(config); } return configs; }
/** * {@inheritDoc} * * @see org.jgroups.conf.ProtocolStackConfigurator#getProtocolStack() */ @Override public List<org.jgroups.conf.ProtocolConfiguration> getProtocolStack() { List<org.jgroups.conf.ProtocolConfiguration> stack = new ArrayList<>(this.configuration.getProtocols().size() + 1); TransportConfiguration transport = this.configuration.getTransport(); org.jgroups.conf.ProtocolConfiguration protocol = createProtocol(this.configuration, transport); Map<String, String> properties = protocol.getProperties(); Introspector introspector = new Introspector(protocol); SocketBinding binding = transport.getSocketBinding(); if (binding != null) { configureBindAddress(introspector, protocol, binding); configureServerSocket(introspector, protocol, "bind_port", binding); configureMulticastSocket(introspector, protocol, "mcast_addr", "mcast_port", binding); } SocketBinding diagnosticsSocketBinding = transport.getDiagnosticsSocketBinding(); boolean diagnostics = (diagnosticsSocketBinding != null); properties.put("enable_diagnostics", String.valueOf(diagnostics)); if (diagnostics) { configureMulticastSocket( introspector, protocol, "diagnostics_addr", "diagnostics_port", diagnosticsSocketBinding); } stack.add(protocol); final Class<? extends TP> transportClass = introspector.getProtocolClass().asSubclass(TP.class); PrivilegedExceptionAction<TP> action = new PrivilegedExceptionAction<TP>() { @Override public TP run() throws InstantiationException, IllegalAccessException { return transportClass.newInstance(); } }; try { stack.addAll( createProtocols( this.configuration, WildFlySecurityManager.doChecked(action).isMulticastCapable())); } catch (PrivilegedActionException e) { throw new IllegalStateException(e.getCause()); } return stack; }
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 configureServerSocket( ProtocolConfiguration protocol, org.jgroups.conf.ProtocolConfiguration config, String property, SocketBinding binding) { if (protocol.hasProperty(property)) { config.getProperties().put(property, String.valueOf(binding.getSocketAddress().getPort())); } }
private void configureBindAddress( ProtocolConfiguration protocol, org.jgroups.conf.ProtocolConfiguration config, SocketBinding binding) { final String property = "bind_addr"; if (protocol.hasProperty(property)) { config .getProperties() .put(property, binding.getSocketAddress().getAddress().getHostAddress()); } }
private static void configureMulticastSocket( Introspector introspector, org.jgroups.conf.ProtocolConfiguration config, String addressProperty, String portProperty, SocketBinding binding) { try { InetSocketAddress mcastSocketAddress = binding.getMulticastSocketAddress(); setSocketBindingProperty( introspector, config, addressProperty, mcastSocketAddress.getAddress().getHostAddress()); setSocketBindingProperty( introspector, config, portProperty, String.valueOf(mcastSocketAddress.getPort())); } catch (IllegalStateException e) { ROOT_LOGGER.couldNotSetAddressAndPortNoMulticastSocket( e, config.getProtocolName(), addressProperty, config.getProtocolName(), portProperty, binding.getName()); } }