Search in sources :

Example 1 with ProtocolConfiguration

use of org.jgroups.conf.ProtocolConfiguration in project JGroups by belaban.

the class Configurator method createProtocol.

/**
 * 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;
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration)

Example 2 with ProtocolConfiguration

use of org.jgroups.conf.ProtocolConfiguration in project JGroups by belaban.

the class ProtocolConfigurationTest method testDefaultAssignment.

/*
	 * Checks assignment of defaults
	 */
public void testDefaultAssignment() throws Exception {
    List<ProtocolConfiguration> protocol_configs = new ArrayList<>();
    List<Protocol> protocols = new ArrayList<>();
    // create the layer described by DEFAULTS
    protocol = Configurator.createProtocol(defaultProps, stack);
    // process the defaults
    protocol_configs.add(new ProtocolConfiguration(defaultProps));
    protocols.add(protocol);
    Configurator.setDefaultAddressValues(protocols, StackType.IPv4);
    // get the value which should have been assigned a default
    int a = ((DEFAULTS) protocol).getA();
    System.out.println("value of a = " + a);
    // get the value which should not have been assigned a default
    int b = ((DEFAULTS) protocol).getB();
    System.out.println("value of b = " + b);
    // assert b == 333 ;
    if (b != 333) {
        throw new RuntimeException("default property value set when it should not have been");
    }
    // get the value which should not have been assigned a default
    InetAddress c = ((DEFAULTS) protocol).getC();
    System.out.println("value of c = " + c);
    assert c != null;
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) ArrayList(java.util.ArrayList) Protocol(org.jgroups.stack.Protocol) InetAddress(java.net.InetAddress)

Example 3 with ProtocolConfiguration

use of org.jgroups.conf.ProtocolConfiguration in project JGroups by belaban.

the class Configurator method createInetAddressMap.

/*
     * Discovers all fields or methods within the protocol stack which set InetAddress, IpAddress, InetSocketAddress
     * (and lists of such) for which the user has specified a default value. Stores the resulting set of fields and
     * methods in a map of the form Protocol -> Property -> InetAddressInfo
     * where InetAddressInfo instances encapsulate the InetAddress related information of the fields and methods.
     */
public static Map<String, Map<String, InetAddressInfo>> createInetAddressMap(List<ProtocolConfiguration> protocol_configs, List<Protocol> protocols) throws Exception {
    Map<String, Map<String, InetAddressInfo>> inetAddressMap = new HashMap<>();
    for (int i = 0; i < protocol_configs.size(); i++) {
        ProtocolConfiguration protocol_config = protocol_configs.get(i);
        Protocol protocol = protocols.get(i);
        String protocolName = protocol.getName();
        // regenerate the properties which were destroyed during basic property processing
        Map<String, String> properties = new HashMap<>(protocol_config.getProperties());
        // check which InetAddress-related properties are non-null, and create an InetAddressInfo structure for them
        Method[] methods = Util.getAllDeclaredMethodsWithAnnotations(protocol.getClass(), Property.class);
        for (int j = 0; j < methods.length; j++) {
            if (isSetPropertyMethod(methods[j], protocol.getClass())) {
                String propertyName = PropertyHelper.getPropertyName(methods[j]);
                String propertyValue = properties.get(propertyName);
                // if there is a systemProperty attribute defined in the annotation, set the property value from the system property
                String tmp = grabSystemProp(methods[j].getAnnotation(Property.class));
                if (tmp != null)
                    propertyValue = tmp;
                if (propertyValue != null && InetAddressInfo.isInetAddressRelated(methods[j])) {
                    Object converted = null;
                    try {
                        converted = PropertyHelper.getConvertedValue(protocol, methods[j], properties, propertyValue, false, Util.getIpStackType());
                    } catch (Exception e) {
                        throw new Exception("string could not be converted for method " + propertyName + " in " + protocolName + " with default value " + propertyValue + ".Exception is " + e, e);
                    }
                    InetAddressInfo inetinfo = new InetAddressInfo(protocol, methods[j], properties, propertyValue, converted);
                    Map<String, InetAddressInfo> m = inetAddressMap.computeIfAbsent(protocolName, k -> new HashMap<>());
                    m.put(propertyName, inetinfo);
                }
            }
        }
        // traverse class hierarchy and find all annotated fields and add them to the list if annotated
        Field[] fields = Util.getAllDeclaredFieldsWithAnnotations(protocol.getClass(), Property.class);
        for (int j = 0; j < fields.length; j++) {
            String propertyName = PropertyHelper.getPropertyName(fields[j], properties);
            String propertyValue = properties.get(propertyName);
            // if there is a systemProperty attribute defined in the annotation, set the property value from the system property
            String tmp = grabSystemProp(fields[j].getAnnotation(Property.class));
            if (tmp != null)
                propertyValue = tmp;
            if ((propertyValue != null || !PropertyHelper.usesDefaultConverter(fields[j])) && InetAddressInfo.isInetAddressRelated(fields[j])) {
                Object converted = null;
                try {
                    converted = PropertyHelper.getConvertedValue(protocol, fields[j], properties, propertyValue, false, Util.getIpStackType());
                } catch (Exception e) {
                    throw new Exception("string could not be converted for method " + propertyName + " in " + protocolName + " with default value " + propertyValue + ".Exception is " + e, e);
                }
                InetAddressInfo inetinfo = new InetAddressInfo(protocol, fields[j], properties, propertyValue, converted);
                Map<String, InetAddressInfo> m = inetAddressMap.computeIfAbsent(protocolName, k -> new HashMap<>());
                m.put(propertyName, inetinfo);
            }
        }
    }
    return inetAddressMap;
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) Property(org.jgroups.annotations.Property)

