Search in sources :

Example 36 with Protocol

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

the class JmxConfigurator method unregisterChannel.

public static void unregisterChannel(JChannel c, MBeanServer server, String domain, String clusterName) throws Exception {
    if (clusterName != null)
        clusterName = ObjectName.quote(clusterName);
    ProtocolStack stack = c.getProtocolStack();
    List<Protocol> protocols = stack.getProtocols();
    for (Protocol p : protocols) {
        if (p.getClass().isAnnotationPresent(MBean.class)) {
            try {
                String obj_name = getProtocolRegistrationName(clusterName, domain, p);
                unregister(p, server, obj_name);
            } catch (MBeanRegistrationException e) {
                log.warn("MBean unregistration failed: " + e.getCause());
            }
        }
    }
    unregister(c, server, getChannelRegistrationName(domain, clusterName));
}
Also used : ProtocolStack(org.jgroups.stack.ProtocolStack) Protocol(org.jgroups.stack.Protocol)

Example 37 with Protocol

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

the class GMS_MergeTest method modify.

protected static Protocol[] modify(Protocol[] retval) {
    for (Protocol prot : retval) {
        if (prot instanceof GMS)
            ((GMS) prot).setJoinTimeout(1000);
        if (prot instanceof NAKACK2) {
            ((NAKACK2) prot).logDiscardMessages(false);
            ((NAKACK2) prot).logNotFoundMessages(false);
        }
    }
    return retval;
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS)

Example 38 with Protocol

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

the class NAKACK_Delivery_Test method setUp.

@BeforeMethod
protected void setUp() throws Exception {
    a = Util.createRandomAddress("A");
    b = Util.createRandomAddress("B");
    nak = new NAKACK2();
    TP transport = new TP() {

        public boolean supportsMulticasting() {
            return false;
        }

        public void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) throws Exception {
        }

        public String getInfo() {
            return null;
        }

        public Object down(Event evt) {
            return null;
        }

        public Object down(Message msg) {
            return null;
        }

        protected PhysicalAddress getPhysicalAddress() {
            return null;
        }

        public TimeScheduler getTimer() {
            return new TimeScheduler3();
        }
    };
    transport.setId((short) 100);
    nak.setDownProtocol(transport);
    receiver.init(a, b);
    nak.setUpProtocol(receiver);
    nak.start();
    List<Address> members = new ArrayList<>(2);
    members.add(a);
    members.add(b);
    View view = new View(a, 1, members);
    // set the local address
    for (Protocol p = nak; p != null; p = p.getDownProtocol()) p.setAddress(a);
    // set a dummy digest
    View tmp_view = View.create(a, 1, a, b);
    MutableDigest digest = new MutableDigest(tmp_view.getMembersRaw());
    digest.set(a, 0, 0);
    digest.set(b, 0, 0);
    nak.down(new Event(Event.SET_DIGEST, digest));
    // set dummy view
    nak.down(new Event(Event.VIEW_CHANGE, view));
    nak.down(new Event(Event.BECOME_SERVER));
    pool = new ThreadPoolExecutor(1, 100, 1000, TimeUnit.MILLISECONDS, new SynchronousQueue<>());
    // pool=new DirectExecutor();
    // if(pool instanceof ThreadPoolExecutor)
    ((ThreadPoolExecutor) pool).setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) Protocol(org.jgroups.stack.Protocol) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 39 with Protocol

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

the class UNICAST_OOB_Test method sendMessages.

/**
 * Check that 4 is received before 3
 */
private void sendMessages(boolean oob) throws Exception {
    DISCARD_PAYLOAD discard = new DISCARD_PAYLOAD();
    MyReceiver receiver = new MyReceiver();
    b.setReceiver(receiver);
    // the first channel will discard the unicast messages with seqno #3 two times, the let them pass down
    ProtocolStack stack = a.getProtocolStack();
    Protocol neighbor = stack.findProtocol(Util.getUnicastProtocols());
    System.out.println("Found unicast protocol " + neighbor.getClass().getSimpleName());
    stack.insertProtocolInStack(discard, neighbor, ProtocolStack.Position.BELOW);
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, a, b);
    Address dest = b.getAddress();
    for (int i = 1; i <= 5; i++) {
        Message msg = new ObjectMessage(dest, (long) i);
        if (i == 4 && oob)
            msg.setFlag(Message.Flag.OOB);
        System.out.println("-- sending message #" + i);
        a.send(msg);
        Util.sleep(100);
    }
    // wait until retransmission of seqno #3 happens, so that 4 and 5 are received as well
    long target_time = System.currentTimeMillis() + 30000;
    do {
        if (receiver.size() >= 5)
            break;
        Util.sleep(500);
    } while (target_time > System.currentTimeMillis());
    List<Long> seqnos = receiver.getSeqnos();
    System.out.println("-- sequence numbers: " + seqnos);
    assert seqnos.size() == 5;
    if (!oob) {
        for (int i = 0; i < 5; i++) assert seqnos.get(i) == i + 1 : " seqno is " + seqnos.get(i) + ", but expected " + i + 1;
    } else {
        // 4 needs to be received before 3. Reason: 4 is sent OOB,  does *not* wait until 3 has been retransmitted !
        int index_3 = -1, index_4 = -1;
        for (int i = 0; i < 5; i++) {
            if (seqnos.get(i) == 3)
                index_3 = i;
            if (seqnos.get(i) == 4)
                index_4 = i;
        }
        assert index_4 < index_3 : "4 must come before 3 in list " + seqnos;
    }
}
Also used : ProtocolStack(org.jgroups.stack.ProtocolStack) Protocol(org.jgroups.stack.Protocol)

Example 40 with Protocol

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

the class UNICAST_ConnectionTests method testMessageToNonExistingMember.

@Test(dataProvider = "configProvider")
public void testMessageToNonExistingMember(Class<? extends UNICAST3> unicast) throws Exception {
    setup(unicast);
    Stream.of(a, b).forEach(ch -> ((UNICAST3) ch.getProtocolStack().findProtocol(unicast)).setMaxRetransmitTime(5000));
    Address target = Util.createRandomAddress("FakeAddress");
    a.send(target, "hello");
    Protocol prot = a.getProtocolStack().findProtocol(unicast);
    Method hasSendConnectionTo = unicast.getMethod("hasSendConnectionTo", Address.class);
    for (int i = 0; i < 10; i++) {
        boolean result = (Boolean) hasSendConnectionTo.invoke(prot, target);
        if (!result)
            break;
        Util.sleep(1000);
    }
    assert !(Boolean) hasSendConnectionTo.invoke(prot, target);
}
Also used : AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) Protocol(org.jgroups.stack.Protocol) 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