Search in sources :

Example 1 with AsciiString

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

the class AsciiStringTest method testCreation.

public void testCreation() {
    String orig = "hello";
    AsciiString str = new AsciiString(orig);
    assert str.length() == orig.length();
    assert str.toString().equals(orig);
    AsciiString str2 = new AsciiString(str);
    assert str2.equals(str);
    assert str2.length() == str.length();
    byte[] tmp = { 'h', 'e', 'l', 'l', 'o' };
    str2 = new AsciiString(tmp);
    assert str2.equals(str);
    assert str2.length() == str.length();
    assert str.equals(tmp);
    assert str.equals(str.chars());
    tmp = null;
    assert !str.equals(tmp);
}
Also used : AsciiString(org.jgroups.util.AsciiString) AsciiString(org.jgroups.util.AsciiString)

Example 2 with AsciiString

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

the class BitsTest method testAsciiStringByteBuffer.

public void testAsciiStringByteBuffer() throws Exception {
    AsciiString[] strings = { null, new AsciiString("hello world"), new AsciiString("1") };
    for (AsciiString str : strings) {
        ByteBuffer buf = marshallToByteBuffer(str);
        buf.rewind();
        AsciiString s = unmarshallAsciiString(buf);
        assert str == null && s == null || str.equals(s);
    }
}
Also used : AsciiString(org.jgroups.util.AsciiString) ByteBuffer(java.nio.ByteBuffer)

Example 3 with AsciiString

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

the class SHARED_LOOPBACK method dumpRoutingTable.

@ManagedOperation(description = "Dumps the contents of the routing table")
public static String dumpRoutingTable() {
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<AsciiString, Map<Address, SHARED_LOOPBACK>> entry : routing_table.entrySet()) {
        AsciiString cluster_name = entry.getKey();
        Set<Address> mbrs = entry.getValue().keySet();
        sb.append(cluster_name).append(": ").append(mbrs).append("\n");
    }
    return sb.toString();
}
Also used : PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) AsciiString(org.jgroups.util.AsciiString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 4 with AsciiString

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

the class SHARED_LOOPBACK method getDiscoveryResponsesFor.

public static List<PingData> getDiscoveryResponsesFor(String cluster_name) {
    if (cluster_name == null)
        return null;
    Map<Address, SHARED_LOOPBACK> mbrs = routing_table.get(new AsciiString(cluster_name));
    List<PingData> rsps = new ArrayList<>(mbrs != null ? mbrs.size() : 0);
    if (mbrs != null) {
        for (Map.Entry<Address, SHARED_LOOPBACK> entry : mbrs.entrySet()) {
            Address addr = entry.getKey();
            SHARED_LOOPBACK slp = entry.getValue();
            PingData data = new PingData(addr, slp.isServer(), NameCache.get(addr), null).coord(slp.isCoord());
            rsps.add(data);
        }
    }
    return rsps;
}
Also used : PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) AsciiString(org.jgroups.util.AsciiString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 5 with AsciiString

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

the class AsciiStringTest method testCompareTo.

public void testCompareTo() {
    AsciiString str = new AsciiString("hello"), str2 = new AsciiString("hello world");
    int comp = str.compareTo(str2);
    assert comp < 0;
}
Also used : AsciiString(org.jgroups.util.AsciiString)

Aggregations

AsciiString (org.jgroups.util.AsciiString)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Address (org.jgroups.Address)2 PhysicalAddress (org.jgroups.PhysicalAddress)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 ManagedOperation (org.jgroups.annotations.ManagedOperation)1