Example 4 with ProtocolConfiguration

use of org.jgroups.conf.ProtocolConfiguration in project JGroups by belaban.

the class InetAddressChecksTest method testIPVersionCheckingNoConsistentVersion.

/*
	 * Checks IP version mechanism for inconsistent version processing
	 */
@Test(expectedExceptions = RuntimeException.class)
public void testIPVersionCheckingNoConsistentVersion() throws Exception {
    List<ProtocolConfiguration> protocol_configs = new ArrayList<>();
    List<Protocol> protocols = new ArrayList<>();
    // create the layer described by IPCHECK
    protocol = Configurator.createProtocol(ipCheckNoConsistentProps, stack);
    // process the defaults
    protocol_configs.add(new ProtocolConfiguration(ipCheckNoConsistentProps));
    protocols.add(protocol);
    Map<String, Map<String, InetAddressInfo>> inetAddressMap = null;
    try {
        inetAddressMap = Configurator.createInetAddressMap(protocol_configs, protocols);
        Collection<InetAddress> addrs = Configurator.getAddresses(inetAddressMap);
        determineIpVersionFromAddresses(addrs);
    } catch (RuntimeException e) {
        System.out.println("Expected exception received: " + e.getMessage());
        throw e;
    }
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) Protocol(org.jgroups.stack.Protocol) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test)

Example 5 with ProtocolConfiguration

use of org.jgroups.conf.ProtocolConfiguration in project JGroups by belaban.

the class ForkConfig method parseForkStack.

protected static void parseForkStack(final Map<String, List<ProtocolConfiguration>> map, XmlNode root) throws Exception {
    List<XmlNode> children = root.getChildren();
    if (children == null || children.isEmpty())
        return;
    Map<String, String> 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<ProtocolConfiguration> protocols = XmlConfigurator.parseProtocols(node);
        map.put(fork_stack_id, protocols);
    }
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) XmlNode(org.jgroups.conf.XmlNode)

Aggregations

ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)12 InetAddress (java.net.InetAddress)6 Protocol (org.jgroups.stack.Protocol)4 Property (org.jgroups.annotations.Property)3 Inet6Address (java.net.Inet6Address)2 ArrayList (java.util.ArrayList)2 TP (org.jgroups.protocols.TP)2 StackType (org.jgroups.util.StackType)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 Pattern (java.util.regex.Pattern)1 org.jgroups (org.jgroups)1 DeprecatedProperty (org.jgroups.annotations.DeprecatedProperty)1 ClassConfigurator (org.jgroups.conf.ClassConfigurator)1 PropertyConverter (org.jgroups.conf.PropertyConverter)1 XmlNode (org.jgroups.conf.XmlNode)1 ReflectUtils (org.jgroups.jmx.ReflectUtils)1 MessageBatch (org.jgroups.util.MessageBatch)1