Search in sources :

Example 66 with Protocol

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

the class JmxConfigurator method registerChannel.

public static void registerChannel(JChannel ch, MBeanServer server, ObjectName namePrefix, String cluster_name, boolean register_protocols) throws Exception {
    if (ch == null)
        throw new NullPointerException("channel cannot be null");
    if (cluster_name == null)
        cluster_name = ch.getClusterName();
    if (cluster_name == null)
        cluster_name = "null";
    cluster_name = ObjectName.quote(cluster_name);
    if (register_protocols) {
        ProtocolStack stack = ch.getProtocolStack();
        List<Protocol> protocols = stack.getProtocols();
        for (Protocol p : protocols) {
            if (p.getClass().isAnnotationPresent(MBean.class)) {
                String jmx_name = getProtocolRegistrationName(cluster_name, namePrefix, p);
                register(p, server, jmx_name);
            }
        }
    }
    register(ch, server, getChannelRegistrationName(namePrefix, cluster_name));
}
Also used : ProtocolStack(org.jgroups.stack.ProtocolStack) Protocol(org.jgroups.stack.Protocol)

Example 67 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, StackType ip_version) throws Exception {
    Objects.requireNonNull(obj, "cannot get converted value: obj is null");
    Objects.requireNonNull(field, "cannot get converted value: field is null");
    Objects.requireNonNull(props, "cannot get converted value: props 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().getDeclaredConstructor().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, ip_version);
    } catch (Exception e) {
        throw new Exception("Conversion of " + propertyName + " in " + name + " with property value " + prop + " failed", e);
    }
    return converted;
}
Also used : Protocol(org.jgroups.stack.Protocol) Property(org.jgroups.annotations.Property)

Example 68 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, String value, boolean check_scope, StackType ip_version) throws Exception {
    Objects.requireNonNull(obj, "cannot get converted value: obj is null");
    Objects.requireNonNull(field, "cannot get converted value: field is null");
    String propName = field.getName();
    Property annotation = field.getAnnotation(Property.class);
    if (annotation == null)
        throw new IllegalArgumentException("cannot get property name for " + propName + " (not annotated with @Property)");
    String name = obj instanceof Protocol ? ((Protocol) obj).getName() : obj.getClass().getName();
    PropertyConverter propertyConverter = (PropertyConverter) annotation.converter().getDeclaredConstructor().newInstance();
    if (propertyConverter == null)
        throw new Exception("Could not find property converter for field " + propName + " in " + name);
    Object converted = null;
    try {
        String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propName : propName;
        converted = propertyConverter.convert(obj, field.getType(), tmp, value, check_scope, ip_version);
    } catch (Exception e) {
        throw new Exception("Conversion of " + name + "." + " with original property value " + value + " failed", e);
    }
    return converted;
}
Also used : Protocol(org.jgroups.stack.Protocol) Property(org.jgroups.annotations.Property)

Example 69 with Protocol

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

the class FORK method setStateInMainAndForkChannels.

protected void setStateInMainAndForkChannels(InputStream in) {
    try (DataInputStream input = new DataInputStream(in)) {
        for (; ; ) {
            String stack_name = Bits.readString(input);
            String ch_name = Bits.readString(input);
            int len = input.readInt();
            if (len > 0) {
                byte[] data = new byte[len];
                in.read(data, 0, len);
                ByteArrayInputStream tmp = new ByteArrayInputStream(data, 0, len);
                if (stack_name == null && ch_name == null)
                    up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
                else {
                    Protocol prot = fork_stacks.get(stack_name);
                    if (prot == null) {
                        log.warn("%s: fork stack %s not found, dropping state for %s:%s", local_addr, stack_name, stack_name, ch_name);
                        continue;
                    }
                    ForkProtocolStack fork_stack = getForkStack(prot);
                    JChannel fork_ch = fork_stack.get(ch_name);
                    if (fork_ch == null) {
                        log.warn("%s: fork channel %s not found, dropping state for %s:%s", local_addr, ch_name, stack_name, ch_name);
                        continue;
                    }
                    fork_ch.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
                }
            }
        }
    } catch (EOFException ignored) {
    } catch (Throwable ex) {
        log.error("%s: failed setting state in main channel", local_addr, ex);
    }
}
Also used : JChannel(org.jgroups.JChannel) Event(org.jgroups.Event) ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

Example 70 with Protocol

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

the class FORK method up.

public Object up(Message msg) {
    ForkHeader hdr = msg.getHeader(id);
    if (hdr == null)
        return up_prot.up(msg);
    if (hdr.fork_stack_id == null)
        throw new IllegalArgumentException("header has a null fork_stack_id");
    Protocol bottom_prot = get(hdr.fork_stack_id);
    return bottom_prot != null ? bottom_prot.up(msg) : this.unknownForkHandler.handleUnknownForkStack(msg, hdr.fork_stack_id);
}
Also used : ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol)

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