Search in sources :

Example 1 with Locking

use of org.jgroups.protocols.Locking in project JGroups by belaban.

the class LockServiceConcurrencyTest method printLocks.

protected static void printLocks(JChannel... channels) {
    for (JChannel ch : channels) {
        Locking l = ch.getProtocolStack().findProtocol(Locking.class);
        System.out.printf("**** server locks on %s: %s\n", ch.getAddress(), l.printServerLocks());
    }
}
Also used : JChannel(org.jgroups.JChannel) Locking(org.jgroups.protocols.Locking)

Example 2 with Locking

use of org.jgroups.protocols.Locking in project JGroups by belaban.

the class LockServiceDuplicateLockTest method setup.

@BeforeMethod
protected void setup() throws Exception {
    for (int i = 0; i < channels.length; i++) {
        channels[i] = create(i + 1).connect(LockServiceDuplicateLockTest.class.getSimpleName());
        lock_services[i] = new LockService(channels[i]);
    }
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, channels);
    System.out.printf("channels:\n%s", Stream.of(channels).map(ch -> String.format("%s: %s\n", ch.getAddress(), ch.getView())).collect(Collectors.joining("\n")));
    lock_3 = lock_services[2].getLock(LOCK_NAME);
    lock_6 = lock_services[5].getLock(LOCK_NAME);
    for (JChannel ch : channels) {
        Locking l = ch.getProtocolStack().findProtocol(Locking.class);
        l.addLockListener(this);
    }
}
Also used : LockService(org.jgroups.blocks.locking.LockService) Locking(org.jgroups.protocols.Locking) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with Locking

use of org.jgroups.protocols.Locking in project JGroups by belaban.

the class LockServiceDuplicateLockTest method assertClientLocks.

protected void assertClientLocks(int num, int... indices) {
    for (int index : indices) {
        JChannel ch = channels[index];
        Locking lock = ch.getProtocolStack().findProtocol(Locking.class);
        assert lock.getNumClientLocks() == num : String.format("expected %d client locks but found %d in %s", num, lock.getNumClientLocks(), ch.getAddress());
    }
}
Also used : Locking(org.jgroups.protocols.Locking)

Example 4 with Locking

use of org.jgroups.protocols.Locking in project JGroups by belaban.

the class LockServiceTest method setProp.

protected static void setProp(Class<? extends Locking> clazz, boolean value, JChannel... channels) {
    for (JChannel ch : channels) {
        Locking prot = ch.getProtocolStack().findProtocol(clazz);
        prot.useThreadIdForLockOwner(value);
    }
}
Also used : JChannel(org.jgroups.JChannel) Locking(org.jgroups.protocols.Locking)

Example 5 with Locking

use of org.jgroups.protocols.Locking in project JGroups by belaban.

the class ClusterSplitLockTest method setUp.

protected void setUp(Class<? extends Locking> locking_class) throws Exception {
    for (int i = 0; i < MEMBERS; i++) {
        Locking lock_prot = locking_class.getDeclaredConstructor().newInstance().level("debug");
        if (lock_prot instanceof CENTRAL_LOCK)
            ((CENTRAL_LOCK) lock_prot).setNumberOfBackups(2);
        Protocol[] stack = Util.getTestStack(lock_prot);
        channels[i] = new JChannel(stack);
        lockServices[i] = new LockService(channels[i]);
        channels[i].setName(memberName(i));
        channels[i].connect("TEST");
        execs[i] = Executors.newCachedThreadPool();
        if (i == 0)
            Util.sleep(500);
    }
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, channels);
    // Make sure A is coordinator, because we blindly assume it is in the tests below.
    assertEquals(channels[0].getAddress(), channels[0].getView().getCoord());
}
Also used : JChannel(org.jgroups.JChannel) LockService(org.jgroups.blocks.locking.LockService) Protocol(org.jgroups.stack.Protocol) CENTRAL_LOCK(org.jgroups.protocols.CENTRAL_LOCK) Locking(org.jgroups.protocols.Locking)

Aggregations

Locking (org.jgroups.protocols.Locking)6 JChannel (org.jgroups.JChannel)3 LockService (org.jgroups.blocks.locking.LockService)2 CENTRAL_LOCK (org.jgroups.protocols.CENTRAL_LOCK)1 Protocol (org.jgroups.stack.Protocol)1 BeforeMethod (org.testng.annotations.BeforeMethod)1