use of org.jgroups.util.ByteArray in project JGroups by belaban.
the class MessageDispatcherSpeedTest method sendMessages.
void sendMessages(int num) throws Exception {
long start, stop;
int show = num / 10;
if (show <= 0)
show = 1;
start = System.currentTimeMillis();
RequestOptions opts = new RequestOptions(ResponseMode.GET_ALL, TIMEOUT).flags(Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC);
byte[] data = "bla".getBytes();
ByteArray buf = new ByteArray(data, 0, data.length);
System.out.println("-- sending " + num + " messages");
for (int i = 1; i <= num; i++) {
disp.castMessage(null, new BytesMessage(null, buf), opts);
if (i % show == 0)
System.out.println("-- sent " + i);
}
stop = System.currentTimeMillis();
printStats(stop - start, num);
}
use of org.jgroups.util.ByteArray in project JGroups by belaban.
the class DNS_PING method findMembers.
@Override
public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) {
PingData data = null;
PhysicalAddress physical_addr = null;
Set<PhysicalAddress> cluster_members = new LinkedHashSet<>();
DNSResolver.DNSRecordType record_type = DNSResolver.DNSRecordType.valueOf(dns_record_type);
physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
// https://issues.jboss.org/browse/JGRP-1670
data = new PingData(local_addr, false, NameCache.get(local_addr), physical_addr);
if (members != null && members.size() <= max_members_in_discovery_request)
data.mbrs(members);
long start = System.currentTimeMillis();
List<Address> dns_discovery_members = getMembers(dns_query, record_type);
long time = System.currentTimeMillis() - start;
if (log.isDebugEnabled()) {
if (dns_discovery_members != null && !dns_discovery_members.isEmpty())
log.debug("%s: entries collected from DNS (in %d ms): %s", local_addr, time, dns_discovery_members);
else
log.debug("%s: no entries collected from DNS (in %d ms)", local_addr, time);
}
boolean ports_found = false;
if (dns_discovery_members != null) {
for (Address address : dns_discovery_members) {
if (// no need to send the request to myself
address.equals(physical_addr))
continue;
if (address instanceof IpAddress) {
IpAddress ip = ((IpAddress) address);
if (record_type == DNSResolver.DNSRecordType.SRV && ip.getPort() > 0) {
ports_found = true;
cluster_members.add(ip);
if (!probe_transport_ports)
continue;
}
for (int i = 0; i <= portRange; i++) cluster_members.add(new IpAddress(ip.getIpAddress(), transportPort + i));
}
}
}
if (dns_discovery_members != null && !dns_discovery_members.isEmpty() && log.isDebugEnabled()) {
if (ports_found)
log.debug("%s: sending discovery requests to %s", local_addr, cluster_members);
else
log.debug("%s: sending discovery requests to hosts %s on ports [%d .. %d]", local_addr, dns_discovery_members, transportPort, transportPort + portRange);
}
ByteArray data_buf = data != null ? marshal(data) : null;
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery);
for (Address addr : cluster_members) {
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new BytesMessage(addr).setFlag(DONT_BUNDLE, OOB).setFlag(DONT_LOOPBACK).putHeader(this.id, hdr);
if (data_buf != null)
msg.setArray(data_buf);
if (async_discovery_use_separate_thread_per_request)
timer.execute(() -> sendDiscoveryRequest(msg), sends_can_block);
else
sendDiscoveryRequest(msg);
}
}
use of org.jgroups.util.ByteArray in project JGroups by belaban.
the class MessageSizeTest method testUnicast.
/**
* Tests size of a unicast message.
* Current record: 102 (March 2010)
* Prev: 161, 127, 121, 102
* @throws Exception
*/
public static void testUnicast() throws Exception {
Address dest = Util.createRandomAddress();
Address src = Util.createRandomAddress();
Message msg = createMessage(dest, src);
ByteArray buf = marshal(msg);
System.out.println("buf = " + buf);
int len = buf.getLength();
System.out.println("len = " + len);
assert len <= UNICAST_MAX_SIZE;
if (len < UNICAST_MAX_SIZE) {
double percentage = compute(len, UNICAST_MAX_SIZE);
System.out.printf("unicast message (%d bytes) is %.2f %% smaller than previous max size (%d bytes)\n", len, percentage, MCAST_MAX_SIZE);
}
}
use of org.jgroups.util.ByteArray in project JGroups by belaban.
the class MessageSizeTest method testMulticast.
/**
* Tests size of a multicast message.
* Current record: 84 bytes (March 2010)
* Prev: 166, 109, 103, 84
* @throws Exception
*/
public static void testMulticast() throws Exception {
Address src = Util.createRandomAddress();
Message msg = createMessage(null, src);
ByteArray buf = marshal(msg);
System.out.println("buf = " + buf);
int len = buf.getLength();
System.out.println("len = " + len);
assert len <= MCAST_MAX_SIZE;
if (len < MCAST_MAX_SIZE) {
double percentage = compute(len, MCAST_MAX_SIZE);
System.out.printf("multicast message (%d bytes) is %.2f %% smaller than previous max size (%d bytes)\n", len, percentage, MCAST_MAX_SIZE);
}
}
use of org.jgroups.util.ByteArray in project JGroups by belaban.
the class CompositeMessageTest method testCollapse.
public void testCollapse() throws Exception {
CompositeMessage msg = new CompositeMessage(DEST, M1, M2, M3).collapse(true);
int length = msg.getLength();
ByteArray buf = Util.messageToBuffer(msg);
Message msg2 = Util.messageFromBuffer(buf.getArray(), buf.getOffset(), buf.getLength(), MF);
assert msg2 instanceof BytesMessage;
assert msg2.getLength() == length;
}
Aggregations