Search in sources :

Example 96 with Message

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();
}
Also used : Message(org.jgroups.Message)

Example 97 with Message

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);
    }
}
Also used : Message(org.jgroups.Message) EmptyMessage(org.jgroups.EmptyMessage)

Example 98 with Message

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);
        }
    }
}
Also used : DataInput(java.io.DataInput) BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) BytesMessage(org.jgroups.BytesMessage)

Example 99 with Message

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);
    }
}
Also used : Message(org.jgroups.Message) Address(org.jgroups.Address)

Example 100 with Message

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;
}
Also used : Message(org.jgroups.Message)

Aggregations

Message (org.jgroups.Message)246 Address (org.jgroups.Address)50 MessageBatch (org.jgroups.util.MessageBatch)37 BytesMessage (org.jgroups.BytesMessage)31 NioMessage (org.jgroups.NioMessage)14 ObjectMessage (org.jgroups.ObjectMessage)14 EmptyMessage (org.jgroups.EmptyMessage)12 Test (org.testng.annotations.Test)12 Event (org.jgroups.Event)11 ToaHeader (org.jgroups.protocols.tom.ToaHeader)11 Test (org.junit.Test)11 IOException (java.io.IOException)8 JChannel (org.jgroups.JChannel)8 MessageID (org.jgroups.protocols.tom.MessageID)8 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)7 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)7 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)7 TimeoutException (java.util.concurrent.TimeoutException)6 Collectors (java.util.stream.Collectors)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6