use of org.jgroups.Message in project JGroups by belaban.
the class MessageBatch method printHeaders.
public String printHeaders() {
StringBuilder sb = new StringBuilder().append("dest=" + dest);
if (sender != null)
sb.append(", sender=").append(sender);
sb.append("\n").append(size()).append(":\n");
int count = 1;
for (Message msg : this) sb.append("#").append(count++).append(": ").append(msg.printHeaders()).append("\n");
return sb.toString();
}
use of org.jgroups.Message in project JGroups by belaban.
the class DrainTest method drain.
protected void drain() {
if (counter.getAndIncrement() == 0) {
num_removers.increment();
int cnt = 0;
do {
Message msg = queue.poll();
if (msg == null)
// System.err.printf("got empty message");
continue;
removed.increment();
cnt++;
} while (counter.decrementAndGet() != 0);
avg_removed.add(cnt);
}
}
use of org.jgroups.Message in project JGroups by belaban.
the class MPING method run.
public void run() {
final byte[] receive_buf = new byte[65535];
DatagramPacket packet = new DatagramPacket(receive_buf, receive_buf.length);
while (mcast_receive_sock != null && Thread.currentThread().equals(receiver)) {
packet.setData(receive_buf, 0, receive_buf.length);
try {
mcast_receive_sock.receive(packet);
DataInput inp = new ByteArrayDataInputStream(packet.getData(), packet.getOffset(), packet.getLength());
Message msg = new BytesMessage();
msg.readFrom(inp);
if (// discard discovery request from self
!Objects.equals(local_addr, msg.getSrc()))
up(msg);
} catch (SocketException socketEx) {
break;
} catch (Throwable ex) {
log.error(Util.getMessage("FailedReceivingPacketFrom"), packet.getSocketAddress(), ex);
}
}
}
use of org.jgroups.Message in project JGroups by belaban.
the class RingBufferBundler method sendBundledMessages.
/**
* Read and send messages in range [read-index .. read-index+available_msgs-1]
*/
public void sendBundledMessages(final Message[] buf, final int read_index, final int available_msgs) {
byte[] cluster_name = transport.cluster_name.chars();
int start = read_index;
// index of the last message to be read
final int end = index(start + available_msgs - 1);
for (; ; ) {
Message msg = buf[start];
if (msg == null) {
if (start == end)
break;
start = advance(start);
continue;
}
Address dest = msg.getDest();
try {
output.position(0);
Util.writeMessageListHeader(dest, msg.getSrc(), cluster_name, 1, output, dest == null);
// remember the position at which the number of messages (an int) was written, so we can later set the
// correct value (when we know the correct number of messages)
int size_pos = output.position() - Global.INT_SIZE;
int num_msgs = marshalMessagesToSameDestination(dest, buf, start, end, max_size);
if (num_msgs > 1) {
int current_pos = output.position();
output.position(size_pos);
output.writeInt(num_msgs);
output.position(current_pos);
}
transport.doSend(output.buffer(), 0, output.position(), dest);
if (transport.statsEnabled())
transport.getMessageStats().incrNumBatchesSent(num_msgs);
} catch (Exception ex) {
log.trace("failed to send message(s) to %s: %s", dest == null ? "group" : dest, ex.getMessage());
}
if (start == end)
break;
start = advance(start);
}
}
use of org.jgroups.Message in project JGroups by belaban.
the class RingBufferBundler method marshalMessagesToSameDestination.
// Iterate through the following messages and find messages to the same destination (dest) and write them to output
protected int marshalMessagesToSameDestination(Address dest, Message[] buf, int start_index, final int end_index, int max_bundle_size) throws Exception {
int num_msgs = 0, bytes = 0;
for (; ; ) {
Message msg = buf[start_index];
if (msg != null && Objects.equals(dest, msg.getDest())) {
int size = msg.size() + Global.SHORT_SIZE;
if (bytes + size > max_bundle_size)
break;
bytes += size;
num_msgs++;
buf[start_index] = null;
output.writeShort(msg.getType());
msg.writeToNoAddrs(msg.getSrc(), output, transport.getId());
}
if (start_index == end_index)
break;
start_index = advance(start_index);
}
return num_msgs;
}
Aggregations