@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); } }
params.put(name, value); ProtocolConfiguration cfg=new ProtocolConfiguration(protocol, params); prot_data.add(cfg); if(subnode.getNodeType() != Node.ELEMENT_NODE) continue; cfg.addSubtree(subnode);
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; clazz=Util.loadClass(protocol_name, config.getClassLoader()); List<Node> subtrees=config.getSubtrees(); if(subtrees != null) { for(Node node: subtrees)
/** * 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); } } }); } }
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; } }
Introspector(org.jgroups.conf.ProtocolConfiguration config) { String name = config.getProtocolName(); try { this.protocolClass = config.getClassLoader().loadClass(name).asSubclass(Protocol.class); PrivilegedAction<Void> action = () -> { 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 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()); } }
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()); } }
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(); }
/** * Creates a new protocol given the protocol specification. Initializes the properties and starts the * up and down handler threads. * @param prot_spec The specification of the protocol. Same convention as for specifying a protocol stack. * An exception will be thrown if the class cannot be created. Example: * <pre>"VERIFY_SUSPECT(timeout=1500)"</pre> Note that no colons (:) have to be * specified * @param stack The protocol stack * @return Protocol The newly created protocol * @exception Exception Will be thrown when the new protocol cannot be created */ public static Protocol createProtocol(String prot_spec, ProtocolStack stack) throws Exception { ProtocolConfiguration config; Protocol prot; if(prot_spec == null) throw new Exception("Configurator.createProtocol(): prot_spec is null"); // parse the configuration for this protocol config=new ProtocolConfiguration(prot_spec); // create an instance of the protocol class and configure it prot=createLayer(stack, config); prot.init(); return prot; }
public String getProtocolStringNewXml() { StringBuilder buf=new StringBuilder(protocol_name + ' '); if(!properties.isEmpty()) { boolean first=true; for(Map.Entry<String,String> entry: properties.entrySet()) { String key=entry.getKey(); String val=entry.getValue(); if(first) first=false; else buf.append(' '); buf.append(getParameterStringXml(key, val)); } } return buf.toString(); }
public String getProtocolString() { StringBuilder buf=new StringBuilder(protocol_name); if(!properties.isEmpty()) { boolean first=true; buf.append('('); for(Map.Entry<String,String> entry: properties.entrySet()) { String key=entry.getKey(); String val=entry.getValue(); if(first) first=false; else buf.append(';'); buf.append(getParameterString(key, val)); } buf.append(')'); } return buf.toString(); }
private void setPropertyNoOverride(ProtocolConfiguration protocol, org.jgroups.conf.ProtocolConfiguration config, String name, String value) { boolean overridden = false ; String propertyValue = null ; // check if the property has been overridden by the user and log a message try { if (overridden = config.getOriginalProperties().containsKey(name)) propertyValue = config.getOriginalProperties().get(name); } catch(Exception e) { ROOT_LOGGER.unableToAccessProtocolPropertyValue(e, name, protocol.getName()); } // log a warning if property tries to override if (overridden) { ROOT_LOGGER.unableToOverrideSocketBindingValue(name, protocol.getName(), value, propertyValue); } setProperty(protocol, config, name, value); }
Map<String,String> properties = new HashMap<>(protocol_config.getProperties());
private void configureMulticastSocket(ProtocolConfiguration protocol, org.jgroups.conf.ProtocolConfiguration config, String addressProperty, String portProperty, SocketBinding binding) { try { InetSocketAddress mcastSocketAddress = binding.getMulticastSocketAddress(); this.setPropertyNoOverride(protocol, config, addressProperty, mcastSocketAddress.getAddress().getHostAddress()); this.setPropertyNoOverride(protocol, config, portProperty, String.valueOf(mcastSocketAddress.getPort())); } catch (IllegalStateException e) { ROOT_LOGGER.couldNotSetAddressAndPortNoMulticastSocket(e, config.getProtocolName(), addressProperty, config.getProtocolName(), portProperty, binding.getName()); } }
/** * Creates a new protocol given the protocol specification. Initializes the properties and starts the * up and down handler threads. * @param prot_spec The specification of the protocol. Same convention as for specifying a protocol stack. * An exception will be thrown if the class cannot be created. Example: * <pre>"VERIFY_SUSPECT(timeout=1500)"</pre> Note that no colons (:) have to be * specified * @param stack The protocol stack * @return Protocol The newly created protocol * @exception Exception Will be thrown when the new protocol cannot be created */ public static Protocol createProtocol(String prot_spec, ProtocolStack stack) throws Exception { ProtocolConfiguration config; Protocol prot; if(prot_spec == null) throw new Exception("Configurator.createProtocol(): prot_spec is null"); // parse the configuration for this protocol config=new ProtocolConfiguration(prot_spec); // create an instance of the protocol class and configure it prot=createLayer(stack, config); prot.init(); return prot; }
public String getProtocolStringNewXml() { StringBuilder buf=new StringBuilder(protocol_name + ' '); if(!properties.isEmpty()) { boolean first=true; for(Map.Entry<String,String> entry: properties.entrySet()) { String key=entry.getKey(); String val=entry.getValue(); if(first) first=false; else buf.append(' '); buf.append(getParameterStringXml(key, val)); } } return buf.toString(); }
public String getProtocolString() { StringBuilder buf=new StringBuilder(protocol_name); if(!properties.isEmpty()) { boolean first=true; buf.append('('); for(Map.Entry<String,String> entry: properties.entrySet()) { String key=entry.getKey(); String val=entry.getValue(); if(first) first=false; else buf.append(';'); buf.append(getParameterString(key, val)); } buf.append(')'); } return buf.toString(); }
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(); }
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; clazz=Util.loadClass(protocol_name, config.getClassLoader()); List<Node> subtrees=config.getSubtrees(); if(subtrees != null) { for(Node node: subtrees)