Search in sources :

Example 21 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class LazyRemovalCacheTest method testRemoveAll.

public static void testRemoveAll() {
    LazyRemovalCache<UUID, String> cache = new LazyRemovalCache<>(10, 0);
    List<UUID> list = Arrays.asList(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID());
    int cnt = 1;
    for (UUID uuid : list) cache.add(uuid, "node-" + cnt++);
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    cache.add(uuid1, "foo");
    cache.add(uuid2, "bar");
    System.out.println("cache = " + cache);
    assert cache.size() == 5;
    System.out.println("removing " + list);
    cache.removeAll(list);
    System.out.println("cache = " + cache);
    assert cache.size() == 5;
    assert cache.get(uuid1).equals("foo");
    assert cache.get(uuid2).equals("bar");
    cache.removeMarkedElements();
    System.out.println("cache = " + cache);
    assert cache.size() == 2;
    assert cache.get(uuid1).equals("foo");
    assert cache.get(uuid2).equals("bar");
}
Also used : UUID(org.jgroups.util.UUID)

Example 22 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class LazyRemovalCacheTest method testRetainAll.

public static void testRetainAll() {
    LazyRemovalCache<UUID, String> cache = new LazyRemovalCache<>(10, 0);
    List<UUID> list = Arrays.asList(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID());
    int cnt = 1;
    for (UUID uuid : list) cache.add(uuid, "node-" + cnt++);
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    cache.add(uuid1, "foo");
    cache.add(uuid2, "bar");
    System.out.println("cache = " + cache);
    assert cache.size() == 5;
    List<UUID> retain = Arrays.asList(uuid1, uuid2);
    System.out.println("retaining " + retain);
    cache.retainAll(retain);
    System.out.println("cache = " + cache);
    assert cache.size() == 5;
    assert cache.get(uuid1).equals("foo");
    assert cache.get(uuid2).equals("bar");
    cache.removeMarkedElements();
    System.out.println("cache = " + cache);
    assert cache.size() == 2;
    assert cache.get(uuid1).equals("foo");
    assert cache.get(uuid2).equals("bar");
}
Also used : UUID(org.jgroups.util.UUID)

Example 23 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class ParseMessages method readMappings.

protected static void readMappings(String filename) throws IOException {
    try (InputStream in = new FileInputStream(filename)) {
        for (; ; ) {
            String uuid_str = Util.readToken(in);
            String name = Util.readToken(in);
            if (uuid_str == null || name == null)
                break;
            UUID uuid = null;
            try {
                long tmp = Long.valueOf(uuid_str);
                uuid = new UUID(0, tmp);
            } catch (Throwable t) {
                uuid = UUID.fromString(uuid_str);
            }
            NameCache.add(uuid, name);
        }
    }
}
Also used : UUID(org.jgroups.util.UUID)

Example 24 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class Discovery method read.

/* -------------------------- Private methods ---------------------------- */
protected List<PingData> read(InputStream in) {
    List<PingData> retval = null;
    try {
        while (true) {
            try {
                String name_str = Util.readToken(in);
                String uuid_str = Util.readToken(in);
                String addr_str = Util.readToken(in);
                String coord_str = Util.readToken(in);
                if (name_str == null || uuid_str == null || addr_str == null || coord_str == null)
                    break;
                UUID uuid = null;
                try {
                    long tmp = Long.parseLong(uuid_str);
                    uuid = new UUID(0, tmp);
                } catch (Throwable t) {
                    uuid = UUID.fromString(uuid_str);
                }
                PhysicalAddress phys_addr = new IpAddress(addr_str);
                boolean is_coordinator = coord_str.trim().equals("T") || coord_str.trim().equals("t");
                if (retval == null)
                    retval = new ArrayList<>();
                retval.add(new PingData(uuid, true, name_str, phys_addr).coord(is_coordinator));
            } catch (Throwable t) {
                log.error(Util.getMessage("FailedReadingLineOfInputStream"), t);
            }
        }
        return retval;
    } finally {
        Util.close(in);
    }
}
Also used : IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID)

Example 25 with UUID

use of org.jgroups.util.UUID in project wildfly by wildfly.

the class AddressSerializerTestCase method test.

private static void test(Tester<Address> tester) throws IOException {
    UUID uuid = UUID.randomUUID();
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLoopbackAddress(), Short.MAX_VALUE);
    IpAddress ipAddress = new IpAddress(address);
    IpAddressUUID ipAddressUUID = new IpAddressUUID(address);
    tester.test(uuid);
    tester.test(ipAddress);
    tester.test(ipAddressUUID);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID)

Aggregations

UUID (org.jgroups.util.UUID)27 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)4 Event (org.jgroups.Event)4 Test (org.junit.Test)4 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 SiteUUID (org.jgroups.protocols.relay.SiteUUID)3 IpAddress (org.jgroups.stack.IpAddress)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 ExtendedUUID (org.jgroups.util.ExtendedUUID)2 FlagsUUID (org.jgroups.util.FlagsUUID)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1