Search in sources :

Example 46 with Protocol

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

the class PropertyHelper method getConvertedValue.

public static Object getConvertedValue(Object obj, Method method, 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 (method == null) {
        throw new IllegalArgumentException("Cannot get converted value: Method is null");
    }
    if (!Configurator.isSetPropertyMethod(method, obj.getClass())) {
        throw new IllegalArgumentException("Cannot get converted value: Method is not set property method");
    }
    if (props == null) {
        throw new IllegalArgumentException("Cannot get converted value: Properties is null");
    }
    Property annotation = method.getAnnotation(Property.class);
    if (annotation == null) {
        throw new IllegalArgumentException("Cannot get property name for method " + method.getName() + " which is not annotated with @Property");
    }
    String propertyName = getPropertyName(method);
    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 method " + propertyName + " in " + name);
    }
    Object converted = null;
    try {
        String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propertyName : propertyName;
        converted = propertyConverter.convert(obj, method.getParameterTypes()[0], tmp, prop, check_scope);
    } catch (Exception e) {
        throw new Exception("Conversion of " + propertyName + " in " + name + " with original property value " + prop + " failed. Exception is " + e, e);
    }
    return converted;
}
Also used : Protocol(org.jgroups.stack.Protocol) Property(org.jgroups.annotations.Property)

Example 47 with Protocol

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

the class Channel method setSocketFactory.

public void setSocketFactory(SocketFactory factory) {
    ProtocolStack stack = getProtocolStack();
    Protocol prot = stack != null ? stack.getTopProtocol() : null;
    if (prot != null)
        prot.setSocketFactory(factory);
}
Also used : ProtocolStack(org.jgroups.stack.ProtocolStack) Protocol(org.jgroups.stack.Protocol)

Example 48 with Protocol

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

the class GossipRouterTest method createTunnelChannel.

protected JChannel createTunnelChannel(String name, boolean include_failure_detection) throws Exception {
    TUNNEL tunnel = new TUNNEL().setValue("bind_addr", bind_addr).setValue("reconnect_interval", 1000);
    tunnel.setGossipRouterHosts(gossip_router_hosts);
    List<Protocol> protocols = new ArrayList<>();
    protocols.addAll(Arrays.asList(tunnel, new PING(), new MERGE3().setValue("min_interval", 1000).setValue("max_interval", 3000)));
    if (include_failure_detection) {
        List<Protocol> tmp = new ArrayList<>(2);
        tmp.add(new FD().setValue("timeout", 2000).setValue("max_tries", 2));
        tmp.add(new VERIFY_SUSPECT());
        protocols.addAll(tmp);
    }
    protocols.addAll(Arrays.asList(new NAKACK2().setValue("use_mcast_xmit", false), new UNICAST3(), new STABLE(), new GMS().joinTimeout(10)));
    JChannel ch = new JChannel(protocols);
    if (name != null)
        ch.setName(name);
    return ch;
}
Also used : JChannel(org.jgroups.JChannel) ArrayList(java.util.ArrayList) GMS(org.jgroups.protocols.pbcast.GMS) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol)

Example 49 with Protocol

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

the class INJECT_VIEWTest method create.

private static JChannel[] create(boolean use_flush_props, boolean simple_ids, String cluster_name, String... names) throws Exception {
    JChannel[] retval = new JChannel[names.length];
    for (int i = 0; i < retval.length; i++) {
        JChannel ch;
        Protocol[] props = use_flush_props ? getFlushProps() : getProps();
        if (simple_ids) {
            ch = new MyChannel(props);
            ((MyChannel) ch).setId(i + 1);
        } else
            ch = new JChannel(props);
        ch.setName(names[i]);
        retval[i] = ch;
        ch.connect(cluster_name);
        if (i == 0)
            Util.sleep(3000);
    }
    return retval;
}
Also used : JChannel(org.jgroups.JChannel) Protocol(org.jgroups.stack.Protocol)

Example 50 with Protocol

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

the class UNICAST_ConnectionTests method testMultipleConcurrentResets.

/**
 * Tests concurrent reception of multiple messages with a different conn_id (https://issues.jboss.org/browse/JGRP-1347)
 */
@Test(dataProvider = "configProvider")
public void testMultipleConcurrentResets(Class<? extends Protocol> unicast) throws Exception {
    setup(unicast);
    sendAndCheck(a, b_addr, 1, r2);
    // now close connection on A unilaterally
    System.out.println("==== Closing the connection on A");
    removeConnection(u1, b_addr);
    r2.clear();
    final Protocol ucast = b.getProtocolStack().findProtocol(Util.getUnicastProtocols());
    int NUM = 10;
    final List<Message> msgs = new ArrayList<>(NUM);
    for (int i = 1; i <= NUM; i++) {
        Message msg = new Message(b_addr, i).src(a_addr);
        Header hdr = createDataHeader(ucast, 1, (short) 2, true);
        msg.putHeader(ucast.getId(), hdr);
        msgs.add(msg);
    }
    Thread[] threads = new Thread[NUM];
    final CyclicBarrier barrier = new CyclicBarrier(NUM + 1);
    for (int i = 0; i < NUM; i++) {
        final int index = i;
        threads[i] = new Thread() {

            public void run() {
                try {
                    barrier.await();
                    ucast.up(msgs.get(index));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        threads[i].start();
    }
    barrier.await();
    for (Thread thread : threads) thread.join();
    List<Integer> list = r2.getMessages();
    System.out.println("list = " + print(list));
    assert list.size() == 1 : "list must have 1 element but has " + list.size() + ": " + print(list);
}
Also used : ArrayList(java.util.ArrayList) Protocol(org.jgroups.stack.Protocol) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.testng.annotations.Test)

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