Search in sources :

Example 41 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class UNICAST_DropFirstAndLastTest method printConnectionTables.

protected void printConnectionTables(JChannel... channels) {
    System.out.println("**** CONNECTIONS:");
    for (JChannel ch : channels) {
        Protocol ucast = ch.getProtocolStack().findProtocol(Util.getUnicastProtocols());
        System.out.println(ch.getName() + ":\n" + printConnections(ucast) + "\n");
    }
}
Also used : Protocol(org.jgroups.stack.Protocol)

Example 42 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class ConcurrentStartupTest method create.

protected static JChannel create(Class<? extends TP> tp_cl, Class<? extends Discovery> discovery_cl, String name) throws Exception {
    TP tp = tp_cl.getDeclaredConstructor().newInstance().setBindAddress(Util.getLoopback());
    Protocol[] protocols = { tp, discovery_cl.getDeclaredConstructor().newInstance(), new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(1000).setLeaveTimeout(100) };
    return new JChannel(protocols).name(name);
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS)

Example 43 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class StateTransferTest2 method replaceStateTransferProtocolWith.

protected static void replaceStateTransferProtocolWith(JChannel ch, Class<? extends Protocol> state_transfer_class) throws Exception {
    ProtocolStack stack = ch.getProtocolStack();
    if (stack.findProtocol(state_transfer_class) != null)
        // protocol of the right class is already in stack
        return;
    Protocol prot = stack.findProtocol(STATE_TRANSFER.class, StreamingStateTransfer.class);
    Protocol new_state_transfer_protcol = state_transfer_class.getDeclaredConstructor().newInstance();
    if (prot != null) {
        stack.replaceProtocol(prot, new_state_transfer_protcol);
    } else {
        // no state transfer protocol found in stack
        Protocol flush = stack.findProtocol(FLUSH.class);
        if (flush != null)
            stack.insertProtocol(new_state_transfer_protcol, ProtocolStack.Position.BELOW, FLUSH.class);
        else
            stack.insertProtocolAtTop(new_state_transfer_protcol);
    }
}
Also used : ProtocolStack(org.jgroups.stack.ProtocolStack) Protocol(org.jgroups.stack.Protocol)

Example 44 with Protocol

use of org.jgroups.stack.Protocol in project wildfly by wildfly.

the class AbstractProtocolConfigurationBuilder method createProtocol.

@SuppressWarnings("unchecked")
@Override
public final P createProtocol() {
    StringBuilder builder = new StringBuilder();
    if (this.moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !this.name.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) {
        builder.append(org.jgroups.conf.ProtocolConfiguration.protocol_prefix).append('.');
    }
    String className = builder.append(this.name).toString();
    try {
        Module module = this.loader.getValue().loadModule(this.moduleName);
        Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class);
        Protocol protocol = ProtocolFactory.newInstance(protocolClass);
        P result = (P) ProtocolFactory.TRANSFORMER.apply(protocol);
        Map<String, String> properties = new HashMap<>(this.defaults.getValue().getProperties(this.name));
        properties.putAll(this.properties);
        Configurator.resolveAndAssignFields(result, properties);
        Configurator.resolveAndInvokePropertyMethods(result, properties);
        this.accept(result);
        return result;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : HashMap(java.util.HashMap) Module(org.jboss.modules.Module) Protocol(org.jgroups.stack.Protocol) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 45 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class PropertyHelper method getConvertedValue.

public static Object getConvertedValue(Object obj, Field field, Map<String, String> props, String prop, boolean check_scope) throws Exception {
    if (obj == null)
        throw new IllegalArgumentException("Cannot get converted value: Object is null");
    if (field == null)
        throw new IllegalArgumentException("Cannot get converted value: Field is null");
    if (props == null)
        throw new IllegalArgumentException("Cannot get converted value: Properties is null");
    Property annotation = field.getAnnotation(Property.class);
    if (annotation == null) {
        throw new IllegalArgumentException("Cannot get property name for field " + field.getName() + " which is not annotated with @Property");
    }
    String propertyName = getPropertyName(field, props);
    String name = obj instanceof Protocol ? ((Protocol) obj).getName() : obj.getClass().getName();
    PropertyConverter propertyConverter = (PropertyConverter) annotation.converter().newInstance();
    if (propertyConverter == null) {
        throw new Exception("Could not find property converter for field " + propertyName + " in " + name);
    }
    Object converted = null;
    try {
        String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propertyName : propertyName;
        converted = propertyConverter.convert(obj, field.getType(), tmp, prop, check_scope);
    } catch (Exception e) {
        throw new Exception("Conversion of " + propertyName + " in " + name + " with original property value " + prop + " failed", e);
    }
    return converted;
}
Also used : Protocol(org.jgroups.stack.Protocol) Property(org.jgroups.annotations.Property)

Aggregations

Protocol (org.jgroups.stack.Protocol)87 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)18 JChannel (org.jgroups.JChannel)17 GMS (org.jgroups.protocols.pbcast.GMS)17 STABLE (org.jgroups.protocols.pbcast.STABLE)13 ProtocolStack (org.jgroups.stack.ProtocolStack)12 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 Property (org.jgroups.annotations.Property)6 HashMap (java.util.HashMap)5 ForkProtocol (org.jgroups.fork.ForkProtocol)5 ForkProtocolStack (org.jgroups.fork.ForkProtocolStack)5 InetAddress (java.net.InetAddress)4 ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 Message (org.jgroups.Message)3 FORK (org.jgroups.protocols.FORK)3 UNICAST3 (org.jgroups.protocols.UNICAST3)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Method (java.lang.reflect.Method)2