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");
}
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");
}
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);
}
}
}
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);
}
}
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);
}
Aggregations